<div dir="ltr"><div><div><div>Hi David,<br><br>I reverted the commit because a ubsan test was failing.  It turned out the test was fragile, so I fixed the test in r285208 (commit message below).<br></div><br></div>Thanks,<br></div><div>Rob.<br><br></div><div><div><pre class="gmail-vc_log">[ubsan] Fix vptr.cpp test to be more resilient. NFC.

The test contains a switch statement in which two of the cases are
tail-merged, with the call to __ubsan_handle_dynamic_type_cache_miss_abort
in the common tail. When tail-merging occurs, the debug location of the
tail is randomly taken from one of the merge inputs.  Luckily for the test,
the expected line number in the check is the one which is chosen by the
tail-merge.  However, if the switch cases are re-ordered the test will
fail.

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