Skip to content

Commit b1fbcdf

Browse files
committed
[InstCombine] Fix flag propagation in foldSelectIntoOp
1 parent 9716818 commit b1fbcdf

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,11 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal,
544544

545545
Value *NewSel = Builder.CreateSelect(SI.getCondition(), Swapped ? C : OOp,
546546
Swapped ? OOp : C, "", &SI);
547-
if (isa<FPMathOperator>(&SI))
547+
if (isa<FPMathOperator>(&SI)) {
548548
cast<Instruction>(NewSel)->setFastMathFlags(FMF);
549+
if (!TVI->hasNoInfs() && !FMF.noNaNs())
550+
cast<Instruction>(NewSel)->setHasNoInfs(false);
551+
}
549552
NewSel->takeName(TVI);
550553
BinaryOperator *BO =
551554
BinaryOperator::Create(TVI->getOpcode(), FalseVal, NewSel);

llvm/test/Transforms/InstCombine/select-binop-foldable-floating-point.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ define float @select_fpclass_fadd_ninf1(i1 %cond, float nofpclass(nan) %A, float
3636

3737
define float @select_fpclass_fadd_ninf2(i1 %cond, float nofpclass(nan) %A, float %B) {
3838
; CHECK-LABEL: @select_fpclass_fadd_ninf2(
39-
; CHECK-NEXT: [[C:%.*]] = select ninf i1 [[COND:%.*]], float [[B:%.*]], float -0.000000e+00
39+
; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float [[B:%.*]], float -0.000000e+00
4040
; CHECK-NEXT: [[D:%.*]] = fadd float [[A:%.*]], [[C]]
4141
; CHECK-NEXT: ret float [[D]]
4242
;

0 commit comments

Comments
 (0)