[llvm] [InstCombine] Fix for folding `select` into floating point binary operators. (PR #83200)

Paul Osmialowski via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 10:22:30 PDT 2024


pawosm-arm wrote:

Seems all we need is this change:

```
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index aaf4ece3249a..c8d9b4ee446e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -551,7 +551,7 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal,
     // This makes the transformation incorrect since the original program would
     // have preserved the exact NaN bit-pattern.
     // Avoid the folding if the false value might be a NaN.
-    if (isa<FPMathOperator>(&SI) &&
+    if (isa<FPMathOperator>(&SI) && SI.getFastMathFlags().noNaNs() &&
         !computeKnownFPClass(FalseVal, FMF, fcNan, &SI).isKnownNeverNaN())
       return nullptr;

```


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


More information about the llvm-commits mailing list