<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 5, 2014, at 1:26 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><br class=""><div class="gmail_quote">On Fri, Sep 5, 2014 at 1:13 PM, Adrian Prantl <span dir="ltr" class=""><<a href="mailto:aprantl@apple.com" target="_blank" class="">aprantl@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Sep 5, 2014, at 10:31 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank" class="">dblaikie@gmail.com</a>> wrote:</div><br class=""><div class=""><p dir="ltr" class=""><br class="">
On Sep 5, 2014 10:22 AM, "Adrian Prantl" <<a href="mailto:aprantl@apple.com" target="_blank" class="">aprantl@apple.com</a>> wrote:<br class="">
><br class="">
> Author: adrian<br class="">
> Date: Fri Sep  5 12:10:10 2014<br class="">
> New Revision: 217260<br class="">
><br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=217260&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=217260&view=rev</a><br class="">
> Log:<br class="">
> Set the parent pointer of cloned DBG_VALUE instructions correctly.<br class="">
> Fixes PR20523.<br class="">
><br class="">
> When spilling variables onto the stack, spillVirtReg() is setting the<br class="">
> parent pointer of the cloned DBG_VALUE intrinsic for the stack location<br class="">
> to the parent pointer of the original intrinsic. MachineInstr parent<br class="">
> pointers should however always point to the parent basic block.<br class="">
><br class="">
> MBB is shadowing the MBB member variable. The instruction still ends up<br class="">
> being inserted into the right basic block, because it's inserted after MI<br class="">
> which serves as the iterator.</p><p dir="ltr" class="">Perhaps we should assert that the iterator within the basic block?</p><div class=""><br class=""></div></div></blockquote></span>That makes sense on its own, but it wouldn’t help with catching the bug in the PR. I’ll add this as an additional assertion.</div></div></blockquote><div class=""><br class=""></div><div class="">Hmm, why not? Wouldn't that assertion fail - since the MI is not in the MBB in this case (before your patch)?</div></div></div></div></div></blockquote><div><br class=""></div><div>I meant, (int theory) if somebody really were to re-insert this line into the code, the MI assertion would still hold. (That is, if we insert that assertion at the beginning of the function — I may have misinterpreted you there). Anyway is fine really, I don’t care enough.</div><div><br class=""></div><div><span style="font-family: Menlo-Regular;" class="">      } else</span><br style="font-family: Menlo-Regular;" class=""><span style="font-family: Menlo-Regular;" class="">        DL = MI->getDebugLoc();</span><br style="font-family: Menlo-Regular;" class=""><span style="font-family: Menlo-Regular;" class="">-      MachineBasicBlock *MBB = DBG->getParent();</span><br style="font-family: Menlo-Regular;" class=""><span style="font-family: Menlo-Regular;" class="">      MachineInstr *NewDV =</span><br style="font-family: Menlo-Regular;" class=""><span style="font-family: Menlo-Regular;" class="">          BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::DBG_VALUE))</span><br style="font-family: Menlo-Regular;" class=""><span style="font-family: Menlo-Regular;" class="">              .addFrameIndex(FI).addImm(Offset).addMetadata(MDPtr);</span></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><span class=""><br class=""><blockquote type="cite" class=""><div class=""><p dir="ltr" class="">> I failed at constructing a reliable testcase for this, see<br class="">
> <a href="http://llvm.org/bugs/show_bug.cgi?id=20523" target="_blank" class="">http://llvm.org/bugs/show_bug.cgi?id=20523</a> for a large testcases.<br class="">
><br class="">
> Modified:<br class="">
>     llvm/trunk/lib/CodeGen/RegAllocFast.cpp<br class="">
><br class="">
> Modified: llvm/trunk/lib/CodeGen/RegAllocFast.cpp<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocFast.cpp?rev=217260&r1=217259&r2=217260&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocFast.cpp?rev=217260&r1=217259&r2=217260&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- llvm/trunk/lib/CodeGen/RegAllocFast.cpp (original)<br class="">
> +++ llvm/trunk/lib/CodeGen/RegAllocFast.cpp Fri Sep  5 12:10:10 2014<br class="">
> @@ -309,10 +309,10 @@ void RAFast::spillVirtReg(MachineBasicBl<br class="">
>          DL = (--EI)->getDebugLoc();<br class="">
>        } else<br class="">
>          DL = MI->getDebugLoc();<br class="">
> -      MachineBasicBlock *MBB = DBG->getParent();<br class="">
>        MachineInstr *NewDV =<br class="">
>            BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::DBG_VALUE))<br class="">
>                .addFrameIndex(FI).addImm(Offset).addMetadata(MDPtr);<br class="">
> +      assert(NewDV->getParent() == MBB && "dangling parent pointer");</p><p dir="ltr" class="">Maybe this assertion (in some form) could be moved into a more central location so this invariant (that BuildMI functions are passed an iterator into the same MBB - but maybe even below the build function, in the insertion itself)</p><div class=""><br class=""></div></div></blockquote><div class=""><br class=""></div></span><div class="">I experimented with the following patch and it seems to lead into a world of pain... Apparently we violate this invariant quite often at the moment.</div></div></div></blockquote><div class=""><br class=""></div><div class="">What kind of violations? Is the parent just null here, perhaps? but even then, seems like something not good.</div></div></div></div></div></blockquote><div><br class=""></div><div>Right, just from poking at random testcases it’s running into the assertion from FunctionLoweringInfo::set() with a similar setup where the iterator points to a different basic block.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class=""><br class=""></div><div class=""><div style="margin:0px;font-family:Menlo" class=""><b class="">diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h</b></div><div style="margin:0px;font-family:Menlo" class=""><b class="">index a08cc2e..edd228a 100644</b></div><div style="margin:0px;font-family:Menlo" class=""><b class="">--- a/include/llvm/CodeGen/MachineBasicBlock.h</b></div><div style="margin:0px;font-family:Menlo" class=""><b class="">+++ b/include/llvm/CodeGen/MachineBasicBlock.h</b></div><div style="margin:0px;font-family:Menlo;color:rgb(52,187,199)" class="">@@ -486,11 +486,13 @@<span style="" class=""> public:</span></div><div style="margin:0px;font-family:Menlo" class="">   /// Insert a range of instructions into the instruction list before I.</div><div style="margin:0px;font-family:Menlo" class="">   template<typename IT></div><div style="margin:0px;font-family:Menlo" class="">   void insert(iterator I, IT S, IT E) {</div><div style="margin:0px;font-family:Menlo;color:rgb(52,189,38)" class="">+    assert(I->getParent() == this && "iterator points outside of basic block");</div><div style="margin:0px;font-family:Menlo" class="">     Insts.insert(I.getInstrIterator(), S, E);</div><div style="margin:0px;font-family:Menlo" class="">   }</div><div style="margin: 0px; font-family: Menlo; min-height: 16px;" class=""> <br class=""></div><div style="margin:0px;font-family:Menlo" class="">   /// Insert MI into the instruction list before I.</div><div style="margin:0px;font-family:Menlo" class="">   iterator insert(iterator I, MachineInstr *MI) {</div><div style="margin:0px;font-family:Menlo;color:rgb(52,189,38)" class="">+    assert(I->getParent() == this && "iterator points outside of basic block");</div><div style="margin:0px;font-family:Menlo" class="">     assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&</div><div style="margin:0px;font-family:Menlo" class="">            "Cannot insert instruction with bundle flags");</div><div style="margin:0px;font-family:Menlo" class="">     return Insts.insert(I.getInstrIterator(), MI);</div><div style="margin:0px;font-family:Menlo;color:rgb(52,187,199)" class="">@@ -498,6 +500,7 @@<span style="" class=""> public:</span></div><div style="margin: 0px; font-family: Menlo; min-height: 16px;" class=""> <br class=""></div><div style="margin:0px;font-family:Menlo" class="">   /// Insert MI into the instruction list after I.</div><div style="margin:0px;font-family:Menlo" class="">   iterator insertAfter(iterator I, MachineInstr *MI) {</div><div style="margin:0px;font-family:Menlo;color:rgb(52,189,38)" class="">+    assert(I->getParent() == this && "iterator points outside of basic block");</div><div style="margin:0px;font-family:Menlo" class="">     assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&</div><div style="margin:0px;font-family:Menlo" class="">            "Cannot insert instruction with bundle flags");</div><div style="margin:0px;font-family:Menlo" class="">     return Insts.insertAfter(I.getInstrIterator(), MI);</div><div style="font-size:10px" class=""><br class=""></div></div><span class=""><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><p dir="ltr" class="">>        (void)NewDV;<br class="">
>        DEBUG(dbgs() << "Inserting debug info due to spill:" << "\n" << *NewDV);<br class="">
>      }<br class="">
><br class="">
><br class="">
> _______________________________________________<br class="">
> llvm-commits mailing list<br class="">
> <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank" class="">llvm-commits@cs.uiuc.edu</a><br class="">
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">
</p>
</div></blockquote></span></div><br class=""></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>