[llvm] r285185 - [IndVarSimplify][DebugLoc] When widening the exit loop condition, correctly reuse the debug location of the original comparison.

Andrea Di Biagio via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 26 03:28:32 PDT 2016


Author: adibiagio
Date: Wed Oct 26 05:28:32 2016
New Revision: 285185

URL: http://llvm.org/viewvc/llvm-project?rev=285185&view=rev
Log:
[IndVarSimplify][DebugLoc] When widening the exit loop condition, correctly reuse the debug location of the original comparison.

When the loop exit condition is canonicalized as a != compaison, reuse the
debug location of the original (non canonical) comparison.

Before this patch, the debug location of the new icmp was obtained from the
loop latch terminator. This patch fixes the issue by correctly setting the
IRBuilder's "current debug location" to the location of the original compare.

Differential Revision: https://reviews.llvm.org/D25953

Modified:
    llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
    llvm/trunk/test/DebugInfo/Generic/indvar-discriminator.ll

Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=285185&r1=285184&r2=285185&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Wed Oct 26 05:28:32 2016
@@ -2189,6 +2189,11 @@ linearFunctionTestReplace(Loop *L,
 
   IRBuilder<> Builder(BI);
 
+  // The new loop exit condition should reuse the debug location of the
+  // original loop exit condition.
+  if (auto *Cond = dyn_cast<Instruction>(BI->getCondition()))
+    Builder.SetCurrentDebugLocation(Cond->getDebugLoc());
+
   // LFTR can ignore IV overflow and truncate to the width of
   // BECount. This avoids materializing the add(zext(add)) expression.
   unsigned CmpIndVarSize = SE->getTypeSizeInBits(CmpIndVar->getType());

Modified: llvm/trunk/test/DebugInfo/Generic/indvar-discriminator.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/indvar-discriminator.ll?rev=285185&r1=285184&r2=285185&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/indvar-discriminator.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/indvar-discriminator.ll Wed Oct 26 05:28:32 2016
@@ -2,6 +2,8 @@
 ;
 ; When the induction variable is widened by indvars, check that the debug loc
 ; associated with the loop increment is correctly propagated.
+; Also, when the exit condition of a loop is rewritten to be a canonical !=
+; comparison, check that the debug loc of the orginal comparison is reused.
 ;
 ; Test case obtained from the following source code:
 ;
@@ -19,10 +21,16 @@
 ; Check that the debug location for the loop increment still refers to
 ; line 4, column 26, discriminator 2.
 ;
+; Check that the canonicalized compare instruction for the loop exit
+; condition still refers to line 4, column 21, discriminator 1.
+;
 ; CHECK-LABEL: for.body:
 ; CHECK: [[PHI:%[0-9a-zA-Z.]+]] = phi i64 [
 ; CHECK-LABEL: for.inc:
 ; CHECK: add nuw nsw i64 [[PHI]], 1, !dbg ![[INDVARMD:[0-9]+]]
+; CHECK: icmp ne i64 %{{.+}}, %{{.+}}, !dbg ![[ICMPMD:[0-9]+]]
+; CHECK-DAG: ![[ICMPMD]] = !DILocation(line: 4, column: 21, scope: ![[ICMPSCOPEMD:[0-9]+]]
+; CHECK-DAG: ![[ICMPSCOPEMD]] = !DILexicalBlockFile(scope: !{{[0-9]+}}, file: !{{[0-9]+}}, discriminator: 1)
 ; CHECK-DAG: ![[INDVARMD]] = !DILocation(line: 4, column: 26, scope: ![[INDVARSCOPEMD:[0-9]+]])
 ; CHECK-DAG: ![[INDVARSCOPEMD]] = !DILexicalBlockFile(scope: !{{[0-9]+}}, file: !{{[0-9]+}}, discriminator: 2)
 




More information about the llvm-commits mailing list