[PATCH] D49347: [WIP][DebugInfo][InstCombine] DebugLoc in induction PHI

Anastasis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 16 09:40:17 PDT 2018


gramanas updated this revision to Diff 155705.
gramanas added a comment.

- styling nit


Repository:
  rL LLVM

https://reviews.llvm.org/D49347

Files:
  lib/Transforms/Vectorize/LoopVectorize.cpp
  test/Transforms/LoopVectorize/discriminator.ll
  test/Transforms/LoopVectorize/i8-induction.ll


Index: test/Transforms/LoopVectorize/i8-induction.ll
===================================================================
--- test/Transforms/LoopVectorize/i8-induction.ll
+++ test/Transforms/LoopVectorize/i8-induction.ll
@@ -10,7 +10,9 @@
 ; Check that the induction phis and adds have debug location.
 ;
 ; DEBUGLOC-LABEL: vector.body:
-; DEBUGLOC:         %vec.ind = phi {{.*}}, !dbg ![[DbgLoc:[0-9]+]]
+; DEBUGLOC:         %index = phi {{.*}}, !dbg ![[DbgLoc:[0-9]+]]
+; DEBUGLOC:         %vec.ind = phi {{.*}}, !dbg ![[DbgLoc]]
+; DEBUGLOC:         %index.next = add {{.*}}, !dbg ![[DbgLoc]]
 ; DEBUGLOC:         %vec.ind.next = add {{.*}}, !dbg ![[DbgLoc]]
 
 scalar.ph:
Index: test/Transforms/LoopVectorize/discriminator.ll
===================================================================
--- test/Transforms/LoopVectorize/discriminator.ll
+++ test/Transforms/LoopVectorize/discriminator.ll
@@ -47,8 +47,8 @@
 ;LOOPUNROLL_5: discriminator: 21
 ; When unrolling after loop vectorize, both vec_body and remainder loop
 ; are unrolled.
-;LOOPVEC_UNROLL: discriminator: 385
 ;LOOPVEC_UNROLL: discriminator: 9
+;LOOPVEC_UNROLL: discriminator: 385
 ;DBG_VALUE: ![[DBG]] = {{.*}}, scope: ![[TOP]]
 
 !llvm.dbg.cu = !{!0}
Index: lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- lib/Transforms/Vectorize/LoopVectorize.cpp
+++ lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -467,7 +467,7 @@
 
   /// Create a new induction variable inside L.
   PHINode *createInductionVariable(Loop *L, Value *Start, Value *End,
-                                   Value *Step, Instruction *DL);
+                                   Value *Step, DebugLoc *OldInductionDL);
 
   /// Handle all cross-iteration phis in the header.
   void fixCrossIterationPHIs();
@@ -2558,23 +2558,21 @@
     PredicatedInstructions.push_back(Cloned);
 }
 
-PHINode *InnerLoopVectorizer::createInductionVariable(Loop *L, Value *Start,
-                                                      Value *End, Value *Step,
-                                                      Instruction *DL) {
+PHINode *InnerLoopVectorizer::createInductionVariable(
+    Loop *L, Value *Start, Value *End, Value *Step, DebugLoc *OldInductionDL) {
   BasicBlock *Header = L->getHeader();
   BasicBlock *Latch = L->getLoopLatch();
   // As we're just creating this loop, it's possible no latch exists
   // yet. If so, use the header as this will be a single block loop.
   if (!Latch)
     Latch = Header;
 
   IRBuilder<> Builder(&*Header->getFirstInsertionPt());
-  Instruction *OldInst = getDebugLocFromInstOrOperands(OldInduction);
-  setDebugLocFromInst(Builder, OldInst);
+  Builder.SetCurrentDebugLocation(*OldInductionDL);
   auto *Induction = Builder.CreatePHI(Start->getType(), 2, "index");
 
   Builder.SetInsertPoint(Latch->getTerminator());
-  setDebugLocFromInst(Builder, OldInst);
+  Builder.SetCurrentDebugLocation(*OldInductionDL);
 
   // Create i+1 and fill the PHINode.
   Value *Next = Builder.CreateAdd(Induction, Step, "index.next");
@@ -2886,14 +2884,27 @@
   // faster.
   emitMemRuntimeChecks(Lp, ScalarPH);
 
+  // OldInduction could be nullptr. In that case we want the Debug Location
+  // from the old induction phi to be passed on to the new one.
+  DebugLoc InductionDL;
+  if (!OldInduction) {
+    for (const auto &phi : OldBasicBlock->phis()) {
+      if (Legal->isInductionPhi(&phi)) {
+        InductionDL = phi.getDebugLoc();
+        break;
+      }
+    }
+  } else {
+    InductionDL = getDebugLocFromInstOrOperands(OldInduction)->getDebugLoc();
+  }
+
   // Generate the induction variable.
   // The loop step is equal to the vectorization factor (num of SIMD elements)
   // times the unroll factor (num of SIMD instructions).
   Value *CountRoundDown = getOrCreateVectorTripCount(Lp);
   Constant *Step = ConstantInt::get(IdxTy, VF * UF);
   Induction =
-      createInductionVariable(Lp, StartIdx, CountRoundDown, Step,
-                              getDebugLocFromInstOrOperands(OldInduction));
+      createInductionVariable(Lp, StartIdx, CountRoundDown, Step, &InductionDL);
 
   // We are going to resume the execution of the scalar loop.
   // Go over all of the induction variables that we found and fix the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49347.155705.patch
Type: text/x-patch
Size: 4267 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180716/6190432a/attachment.bin>


More information about the llvm-commits mailing list