Skip to content

Commit ca4dfca

Browse files
authored
[InstCombine] Relax guard against FP min/max in select fold (#143144)
FCmp's commutativity predicates do not work with min/max semantics Closes #142711
1 parent 4f304e2 commit ca4dfca

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,8 @@ Instruction *InstCombinerImpl::FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
17291729
if (auto *CI = dyn_cast<FCmpInst>(SI->getCondition())) {
17301730
if (CI->hasOneUse()) {
17311731
Value *Op0 = CI->getOperand(0), *Op1 = CI->getOperand(1);
1732-
if ((TV == Op0 && FV == Op1) || (FV == Op0 && TV == Op1))
1732+
if (((TV == Op0 && FV == Op1) || (FV == Op0 && TV == Op1)) &&
1733+
!CI->isCommutative())
17331734
return nullptr;
17341735
}
17351736
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,14 @@ define i1 @test_fcmp_select_var_const_unordered(double %x, double %y) {
268268
%cmp2 = fcmp ugt double %sel, 0x3E80000000000000
269269
ret i1 %cmp2
270270
}
271+
272+
define i1 @test_fcmp_ord_select_fcmp_oeq_var_const(double %x) {
273+
; CHECK-LABEL: @test_fcmp_ord_select_fcmp_oeq_var_const(
274+
; CHECK-NEXT: [[CMP1:%.*]] = fcmp oeq double [[X:%.*]], 1.000000e+00
275+
; CHECK-NEXT: ret i1 [[CMP1]]
276+
;
277+
%cmp1 = fcmp ord double %x, 0.000000e+00
278+
%sel = select i1 %cmp1, double %x, double 0.000000e+00
279+
%cmp2 = fcmp oeq double %sel, 1.000000e+00
280+
ret i1 %cmp2
281+
}

0 commit comments

Comments
 (0)