1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

InstCombine: Fold fabs on select of constants

llvm-svn: 290913
This commit is contained in:
Matt Arsenault 2017-01-03 22:40:34 +00:00
parent 571db5f912
commit 9fca19b426
2 changed files with 60 additions and 0 deletions

View File

@ -1625,6 +1625,18 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
break;
}
case Intrinsic::fabs: {
Value *Cond;
Constant *LHS, *RHS;
if (match(II->getArgOperand(0),
m_Select(m_Value(Cond), m_Constant(LHS), m_Constant(RHS)))) {
CallInst *Call0 = Builder->CreateCall(II->getCalledFunction(), {LHS});
CallInst *Call1 = Builder->CreateCall(II->getCalledFunction(), {RHS});
return SelectInst::Create(Cond, Call0, Call1);
}
break;
}
case Intrinsic::ppc_altivec_lvx:
case Intrinsic::ppc_altivec_lvxl:
// Turn PPC lvx -> load if the pointer is known aligned.

View File

@ -98,3 +98,51 @@ define float @square_fabs_shrink_call2(float %x) {
; CHECK-NEXT: ret float %sq
}
; CHECK-LABEL: @fabs_select_constant_negative_positive(
; CHECK: %fabs = select i1 %cmp, float 1.000000e+00, float 2.000000e+00
; CHECK-NEXT: ret float %fabs
define float @fabs_select_constant_negative_positive(i32 %c) {
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float -1.0, float 2.0
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
; CHECK-LABEL: @fabs_select_constant_positive_negative(
; CHECK: %fabs = select i1 %cmp, float 1.000000e+00, float 2.000000e+00
; CHECK-NEXT: ret float %fabs
define float @fabs_select_constant_positive_negative(i32 %c) {
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float 1.0, float -2.0
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
; CHECK-LABEL: @fabs_select_constant_negative_negative(
; CHECK: %fabs = select i1 %cmp, float 1.000000e+00, float 2.000000e+00
; CHECK-NEXT: ret float %fabs
define float @fabs_select_constant_negative_negative(i32 %c) {
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float -1.0, float -2.0
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
; CHECK-LABEL: @fabs_select_constant_neg0(
; CHECK-NEXT: ret float 0.0
define float @fabs_select_constant_neg0(i32 %c) {
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float -0.0, float 0.0
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
; CHECK-LABEL: @fabs_select_var_constant_negative(
; CHECK: %select = select i1 %cmp, float %x, float -1.000000e+00
; CHECK: %fabs = call float @llvm.fabs.f32(float %select)
define float @fabs_select_var_constant_negative(i32 %c, float %x) {
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float %x, float -1.0
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}