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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 6 02:11:36 PST 2024


================
@@ -627,6 +627,31 @@ bool CodeExtractor::isEligible() const {
         return false;
     }
   }
+  // stacksave as input implies stackrestore in the outlined function
+  // This can confuse prologue epilogue insertion phase
+  // stacksave's uses must not cross outlined function
+  for (BasicBlock *BB : Blocks) {
+    for (Instruction &II : *BB) {
+      if (IntrinsicInst *Intrin = dyn_cast<IntrinsicInst>(&II)) {
+        if (Intrin->getIntrinsicID() == Intrinsic::stacksave) {
+          for (User *U : Intrin->users())
+            if (!definedInRegion(Blocks, U)) {
+              return false; // stack-restore outside outlined region
+            }
+        }
+      }
+      for (auto &OI : II.operands()) {
+        Value *V = OI;
----------------
fhahn wrote:

```suggestion
      for (Value *Op : II.operands()) {
```

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


More information about the llvm-commits mailing list