<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="">Hmm.. This fails, too! Apparently the backend is really lax about enforcing sensible parent pointers.<div class=""><br class=""><div class=""><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class=""><b class="">diff --git a/lib/CodeGen/RegAllocFast.cpp b/lib/CodeGen/RegAllocFast.cpp</b></div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class=""><b class="">index 6e7e2c7..15f09f5 100644</b></div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class=""><b class="">--- a/lib/CodeGen/RegAllocFast.cpp</b></div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class=""><b class="">+++ b/lib/CodeGen/RegAllocFast.cpp</b></div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #34bbc7" class="">@@ -278,6 +278,7 @@</span> void RAFast::spillVirtReg(MachineBasicBlock::iterator MI,</div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class="">                           LiveRegMap::iterator LRI) {</div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class="">   LiveReg &LR = *LRI;</div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class="">   assert(PhysRegState[LR.PhysReg] == LRI->VirtReg && "Broken RegState mapping");</div><div style="margin: 0px; font-family: Menlo; color: rgb(52, 189, 38); font-size: 11px;" class="">+  assert(MI->getParent() == MBB && "MI is outside of MBB");</div><p style="margin: 0px; font-family: Menlo; min-height: 16px; font-size: 11px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class="">   if (LR.Dirty) {</div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class="">     // If this physreg is used by the instruction, we want to kill it on the</div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class=""><br class=""></div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""> I wonder if that is the reason why the original code explicitly copied the parent pointer from the original intrinsic?</span></div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="margin: 0px; font-family: Menlo; font-size: 11px;" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">-- adrian</span></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Sep 5, 2014, at 1:13 PM, Adrian Prantl <<a href="mailto:aprantl@apple.com" class="">aprantl@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Sep 5, 2014, at 10:31 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><p dir="ltr" class=""><br class="">
On Sep 5, 2014 10:22 AM, "Adrian Prantl" <<a href="mailto:aprantl@apple.com" 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" 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>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.<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" 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" 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><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 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="webkit-block-placeholder"></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="webkit-block-placeholder"></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><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" class="">llvm-commits@cs.uiuc.edu</a><br class="">
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">
</p>
</div></blockquote></div><br class=""></div>_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br class=""></div></blockquote></div><br class=""></div></div></body></html>