<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Sep 5, 2014 at 1:13 PM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Sep 5, 2014, at 10:31 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><p dir="ltr"><br>
On Sep 5, 2014 10:22 AM, "Adrian Prantl" <<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>> wrote:<br>
><br>
> Author: adrian<br>
> Date: Fri Sep  5 12:10:10 2014<br>
> New Revision: 217260<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=217260&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=217260&view=rev</a><br>
> Log:<br>
> Set the parent pointer of cloned DBG_VALUE instructions correctly.<br>
> Fixes PR20523.<br>
><br>
> When spilling variables onto the stack, spillVirtReg() is setting the<br>
> parent pointer of the cloned DBG_VALUE intrinsic for the stack location<br>
> to the parent pointer of the original intrinsic. MachineInstr parent<br>
> pointers should however always point to the parent basic block.<br>
><br>
> MBB is shadowing the MBB member variable. The instruction still ends up<br>
> being inserted into the right basic block, because it's inserted after MI<br>
> which serves as the iterator.</p><p dir="ltr">Perhaps we should assert that the iterator within the basic block?</p><div><br></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><br></div><div>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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class=""><br><blockquote type="cite"><div><p dir="ltr">> I failed at constructing a reliable testcase for this, see<br>
> <a href="http://llvm.org/bugs/show_bug.cgi?id=20523" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=20523</a> for a large testcases.<br>
><br>
> Modified:<br>
>     llvm/trunk/lib/CodeGen/RegAllocFast.cpp<br>
><br>
> Modified: llvm/trunk/lib/CodeGen/RegAllocFast.cpp<br>
> 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">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocFast.cpp?rev=217260&r1=217259&r2=217260&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/CodeGen/RegAllocFast.cpp (original)<br>
> +++ llvm/trunk/lib/CodeGen/RegAllocFast.cpp Fri Sep  5 12:10:10 2014<br>
> @@ -309,10 +309,10 @@ void RAFast::spillVirtReg(MachineBasicBl<br>
>          DL = (--EI)->getDebugLoc();<br>
>        } else<br>
>          DL = MI->getDebugLoc();<br>
> -      MachineBasicBlock *MBB = DBG->getParent();<br>
>        MachineInstr *NewDV =<br>
>            BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::DBG_VALUE))<br>
>                .addFrameIndex(FI).addImm(Offset).addMetadata(MDPtr);<br>
> +      assert(NewDV->getParent() == MBB && "dangling parent pointer");</p><p dir="ltr">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><br></div></div></blockquote><div><br></div></span><div>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><br></div><div>What kind of violations? Is the parent just null here, perhaps? but even then, seems like something not good.</div><div> </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"><div><div><br></div><div><div style="margin:0px;font-family:Menlo"><b>diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h</b></div><div style="margin:0px;font-family:Menlo"><b>index a08cc2e..edd228a 100644</b></div><div style="margin:0px;font-family:Menlo"><b>--- a/include/llvm/CodeGen/MachineBasicBlock.h</b></div><div style="margin:0px;font-family:Menlo"><b>+++ b/include/llvm/CodeGen/MachineBasicBlock.h</b></div><div style="margin:0px;font-family:Menlo;color:rgb(52,187,199)">@@ -486,11 +486,13 @@<span style="color:#000000"> public:</span></div><div style="margin:0px;font-family:Menlo">   /// Insert a range of instructions into the instruction list before I.</div><div style="margin:0px;font-family:Menlo">   template<typename IT></div><div style="margin:0px;font-family:Menlo">   void insert(iterator I, IT S, IT E) {</div><div style="margin:0px;font-family:Menlo;color:rgb(52,189,38)">+    assert(I->getParent() == this && "iterator points outside of basic block");</div><div style="margin:0px;font-family:Menlo">     Insts.insert(I.getInstrIterator(), S, E);</div><div style="margin:0px;font-family:Menlo">   }</div><p style="margin:0px;font-family:Menlo;min-height:16px"> <br></p><div style="margin:0px;font-family:Menlo">   /// Insert MI into the instruction list before I.</div><div style="margin:0px;font-family:Menlo">   iterator insert(iterator I, MachineInstr *MI) {</div><div style="margin:0px;font-family:Menlo;color:rgb(52,189,38)">+    assert(I->getParent() == this && "iterator points outside of basic block");</div><div style="margin:0px;font-family:Menlo">     assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&</div><div style="margin:0px;font-family:Menlo">            "Cannot insert instruction with bundle flags");</div><div style="margin:0px;font-family:Menlo">     return Insts.insert(I.getInstrIterator(), MI);</div><div style="margin:0px;font-family:Menlo;color:rgb(52,187,199)">@@ -498,6 +500,7 @@<span style="color:#000000"> public:</span></div><p style="margin:0px;font-family:Menlo;min-height:16px"> <br></p><div style="margin:0px;font-family:Menlo">   /// Insert MI into the instruction list after I.</div><div style="margin:0px;font-family:Menlo">   iterator insertAfter(iterator I, MachineInstr *MI) {</div><div style="margin:0px;font-family:Menlo;color:rgb(52,189,38)">+    assert(I->getParent() == this && "iterator points outside of basic block");</div><div style="margin:0px;font-family:Menlo">     assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&</div><div style="margin:0px;font-family:Menlo">            "Cannot insert instruction with bundle flags");</div><div style="margin:0px;font-family:Menlo">     return Insts.insertAfter(I.getInstrIterator(), MI);</div><div style="font-size:10px"><br></div></div><span class=""><div><br></div><br><blockquote type="cite"><div><p dir="ltr">>        (void)NewDV;<br>
>        DEBUG(dbgs() << "Inserting debug info due to spill:" << "\n" << *NewDV);<br>
>      }<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" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</p>
</div></blockquote></span></div><br></div></blockquote></div><br></div></div>