[llvm] [SROA] Propagate no-signed-zeros(nsz) fast-math flag on the phi node using function attribute (PR #83381)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 12 12:43:55 PDT 2024


================
@@ -1113,6 +1114,17 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
         for (unsigned i = 0; i != NumEdges; ++i)
           APN->addIncoming(IncomingVals[AllocaNo], Pred);
 
+        // For the  sequence `return X > 0.0 ? X : -X`, it is expected that this
+        // results in fabs intrinsic. However, without no-signed-zeros(nsz) flag
+        // on the phi node generated at this stage, fabs folding does not
+        // happen. So, we try to infer nsz flag from the function attributes to
+        // enable this fabs folding.
+        if (APN->isComplete() && isa<FPMathOperator>(APN) &&
+            APN->getFunction()
----------------
arsenm wrote:

```suggestion
            BB->getParent()
```

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


More information about the llvm-commits mailing list