Skip to content

Commit 5e22ede

Browse files
committed
[InstCombine] Allow folding with two constant arms
1 parent 4b87c01 commit 5e22ede

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
27092709

27102710
if (match(Arg, m_Select(m_Value(Cond), m_Value(TVal), m_Value(FVal)))) {
27112711
// fabs (select Cond, TrueC, FalseC) --> select Cond, AbsT, AbsF
2712-
if (Arg->hasOneUse() && (isa<Constant>(TVal) || isa<Constant>(FVal))) {
2712+
if (Arg->hasOneUse() ? (isa<Constant>(TVal) || isa<Constant>(FVal))
2713+
: (isa<Constant>(TVal) && isa<Constant>(FVal))) {
27132714
CallInst *AbsT = Builder.CreateCall(II->getCalledFunction(), {TVal});
27142715
CallInst *AbsF = Builder.CreateCall(II->getCalledFunction(), {FVal});
27152716
SelectInst *SI = SelectInst::Create(Cond, AbsT, AbsF);

llvm/test/Transforms/InstCombine/intrinsic-select.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ define float @test_fabs_select_multiuse_both_constant(i1 %cond, float %x) {
363363
; CHECK-LABEL: @test_fabs_select_multiuse_both_constant(
364364
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[COND:%.*]], float -1.000000e+00, float -2.000000e+00
365365
; CHECK-NEXT: call void @usef32(float [[SELECT]])
366-
; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]])
366+
; CHECK-NEXT: [[FABS:%.*]] = select i1 [[COND]], float 1.000000e+00, float 2.000000e+00
367367
; CHECK-NEXT: ret float [[FABS]]
368368
;
369369
%select = select i1 %cond, float -1.0, float -2.0

0 commit comments

Comments
 (0)