[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
Fri Nov 8 07:08:59 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:

Having thought about the issue with folding stores into `sincos` while expanding it to a library call, the possible solutions I came up with are:

1. Check the stores are not within a `CALLSEQ_START`-`CALLSEQ_END` pair
   * As far as I can tell nobody has done this before -- grepping the codebase (and it's possibly a costly graph search)
2. Disallow stores to pointers that don't exist in the IR
    * Much simpler -- and I think could solve the issue, but it's assuming a store to an IR pointer won't occur within a `CALLSEQ_START` - `CALLSEQ_END` pair
     * Maybe this is a valid assumption (the stores I've seen have always been to special stack slots for the call), but maybe this could be broken.
3. Be very conservative and restrict this to trivial cases (e.g. the case where the store input chains are the entry node)

The issue this is trying to avoid is if the stores that are to be folded into `sincos` are within a  `CALLSEQ_START`-`CALLSEQ_END` pair, then the expansion will result in nested call sequences, which is where the issues come from.




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


More information about the llvm-commits mailing list