[llvm] [indvars] Missing variables at Og (PR #88270)

Carlos Alberto Enciso via llvm-commits llvm-commits at lists.llvm.org
Wed May 22 03:56:13 PDT 2024


================
@@ -1611,11 +1657,30 @@ int llvm::rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI,
     // Replace PN with ExitVal if that is legal and does not break LCSSA.
     if (PN->getNumIncomingValues() == 1 &&
         LI->replacementPreservesLCSSAForm(PN, ExitVal)) {
+      addDebugValuesToLoopVariable(PN->getParent(), ExitVal, PN);
       PN->replaceAllUsesWith(ExitVal);
       PN->eraseFromParent();
     }
   }
 
+  // If the loop can be deleted and there are no PHIs to be rewritten (there
+  // are no loop live-out values), record debug variables corresponding to the
+  // induction variable with their constant exit-values. Those values will be
+  // inserted by the 'deletion loop' logic.
+  if (LoopCanBeDel && RewritePhiSet.empty()) {
+    if (auto *IndVar = L->getInductionVariable(*SE)) {
+      const SCEV *PNSCEV = SE->getSCEVAtScope(IndVar, L->getParentLoop());
+      if (auto *Const = dyn_cast<SCEVConstant>(PNSCEV)) {
+        Value *FinalIVValue = Const->getValue();
+        if (L->getUniqueExitBlock()) {
+          SmallVector<DbgVariableIntrinsic *> DbgUsers;
+          findDbgUsers(DbgUsers, IndVar);
+          L->preserveDebugInductionVariableInfo(FinalIVValue, DbgUsers);
----------------
CarlosAlbertoEnciso wrote:

@nikic Patch already reverted.

If I understand correctly, your main concern is the interaction between `IndVars` and `LoopDeletion` passes.

What I would suggest, is to divide the patch into 2 independent ones:
1) If the `IndVars` pass is triggered add the missing debug values.
2) `LoopDeletion` to compute the exit value.

With no interaction between those 2 passes.

Your feedback would be highly valuable.

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


More information about the llvm-commits mailing list