[llvm] [Reland][InstCombine] Fix FMF propagation in `foldSelectIntoOp` (PR #114499)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 31 19:40:19 PDT 2024


================
@@ -564,6 +561,12 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal,
     BinaryOperator *BO =
         BinaryOperator::Create(TVI->getOpcode(), FalseVal, NewSel);
     BO->copyIRFlags(TVI);
+    if (isa<FPMathOperator>(&SI)) {
+      // Merge poison generating flags from the select
+      BO->setHasNoNaNs(BO->hasNoNaNs() && FMF.noNaNs());
+      BO->setHasNoInfs(BO->hasNoInfs() && FMF.noInfs());
+      BO->setHasNoSignedZeros(BO->hasNoSignedZeros() && FMF.noSignedZeros());
----------------
arsenm wrote:

No signed zeros aren't poison generating.

But I'm not sure why it's correct to preserve reassoc 

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


More information about the llvm-commits mailing list