[llvm] [InstCombine] Fix flag propagation in `foldSelectIntoOp` (PR #162003)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 10 10:24:36 PDT 2025


================
@@ -544,8 +544,11 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal,
 
     Value *NewSel = Builder.CreateSelect(SI.getCondition(), Swapped ? C : OOp,
                                          Swapped ? OOp : C, "", &SI);
-    if (isa<FPMathOperator>(&SI))
+    if (isa<FPMathOperator>(&SI)) {
       cast<Instruction>(NewSel)->setFastMathFlags(FMF);
+      if (!TVI->hasNoInfs() && !FMF.noNaNs())
----------------
dtcxzyw wrote:

This fold works for fadd, fsub, and fmul. Unfortunately, there are no exceptions. All of these patterns have counterexamples to block the flag propagation. I have updated comments and proofs.


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


More information about the llvm-commits mailing list