[DebugInfo][LCSSA] Preserve debug location in lcssa phis
authorAnastasis Grammenos <anastasis.gramm2@gmail.com>
Tue, 31 Jul 2018 14:54:52 +0000 (14:54 +0000)
committerAnastasis Grammenos <anastasis.gramm2@gmail.com>
Tue, 31 Jul 2018 14:54:52 +0000 (14:54 +0000)
Summary:
When inserting lcssa Phi Nodes in the exit block
mak sure to preserve the original instructions DL.

Reviewers: vsk

Subscribers: JDevlieghere, llvm-commits

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

llvm-svn: 338391

llvm/lib/Transforms/Utils/LCSSA.cpp
llvm/test/Transforms/LCSSA/basictest.ll

index 31834af..a1f8e74 100644 (file)
@@ -144,7 +144,8 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
 
       PHINode *PN = PHINode::Create(I->getType(), PredCache.size(ExitBB),
                                     I->getName() + ".lcssa", &ExitBB->front());
-
+      // Get the debug location from the original instruction.
+      PN->setDebugLoc(I->getDebugLoc());
       // Add inputs from inside the loop for this PHI.
       for (BasicBlock *Pred : PredCache.get(ExitBB)) {
         PN->addIncoming(I, Pred);
index 910e6f8..7ca5520 100644 (file)
@@ -1,6 +1,6 @@
 ; RUN: opt < %s -lcssa -S | FileCheck %s
 ; RUN: opt < %s -passes=lcssa -S | FileCheck %s
-; RUN: opt < %s -debugify -lcssa -S | FileCheck -check-prefix=CHECK2 %s
+; RUN: opt < %s -debugify -lcssa -S | FileCheck -check-prefix=DEBUGIFY %s
 
 define void @lcssa(i1 %S2) {
 ; CHECK-LABEL: @lcssa
@@ -19,9 +19,12 @@ post.if:             ; preds = %if.false, %if.true
        br i1 %S2, label %loop.exit, label %loop.interior
 loop.exit:             ; preds = %post.if
 ; CHECK: %X3.lcssa = phi i32
-; CHECK2: call void @llvm.dbg.value(metadata i32 %X3.lcssa
+; DEBUGIFY: %X3.lcssa = phi i32 {{.*}}, !dbg ![[DbgLoc:[0-9]+]]
+; DEBUGIFY-NEXT: call void @llvm.dbg.value(metadata i32 %X3.lcssa
 ; CHECK: %X4 = add i32 3, %X3.lcssa
        %X4 = add i32 3, %X3            ; <i32> [#uses=0]
        ret void
 }
 
+; Make sure the lcssa phi has %X3's debug location
+; DEBUGIFY: ![[DbgLoc]] = !DILocation(line: 7