[llvm] [SDAG] Only apply sincos/frexp stack slot folding to IR pointers (PR #115346)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 7 14:54:47 PST 2024


================
@@ -2518,7 +2518,12 @@ bool SelectionDAG::expandMultipleResultFPLibCall(
     SDValue StoreValue = ST->getValue();
     unsigned ResNo = StoreValue.getResNo();
     Type *StoreType = StoreValue.getValueType().getTypeForEVT(Ctx);
-    if (CallRetResNo == ResNo || !ST->isSimple() ||
+    // If the pointer value does not come from the IR, it could come from ABI
+    // lowering and may alias with the arguments of the library call if they are
+    // passed via the stack.
----------------
MacDue wrote:

My understanding (possibly wrong) is you have two calls:
```
sincos(x, ptr, ptr)
g(double, double)
```

All the arguments are passed on the stack, and the call to `sincos` is written to be passed the stack locations of the arguments to `g` directly. The issue is the slack locations of `g`'s arguments alias the stack locations of `sincos`'s arguments, so when `sincos` writes to one of the pointers it clobbers its own arguments. 

The current code is already checking the two pointers for sin and cos don't alias, but it does not expect the pointers could alias its other arguments. 



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


More information about the llvm-commits mailing list