[llvm] [Transforms][CodeExtraction] bug fix regions with stackrestore (PR #118564)

Jon Roelofs via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 11 17:48:38 PST 2024


================
@@ -627,6 +627,26 @@ bool CodeExtractor::isEligible() const {
         return false;
     }
   }
+  // stacksave as input implies stackrestore in the outlined function.
+  // This can confuse prolog epilog insertion phase.
+  // stacksave's uses must not cross outlined function.
+  for (BasicBlock *BB : Blocks) {
+    for (Instruction &I : *BB) {
+      IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I);
+      if (!II)
+        continue;
+      bool IsSave = II->getIntrinsicID() == Intrinsic::stacksave;
+      bool IsRestore = II->getIntrinsicID() == Intrinsic::stackrestore;
+      if (IsSave && any_of(II->users(), [&Blks = this->Blocks](User *U) {
+            return !definedInRegion(Blks, U);
+          })) {
+        return false;
+      }
+      if (IsRestore && !definedInRegion(Blocks, II->getArgOperand(0))) {
+        return false;
+      }
----------------
jroelofs wrote:

okay to keep the one around the body of the outer loop

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


More information about the llvm-commits mailing list