<div dir="ltr">Ah, nice catch.<div><br></div><div>Thanks Alexey!</div><div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jun 11, 2015 at 11:43 AM Alexey Samsonov <<a href="mailto:vonosmas@gmail.com">vonosmas@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: samsonov<br>
Date: Thu Jun 11 13:25:54 2015<br>
New Revision: 239551<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239551-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=c01hi44VuF6StKa1pkGQO3LhVLJddgOfuG2xS2pRe30&s=RO4g7XXW6-hXOALcxPp4RGe6TH4TQ0nbf8joT-Vkr4I&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=239551&view=rev</a><br>
Log:<br>
Set proper debug location for branch added in BasicBlock::splitBasicBlock().<br>
<br>
This improves debug locations in passes that do a lot of basic block<br>
transformations. Important case is LoopUnroll pass, the test for correct<br>
debug locations accompanies this change.<br>
<br>
Test Plan: regression test suite<br>
<br>
Reviewers: dblaikie, sanjoy<br>
<br>
Subscribers: llvm-commits<br>
<br>
Differential Revision: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10367&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=c01hi44VuF6StKa1pkGQO3LhVLJddgOfuG2xS2pRe30&s=0YLkh5MWqYLiTtsmduSEqlUhhKRAk3Btoy1mgTxgwko&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/D10367</a><br>
<br>
Modified:<br>
    llvm/trunk/lib/IR/BasicBlock.cpp<br>
    llvm/trunk/test/Transforms/LoopUnroll/runtime-loop1.ll<br>
