[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:37 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
+            }
+        }
----------------
fhahn wrote:

Using early continues are preferred in general in LLVM to reduce the nesting which is getting a bit hard to keep track here

Maybe something like

```suggestion
     IntrinsicInst *Intrin = dyn_cast<IntrinsicInst>(&II);
     if (!Intrin || Intrin->getIntrinsicID() != Intrinsic::stacksave)
       continue;
     if (any_of(Intrin->users(), [&Blocks](User *U) { return !definedInRegion(Blocks, U); }))
        return false;
```

Similar for below.

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


More information about the llvm-commits mailing list