[llvm] [SDAG] Allow folding stack slots into sincos/frexp in more cases (PR #118117)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 09:26:28 PST 2024


================
@@ -2474,6 +2474,45 @@ SDValue SelectionDAG::getPartialReduceAdd(SDLoc DL, EVT ReducedTy, SDValue Op1,
   return Subvectors[0];
 }
 
+/// Given a store node \p StoreNode, return true if it is safe to fold that node
+/// into \p FPNode, which expands to a library call with output pointers.
+static bool CanFoldStoreIntoFPLibCall(StoreSDNode *StoreNode, SDNode *FPNode) {
+  SmallVector<const SDNode *, 8> Worklist;
+  SmallVector<const SDNode *, 8> DeferredNodes;
+  SmallPtrSet<const SDNode *, 16> Visited;
+
+  // Skip FPNode use by StoreNode (that's the use we want to fold into FPNode).
+  for (SDValue Op : StoreNode->ops())
+    if (Op.getNode() != FPNode)
+      Worklist.push_back(Op.getNode());
+
+  while (!Worklist.empty()) {
----------------
MacDue wrote:

I guess so :+1: I've taken the existing `MaxSteps` option (used in DAGCombine.cpp) and made it more generally accessible with a `SelectionDAG::getHasPredecessorMaxSteps()` helper, so the max steps here is consistent with other uses. 

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


More information about the llvm-commits mailing list