<br>
Modified: llvm/trunk/lib/IR/BasicBlock.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_IR_BasicBlock.cpp-3Frev-3D239551-26r1-3D239550-26r2-3D239551-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=c01hi44VuF6StKa1pkGQO3LhVLJddgOfuG2xS2pRe30&s=8CofUNi9yjFw9RkEbgjgemvKUDL2ecjB0ISbHWyszEE&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/BasicBlock.cpp?rev=239551&r1=239550&r2=239551&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/BasicBlock.cpp (original)<br>
+++ llvm/trunk/lib/IR/BasicBlock.cpp Thu Jun 11 13:25:54 2015<br>
@@ -362,12 +362,15 @@ BasicBlock *BasicBlock::splitBasicBlock(<br>
   BasicBlock *New = BasicBlock::Create(getContext(), BBName,<br>
                                        getParent(), InsertBefore);<br>
<br>
+  // Save DebugLoc of split point before invalidating iterator.<br>
+  DebugLoc Loc = I->getDebugLoc();<br>
   // Move all of the specified instructions from the original basic block into<br>
   // the new basic block.<br>
   New->getInstList().splice(New->end(), this->getInstList(), I, end());<br>
<br>
   // Add a branch instruction to the newly formed basic block.<br>
-  BranchInst::Create(New, this);<br>
+  BranchInst *BI = BranchInst::Create(New, this);<br>
+  BI->setDebugLoc(Loc);<br>
<br>
   // Now we must loop through all of the successors of the New block (which<br>
   // _were_ the successors of the 'this' block), and update any PHI nodes in<br>
<br>
Modified: llvm/trunk/test/Transforms/LoopUnroll/runtime-loop1.ll<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_Transforms_LoopUnroll_runtime-2Dloop1.ll-3Frev-3D239551-26r1-3D239550-26r2-3D239551-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=c01hi44VuF6StKa1pkGQO3LhVLJddgOfuG2xS2pRe30&s=sdsSkZKEJI3qZDJArks4mkpgK6gTUNpSROcYusqZFsQ&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/runtime-loop1.ll?rev=239551&r1=239550&r2=239551&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/LoopUnroll/runtime-loop1.ll (original)<br>
+++ llvm/trunk/test/Transforms/LoopUnroll/runtime-loop1.ll Thu Jun 11 13:25:54 2015<br>
@@ -2,29 +2,50 @@<br>
<br>
 ; This tests that setting the unroll count works<br>
<br>
+; CHECK: for.body.preheader:<br>
+; CHECK:   br {{.*}} label %for.body.prol, label %for.body.preheader.split, !dbg [[PH_LOC:![0-9]+]]<br>
 ; CHECK: for.body.prol:<br>
-; CHECK: br label %for.body.preheader.split<br>
+; CHECK:   br label %for.body.preheader.split, !dbg [[BODY_LOC:![0-9]+]]<br>
+; CHECK: for.body.preheader.split:<br>
+; CHECK:   br {{.*}} label %for.end.loopexit, label %for.body.preheader.split.split, !dbg [[PH_LOC]]<br>
 ; CHECK: for.body:<br>
-; CHECK: br i1 %exitcond.1, label %for.end.loopexit.unr-lcssa, label %for.body<br>
+; CHECK:   br i1 %exitcond.1, label %for.end.loopexit.unr-lcssa, label %for.body, !dbg [[BODY_LOC]]<br>
 ; CHECK-NOT: br i1 %exitcond.4, label %for.end.loopexit{{.*}}, label %for.body<br>
<br>
+; CHECK-DAG: [[PH_LOC]] = !DILocation(line: 101, column: 1, scope: !{{.*}})<br>
+; CHECK-DAG: [[BODY_LOC]] = !DILocation(line: 102, column: 1, scope: !{{.*}})<br>
+<br>
 define i32 @test(i32* nocapture %a, i32 %n) nounwind uwtable readonly {<br>
 entry:<br>
-  %cmp1 = icmp eq i32 %n, 0<br>
-  br i1 %cmp1, label %for.end, label %for.body<br>
+  %cmp1 = icmp eq i32 %n, 0, !dbg !7<br>
+  br i1 %cmp1, label %for.end, label %for.body, !dbg !7<br>
<br>
 for.body:                                         ; preds = %for.body, %entry<br>
   %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]<br>
   %sum.02 = phi i32 [ %add, %for.body ], [ 0, %entry ]<br>
-  %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv<br>
-  %0 = load i32, i32* %arrayidx, align 4<br>
-  %add = add nsw i32 %0, %sum.02<br>
-  %indvars.iv.next = add i64 %indvars.iv, 1<br>
-  %lftr.wideiv = trunc i64 %indvars.iv.next to i32<br>
-  %exitcond = icmp eq i32 %lftr.wideiv, %n<br>
-  br i1 %exitcond, label %for.end, label %for.body<br>
+  %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv, !dbg !8<br>
+  %0 = load i32, i32* %arrayidx, align 4, !dbg !8<br>
+  %add = add nsw i32 %0, %sum.02, !dbg !8<br>
+  %indvars.iv.next = add i64 %indvars.iv, 1, !dbg !9<br>
+  %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !9<br>
+  %exitcond = icmp eq i32 %lftr.wideiv, %n, !dbg !9<br>
+  br i1 %exitcond, label %for.end, label %for.body, !dbg !9<br>
<br>
 for.end:                                          ; preds = %for.body, %entry<br>
   %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ]<br>
-  ret i32 %sum.0.lcssa<br>
+  ret i32 %sum.0.lcssa, !dbg !10<br>
 }<br>
+<br>
+!llvm.module.flags = !{!0, !1, !2}<br>
+!0 = !{i32 2, !"Dwarf Version", i32 4}<br>
+!1 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!2 = !{i32 1, !"PIC Level", i32 2}<br>
+<br>
+!3 = !{}<br>
+!4 = !DISubroutineType(types: !3)<br>
+!5 = !DIFile(filename: "test.cpp", directory: "/tmp")<br>
+!6 = !DISubprogram(name: "test", scope: !5, file: !5, line: 99, type: !4, isLocal: false, isDefinition: true, scopeLine: 100, flags: DIFlagPrototyped, isOptimized: false, function: i32 (i32*, i32)* @test, variables: !3)<br>
+!7 = !DILocation(line: 100, column: 1, scope: !6)<br>
+!8 = !DILocation(line: 101, column: 1, scope: !6)<br>
+!9 = !DILocation(line: 102, column: 1, scope: !6)<br>
+!10 = !DILocation(line: 103, column: 1, scope: !6)<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>