<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 26, 2016 at 10:11 AM Robert Lougher via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rlougher<br class="gmail_msg">
Date: Wed Oct 26 12:01:47 2016<br class="gmail_msg">
New Revision: 285212<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=285212&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=285212&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
Reapply: "Remove debug location from common tail when tail-merging"<br class="gmail_msg">
<br class="gmail_msg">
This reapplies revision 285093. </blockquote><div><br>What was the fix that made this commit of the same change work where the previous one was reverted? (please mention this in future commit messages - it makes it easier to review the changes, etc)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Original commit message:<br class="gmail_msg">
<br class="gmail_msg">
The branch folding pass tail merges blocks into a common-tail. However, the<br class="gmail_msg">
tail retains the debug information from one of the original inputs to the<br class="gmail_msg">
merge (chosen randomly). This is a problem for sampled-based PGO, as hits<br class="gmail_msg">
on the common-tail will be attributed to whichever block was chosen,<br class="gmail_msg">
irrespective of which path was actually taken to the common-tail.<br class="gmail_msg">
<br class="gmail_msg">
This patch fixes the issue by nulling the debug location for the common-tail.<br class="gmail_msg">
<br class="gmail_msg">
Differential Revision: <a href="https://reviews.llvm.org/D25742" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D25742</a><br class="gmail_msg">
<br class="gmail_msg">
Added:<br class="gmail_msg">
llvm/trunk/test/DebugInfo/X86/tail-merge.ll<br class="gmail_msg">
Modified:<br class="gmail_msg">
llvm/trunk/lib/CodeGen/BranchFolding.cpp<br class="gmail_msg">
llvm/trunk/test/DebugInfo/COFF/local-variables.ll<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/lib/CodeGen/BranchFolding.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/BranchFolding.cpp?rev=285212&r1=285211&r2=285212&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/BranchFolding.cpp?rev=285212&r1=285211&r2=285212&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/lib/CodeGen/BranchFolding.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/lib/CodeGen/BranchFolding.cpp Wed Oct 26 12:01:47 2016<br class="gmail_msg">
@@ -720,8 +720,6 @@ bool BranchFolder::CreateCommonTailOnlyB<br class="gmail_msg">
SameTails[commonTailIndex].getTailStartPos();<br class="gmail_msg">
MachineBasicBlock *MBB = SameTails[commonTailIndex].getBlock();<br class="gmail_msg">
<br class="gmail_msg">
- // If the common tail includes any debug info we will take it pretty<br class="gmail_msg">
- // randomly from one of the inputs. Might be better to remove it?<br class="gmail_msg">
DEBUG(dbgs() << "\nSplitting BB#" << MBB->getNumber() << ", size "<br class="gmail_msg">
<< maxCommonTailLength);<br class="gmail_msg">
<br class="gmail_msg">
@@ -898,6 +896,11 @@ bool BranchFolder::TryTailMergeBlocks(Ma<br class="gmail_msg">
// Recompute common tail MBB's edge weights and block frequency.<br class="gmail_msg">
setCommonTailEdgeWeights(*MBB);<br class="gmail_msg">
<br class="gmail_msg">
+ // Remove the original debug location from the common tail.<br class="gmail_msg">
+ for (auto &MI : *MBB)<br class="gmail_msg">
+ if (!MI.isDebugValue())<br class="gmail_msg">
+ MI.setDebugLoc(DebugLoc());<br class="gmail_msg">
+<br class="gmail_msg">
// MBB is common tail. Adjust all other BB's to jump to this one.<br class="gmail_msg">
// Traversal must be forwards so erases work.<br class="gmail_msg">
DEBUG(dbgs() << "\nUsing common tail in BB#" << MBB->getNumber()<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/test/DebugInfo/COFF/local-variables.ll<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/local-variables.ll?rev=285212&r1=285211&r2=285212&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/local-variables.ll?rev=285212&r1=285211&r2=285212&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/test/DebugInfo/COFF/local-variables.ll (original)<br class="gmail_msg">
+++ llvm/trunk/test/DebugInfo/COFF/local-variables.ll Wed Oct 26 12:01:47 2016<br class="gmail_msg">
@@ -63,11 +63,9 @@<br class="gmail_msg">
; ASM: .cv_loc 2 1 5 3 # t.cpp:5:3<br class="gmail_msg">
; ASM: callq capture<br class="gmail_msg">
; ASM: leaq 36(%rsp), %rcx<br class="gmail_msg">
-; ASM: [[inline_site2_end:\.Ltmp.*]]:<br class="gmail_msg">
+; ASM: [[else_end:\.Ltmp.*]]:<br class="gmail_msg">
; ASM: .LBB0_3: # %if.end<br class="gmail_msg">
-; ASM: .cv_loc 0 1 15 5 # t.cpp:15:5<br class="gmail_msg">
; ASM: callq capture<br class="gmail_msg">
-; ASM: [[else_end:\.Ltmp.*]]:<br class="gmail_msg">
; ASM: .cv_loc 0 1 17 1 # t.cpp:17:1<br class="gmail_msg">
; ASM: nop<br class="gmail_msg">
; ASM: addq $56, %rsp<br class="gmail_msg">
@@ -101,7 +99,7 @@<br class="gmail_msg">
; ASM: .long 116 # TypeIndex<br class="gmail_msg">
; ASM: .short 0 # Flags<br class="gmail_msg">
; ASM: .asciz "v"<br class="gmail_msg">
-; ASM: .cv_def_range [[inline_site2]] [[inline_site2_end]], "E\021O\001\000\0000\000\000\000"<br class="gmail_msg">
+; ASM: .cv_def_range [[inline_site2]] [[else_end]], "E\021O\001\000\0000\000\000\000"<br class="gmail_msg">
; ASM: .short 4430 # Record kind: S_INLINESITE_END<br class="gmail_msg">
<br class="gmail_msg">
; OBJ: Subsection [<br class="gmail_msg">
@@ -159,7 +157,7 @@<br class="gmail_msg">
; OBJ: LocalVariableAddrRange {<br class="gmail_msg">
; OBJ: OffsetStart: .text+0x2D<br class="gmail_msg">
; OBJ: ISectStart: 0x0<br class="gmail_msg">
-; OBJ: Range: 0x24<br class="gmail_msg">
+; OBJ: Range: 0x1F<br class="gmail_msg">
; OBJ: }<br class="gmail_msg">
; OBJ: }<br class="gmail_msg">
; OBJ: InlineSite {<br class="gmail_msg">
@@ -200,7 +198,7 @@<br class="gmail_msg">
; OBJ: ChangeLineOffset: 1<br class="gmail_msg">
; OBJ: ChangeCodeOffset: 0x35<br class="gmail_msg">
; OBJ: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xD, LineOffset: 1}<br class="gmail_msg">
-; OBJ: ChangeCodeLength: 0xA<br class="gmail_msg">
+; OBJ: ChangeCodeLength: 0xF<br class="gmail_msg">
; OBJ: ]<br class="gmail_msg">
; OBJ: }<br class="gmail_msg">
; OBJ: Local {<br class="gmail_msg">
<br class="gmail_msg">
Added: llvm/trunk/test/DebugInfo/X86/tail-merge.ll<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/tail-merge.ll?rev=285212&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/tail-merge.ll?rev=285212&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/test/DebugInfo/X86/tail-merge.ll (added)<br class="gmail_msg">
+++ llvm/trunk/test/DebugInfo/X86/tail-merge.ll Wed Oct 26 12:01:47 2016<br class="gmail_msg">
@@ -0,0 +1,76 @@<br class="gmail_msg">
+; RUN: llc %s -mtriple=x86_64-unknown-unknown -use-unknown-locations=true -o - | FileCheck %s<br class="gmail_msg">
+<br class="gmail_msg">
+; Generated with "clang -gline-tables-only -c -emit-llvm -o - | opt -sroa -S"<br class="gmail_msg">
+; from source:<br class="gmail_msg">
+;<br class="gmail_msg">
+; extern int foo(int);<br class="gmail_msg">
+; extern int bar(int);<br class="gmail_msg">
+;<br class="gmail_msg">
+; int test(int a, int b) {<br class="gmail_msg">
+; if(b)<br class="gmail_msg">
+; a += foo(a);<br class="gmail_msg">
+; else<br class="gmail_msg">
+; a += bar(a);<br class="gmail_msg">
+; return a;<br class="gmail_msg">
+; }<br class="gmail_msg">
+<br class="gmail_msg">
+; When tail-merging the debug location of the common tail should be removed.<br class="gmail_msg">
+<br class="gmail_msg">
+; CHECK-LABEL: test:<br class="gmail_msg">
+; CHECK: movl %edi, [[REG:%.*]]<br class="gmail_msg">
+; CHECK: testl %esi, %esi<br class="gmail_msg">
+; CHECK: je [[ELSE:.LBB[0-9]+_[0-9]+]]<br class="gmail_msg">
+; CHECK: .loc 1 6 10<br class="gmail_msg">
+; CHECK: callq foo<br class="gmail_msg">
+; CHECK: jmp [[TAIL:.LBB[0-9]+_[0-9]+]]<br class="gmail_msg">
+; CHECK: [[ELSE]]:<br class="gmail_msg">
+; CHECK: .loc 1 8 10<br class="gmail_msg">
+; CHECK: callq bar<br class="gmail_msg">
+; CHECK: [[TAIL]]:<br class="gmail_msg">
+; CHECK: .loc 1 0 0<br class="gmail_msg">
+; CHECK: addl [[REG]], %eax<br class="gmail_msg">
+; CHECK: .loc 1 9 3<br class="gmail_msg">
+<br class="gmail_msg">
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br class="gmail_msg">
+target triple = "x86_64-unknown-linux-gnu"<br class="gmail_msg">
+<br class="gmail_msg">
+define i32 @test(i32 %a, i32 %b) !dbg !6 {<br class="gmail_msg">
+entry:<br class="gmail_msg">
+ %tobool = icmp ne i32 %b, 0, !dbg !8<br class="gmail_msg">
+ br i1 %tobool, label %if.then, label %if.else, !dbg !8<br class="gmail_msg">
+<br class="gmail_msg">
+if.then: ; preds = %entry<br class="gmail_msg">
+ %call = call i32 @foo(i32 %a), !dbg !9<br class="gmail_msg">
+ %add = add nsw i32 %a, %call, !dbg !10<br class="gmail_msg">
+ br label %if.end, !dbg !11<br class="gmail_msg">
+<br class="gmail_msg">
+if.else: ; preds = %entry<br class="gmail_msg">
+ %call1 = call i32 @bar(i32 %a), !dbg !12<br class="gmail_msg">
+ %add2 = add nsw i32 %a, %call1, !dbg !13<br class="gmail_msg">
+ br label %if.end<br class="gmail_msg">
+<br class="gmail_msg">
+if.end: ; preds = %if.else, %if.then<br class="gmail_msg">
+ %a.addr.0 = phi i32 [ %add, %if.then ], [ %add2, %if.else ]<br class="gmail_msg">
+ ret i32 %a.addr.0, !dbg !14<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+declare i32 @foo(i32)<br class="gmail_msg">
+declare i32 @bar(i32)<br class="gmail_msg">
+<br class="gmail_msg">
+!<a href="http://llvm.dbg.cu" rel="noreferrer" class="gmail_msg" target="_blank">llvm.dbg.cu</a> = !{!0}<br class="gmail_msg">
+!llvm.module.flags = !{!3, !4}<br class="gmail_msg">
+<br class="gmail_msg">
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)<br class="gmail_msg">
+!1 = !DIFile(filename: "test.c", directory: "")<br class="gmail_msg">
+!2 = !{}<br class="gmail_msg">
+!3 = !{i32 2, !"Dwarf Version", i32 4}<br class="gmail_msg">
+!4 = !{i32 2, !"Debug Info Version", i32 3}<br class="gmail_msg">
+!6 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !7, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)<br class="gmail_msg">
+!7 = !DISubroutineType(types: !2)<br class="gmail_msg">
+!8 = !DILocation(line: 5, column: 6, scope: !6)<br class="gmail_msg">
+!9 = !DILocation(line: 6, column: 10, scope: !6)<br class="gmail_msg">
+!10 = !DILocation(line: 6, column: 7, scope: !6)<br class="gmail_msg">
+!11 = !DILocation(line: 6, column: 5, scope: !6)<br class="gmail_msg">
+!12 = !DILocation(line: 8, column: 10, scope: !6)<br class="gmail_msg">
+!13 = !DILocation(line: 8, column: 7, scope: !6)<br class="gmail_msg">
+!14 = !DILocation(line: 9, column: 3, scope: !6)<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
llvm-commits mailing list<br class="gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div></div>