[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();
----------------
felipepiovezan wrote:

> Note that you should not use an isa<> test followed by a cast<>, for that use the dyn_cast<> operator.

https://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates


I think this would be easier to follow with an early exit on the result of the dyn cast: https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code

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


More information about the llvm-commits mailing list