<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">As promised, here are bug reports for differences in `opt -O1` output with/without debug info present:<div class=""><br class=""></div><div class=""><a href="https://bugs.llvm.org/show_bug.cgi?id=37713" class="">https://bugs.llvm.org/show_bug.cgi?id=37713</a> (instcombine, stacksaverestore.ll)</div><div class=""><a href="https://bugs.llvm.org/show_bug.cgi?id=37714" class="">https://bugs.llvm.org/show_bug.cgi?id=37714</a> (instcombine, call-guard.ll)</div><div class=""><a href="https://bugs.llvm.org/show_bug.cgi?id=37715" class="">https://bugs.llvm.org/show_bug.cgi?id=37715</a> (guard-widening, range-check-merging.ll)</div><div class=""><br class=""></div><div class="">vedant</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jun 6, 2018, at 12:05 PM, Vedant Kumar via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Author: vedantk<br class="">Date: Wed Jun  6 12:05:42 2018<br class="">New Revision: 334118<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=334118&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=334118&view=rev</a><br class="">Log:<br class="">[Debugify] Move debug value intrinsics closer to their operand defs<br class=""><br class="">Before this patch, debugify would insert debug value intrinsics before the<br class="">terminating instruction in a block. This had the advantage of being simple,<br class="">but was a bit too simple/unrealistic.<br class=""><br class="">This patch teaches debugify to insert debug values immediately after their<br class="">operand defs. This enables better testing of the compiler.<br class=""><br class="">For example, with this patch, `opt -debugify-each` is able to identify a<br class="">vectorizer DI-invariance bug fixed in <a href="http://llvm.org/PR32761" class="">llvm.org/PR32761</a>. In this bug, the<br class="">vectorizer produced different output with/without debug info present.<br class=""><br class="">Reverting Davide's bugfix locally, I see:<br class=""><br class="">$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \<br class="">  .../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer<br class="">Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll<br class="">  Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf<br class="">  With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet<br class="">9,11c9,11<br class=""><   %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1<br class=""><   %6 = bitcast i64* %4 to <2 x i64>*<br class=""><   %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0<br class="">---<br class=""><blockquote type="cite" class="">  %5 = load i64, i64* %4, align 8, !tbaa !0<br class="">  %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1<br class="">  %7 = load i64, i64* %6, align 8, !tbaa !5<br class=""></blockquote>12a13<br class=""><blockquote type="cite" class="">  store i64 %5, i64* %8, align 8, !tbaa !0<br class=""></blockquote>14,15c15<br class=""><   %10 = bitcast i64* %8 to <2 x i64>*<br class=""><   store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0<br class="">---<br class=""><blockquote type="cite" class="">  store i64 %7, i64* %9, align 8, !tbaa !5<br class=""></blockquote>:: Found a test case ^<br class=""><br class="">Running this over the *.ll files in tree, I found four additional examples<br class="">which compile differently with/without DI present. I plan on filing bugs for<br class="">these.<br class=""><br class="">Modified:<br class="">    llvm/trunk/test/Transforms/DeadStoreElimination/debuginfo.ll<br class="">    llvm/trunk/test/Transforms/GVN/PRE/phi-translate-2.ll<br class="">    llvm/trunk/test/Transforms/GVN/fence.ll<br class="">    llvm/trunk/tools/opt/Debugify.cpp<br class=""><br class="">Modified: llvm/trunk/test/Transforms/DeadStoreElimination/debuginfo.ll<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadStoreElimination/debuginfo.ll?rev=334118&r1=334117&r2=334118&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadStoreElimination/debuginfo.ll?rev=334118&r1=334117&r2=334118&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/Transforms/DeadStoreElimination/debuginfo.ll (original)<br class="">+++ llvm/trunk/test/Transforms/DeadStoreElimination/debuginfo.ll Wed Jun  6 12:05:42 2018<br class="">@@ -7,17 +7,17 @@ declare noalias i8* @malloc(i32)<br class=""> declare void @test_f()<br class=""><br class=""> define i32* @test_salvage() {<br class="">+; Check that all four original local variables have their values preserved.<br class=""> ; CHECK-LABEL: @test_salvage()<br class=""> ; CHECK-NEXT: malloc<br class="">-; CHECK-NEXT: bitcast<br class="">-; CHECK-NEXT: call void @test_f()<br class="">-; CHECK-NEXT: store i32 0, i32* %P<br class="">-<br class="">-; Check that all four original local variables have their values preserved.<br class=""> ; CHECK-NEXT: @llvm.dbg.value(metadata i8* %p, metadata ![[p:.*]], metadata !DIExpression())<br class="">+; CHECK-NEXT: bitcast<br class=""> ; CHECK-NEXT: @llvm.dbg.value(metadata i32* %P, metadata ![[P:.*]], metadata !DIExpression())<br class=""> ; CHECK-NEXT: @llvm.dbg.value(metadata i32* %P, metadata ![[DEAD:.*]], metadata !DIExpression(DW_OP_deref))<br class=""> ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32* %P, metadata ![[DEAD2:.*]], metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 1, DW_OP_stack_value))<br class="">+; CHECK-NEXT: call void @test_f()<br class="">+; CHECK-NEXT: store i32 0, i32* %P<br class="">+<br class="">   %p = tail call i8* @malloc(i32 4)<br class="">   %P = bitcast i8* %p to i32*<br class="">   %DEAD = load i32, i32* %P<br class=""><br class="">Modified: llvm/trunk/test/Transforms/GVN/PRE/phi-translate-2.ll<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/PRE/phi-translate-2.ll?rev=334118&r1=334117&r2=334118&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/PRE/phi-translate-2.ll?rev=334118&r1=334117&r2=334118&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/Transforms/GVN/PRE/phi-translate-2.ll (original)<br class="">+++ llvm/trunk/test/Transforms/GVN/PRE/phi-translate-2.ll Wed Jun  6 12:05:42 2018<br class="">@@ -141,9 +141,9 @@ critedge.loopexit:<br class=""> ; CHECK: br label %if.end3<br class=""> ; CHECK: if.end3:<br class=""> ; CHECK: %[[PREPHI:.*]] = phi i64 [ %sub.ptr.sub, %if.else ], [ %[[SUB]], %if.then2 ], [ %sub.ptr.sub, %entry ]<br class="">-; CHECK: %[[DIV:.*]] = ashr exact i64 %[[PREPHI]], 2<br class=""> ; CHECK: call void @llvm.dbg.value(metadata i32* %p.0, metadata [[var_p0:![0-9]+]], metadata !DIExpression())<br class=""> ; CHECK: call void @llvm.dbg.value(metadata i64 %sub.ptr.rhs.cast5.pre-phi, metadata [[var_sub_ptr:![0-9]+]], metadata !DIExpression())<br class="">+; CHECK: %[[DIV:.*]] = ashr exact i64 %[[PREPHI]], 2<br class=""> ; CHECK: ret i64 %[[DIV]]<br class=""><br class=""> declare void @bar(...) local_unnamed_addr #1<br class=""><br class="">Modified: llvm/trunk/test/Transforms/GVN/fence.ll<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/fence.ll?rev=334118&r1=334117&r2=334118&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/fence.ll?rev=334118&r1=334117&r2=334118&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/Transforms/GVN/fence.ll (original)<br class="">+++ llvm/trunk/test/Transforms/GVN/fence.ll Wed Jun  6 12:05:42 2018<br class="">@@ -18,10 +18,10 @@ define i32 @test(i32* %addr.i) {<br class=""> ; Same as above<br class=""> define i32 @test2(i32* %addr.i) {<br class=""> ; CHECK-LABEL: @test2<br class="">-; CHECK-NEXT: fence<br class=""> ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32* %addr.i, metadata [[var_a:![0-9]+]], metadata !DIExpression(DW_OP_deref))<br class="">-; CHECK-NEXT: call void @llvm.dbg.value(metadata i32* %addr.i, metadata [[var_a2:![0-9]+]], metadata !DIExpression(DW_OP_deref))<br class="">+; CHECK-NEXT: fence<br class=""> ; CHECK-NOT: load<br class="">+; CHECK-NEXT: call void @llvm.dbg.value(metadata i32* %addr.i, metadata [[var_a2:![0-9]+]], metadata !DIExpression(DW_OP_deref))<br class=""> ; CHECK: ret<br class="">   %a = load i32, i32* %addr.i, align 4<br class="">   fence release<br class=""><br class="">Modified: llvm/trunk/tools/opt/Debugify.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/Debugify.cpp?rev=334118&r1=334117&r2=334118&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/Debugify.cpp?rev=334118&r1=334117&r2=334118&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/tools/opt/Debugify.cpp (original)<br class="">+++ llvm/trunk/tools/opt/Debugify.cpp Wed Jun  6 12:05:42 2018<br class="">@@ -44,12 +44,11 @@ bool isFunctionSkipped(Function &F) {<br class="">   return F.isDeclaration() || !F.hasExactDefinition();<br class=""> }<br class=""><br class="">-/// Find a suitable insertion point for debug values intrinsics.<br class="">+/// Find the basic block's terminating instruction.<br class=""> ///<br class="">-/// These must be inserted before the terminator. Special care is needed to<br class="">-/// handle musttail and deopt calls, as these behave like (but are in fact not)<br class="">-/// terminators.<br class="">-Instruction *findDebugValueInsertionPoint(BasicBlock &BB) {<br class="">+/// Special care is needed to handle musttail and deopt calls, as these behave<br class="">+/// like (but are in fact not) terminators.<br class="">+Instruction *findTerminatingInstruction(BasicBlock &BB) {<br class="">   if (auto *I = BB.getTerminatingMustTailCall())<br class="">     return I;<br class="">   if (auto *I = BB.getTerminatingDeoptimizeCall())<br class="">@@ -109,28 +108,35 @@ bool applyDebugifyMetadata(Module &M,<br class="">       if (BB.isEHPad())<br class="">         continue;<br class=""><br class="">-      Instruction *LastInst = findDebugValueInsertionPoint(BB);<br class="">+      // Find the terminating instruction, after which no debug values are<br class="">+      // attached.<br class="">+      Instruction *LastInst = findTerminatingInstruction(BB);<br class="">+      assert(LastInst && "Expected basic block with a terminator");<br class="">+<br class="">+      // Maintain an insertion point which can't be invalidated when updates<br class="">+      // are made.<br class="">+      BasicBlock::iterator InsertPt = BB.getFirstInsertionPt();<br class="">+      assert(InsertPt != BB.end() && "Expected to find an insertion point");<br class="">+      Instruction *InsertBefore = &*InsertPt;<br class=""><br class="">       // Attach debug values.<br class="">-      for (auto It = BB.begin(), End = LastInst->getIterator(); It != End;<br class="">-           ++It) {<br class="">-        Instruction &I = *It;<br class="">-<br class="">+      for (Instruction *I = &*BB.begin(); I != LastInst; I = I->getNextNode()) {<br class="">         // Skip void-valued instructions.<br class="">-        if (I.getType()->isVoidTy())<br class="">+        if (I->getType()->isVoidTy())<br class="">           continue;<br class=""><br class="">-        // Skip any just-inserted intrinsics.<br class="">-        if (isa<DbgValueInst>(&I))<br class="">-          break;<br class="">+        // Phis and EH pads must be grouped at the beginning of the block.<br class="">+        // Only advance the insertion point when we finish visiting these.<br class="">+        if (!isa<PHINode>(I) && !I->isEHPad())<br class="">+          InsertBefore = I->getNextNode();<br class=""><br class="">         std::string Name = utostr(NextVar++);<br class="">-        const DILocation *Loc = I.getDebugLoc().get();<br class="">+        const DILocation *Loc = I->getDebugLoc().get();<br class="">         auto LocalVar = DIB.createAutoVariable(SP, Name, File, Loc->getLine(),<br class="">-                                               getCachedDIType(I.getType()),<br class="">+                                               getCachedDIType(I->getType()),<br class="">                                                /*AlwaysPreserve=*/true);<br class="">-        DIB.insertDbgValueIntrinsic(&I, LocalVar, DIB.createExpression(), Loc,<br class="">-                                    LastInst);<br class="">+        DIB.insertDbgValueIntrinsic(I, LocalVar, DIB.createExpression(), Loc,<br class="">+                                    InsertBefore);<br class="">       }<br class="">     }<br class="">     DIB.finalizeSubprogram(SP);<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></div></blockquote></div><br class=""></div></body></html>