[llvm] [InstCombine] Fix miscompilation for `select` + `FCmp` (PR #177872)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 25 15:10:36 PST 2026


================
@@ -4486,13 +4486,21 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
         CmpInst::Predicate MinMaxPred = getMinMaxPred(SPF, SPR.Ordered);
 
         Value *Cmp;
-        if (CmpInst::isIntPredicate(MinMaxPred))
+        Value *NewSI;
+        if (CmpInst::isIntPredicate(MinMaxPred)) {
           Cmp = Builder.CreateICmp(MinMaxPred, LHS, RHS);
-        else
+          NewSI = Builder.CreateSelect(Cmp, LHS, RHS, SI.getName(), &SI);
+        } else {
+          if (!isGuaranteedNotToBePoison(LHS) ||
+              !isGuaranteedNotToBePoison(RHS))
+            return nullptr;
----------------
arsenm wrote:

You should not need to call this, this is a matter of fast math flag management. This was only invalid because it preserved the ninf flag, I think you need to intersect the flags between the compare and the select 

https://github.com/llvm/llvm-project/pull/177872


More information about the llvm-commits mailing list