[llvm] ca4dfca - [InstCombine] Relax guard against FP min/max in select fold (#143144)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 6 23:26:47 PDT 2025
Author: Acthinks Yang
Date: 2025-06-07T14:26:43+08:00
New Revision: ca4dfca5c7b417048e074a3c4341ea9297f7086a
URL: https://github.com/llvm/llvm-project/commit/ca4dfca5c7b417048e074a3c4341ea9297f7086a
DIFF: https://github.com/llvm/llvm-project/commit/ca4dfca5c7b417048e074a3c4341ea9297f7086a.diff
LOG: [InstCombine] Relax guard against FP min/max in select fold (#143144)
FCmp's commutativity predicates do not work with min/max semantics
Closes #142711
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/fcmp-select.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 439a86d951a83..e261807bbc035 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1729,7 +1729,8 @@ Instruction *InstCombinerImpl::FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
if (auto *CI = dyn_cast<FCmpInst>(SI->getCondition())) {
if (CI->hasOneUse()) {
Value *Op0 = CI->getOperand(0), *Op1 = CI->getOperand(1);
- if ((TV == Op0 && FV == Op1) || (FV == Op0 && TV == Op1))
+ if (((TV == Op0 && FV == Op1) || (FV == Op0 && TV == Op1)) &&
+ !CI->isCommutative())
return nullptr;
}
}
diff --git a/llvm/test/Transforms/InstCombine/fcmp-select.ll b/llvm/test/Transforms/InstCombine/fcmp-select.ll
index 408bc1cdc268f..053b233cb5f04 100644
--- a/llvm/test/Transforms/InstCombine/fcmp-select.ll
+++ b/llvm/test/Transforms/InstCombine/fcmp-select.ll
@@ -268,3 +268,14 @@ define i1 @test_fcmp_select_var_const_unordered(double %x, double %y) {
%cmp2 = fcmp ugt double %sel, 0x3E80000000000000
ret i1 %cmp2
}
+
+define i1 @test_fcmp_ord_select_fcmp_oeq_var_const(double %x) {
+; CHECK-LABEL: @test_fcmp_ord_select_fcmp_oeq_var_const(
+; CHECK-NEXT: [[CMP1:%.*]] = fcmp oeq double [[X:%.*]], 1.000000e+00
+; CHECK-NEXT: ret i1 [[CMP1]]
+;
+ %cmp1 = fcmp ord double %x, 0.000000e+00
+ %sel = select i1 %cmp1, double %x, double 0.000000e+00
+ %cmp2 = fcmp oeq double %sel, 1.000000e+00
+ ret i1 %cmp2
+}
More information about the llvm-commits
mailing list