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

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 11:00:46 PDT 2023


================
@@ -1519,6 +1520,31 @@ int llvm::rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI,
   // The insertion point instruction may have been deleted; clear it out
   // so that the rewriter doesn't trip over it later.
   Rewriter.clearInsertPoint();
+
+  // The loop exit values have been updated; insert the debug location
+  // for the induction variable with its final value.
+  if (PHINode *IndVar = L->getInductionVariable(*SE)) {
+    const SCEV *IndVarSCEV = SE->getSCEVAtScope(IndVar, L->getParentLoop());
+    if (isa<SCEVConstant>(IndVarSCEV)) {
+      Value *FinalIVValue = cast<SCEVConstant>(IndVarSCEV)->getValue();
+      SmallVector<DbgVariableIntrinsic *> DbgUsers;
+      SmallVector<DbgVariableIntrinsic *> DbgUsersCloned;
+      findDbgUsers(DbgUsers, IndVar);
+      for (auto &DebugUser : DbgUsers) {
+        auto *Cloned = cast<DbgVariableIntrinsic>(DebugUser->clone());
+        Cloned->replaceVariableLocationOp(static_cast<unsigned>(0),
+                                          FinalIVValue);
+        DbgUsersCloned.push_back(Cloned);
+      }
+
+      SmallVector<BasicBlock *> ExitBlocks;
+      L->getExitBlocks(ExitBlocks);
+      for (BasicBlock *Exit : ExitBlocks)
+        for (auto &DebugUser : DbgUsersCloned)
----------------
felipepiovezan wrote:

similarly here `auto *`

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


More information about the llvm-commits mailing list