<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>Sorry, but it seems to me that we are working around the problem with the hasExtraRegAllocReq flag and this workaround is introducing new problems that then need to be solved.<br></div>Going back to the original problem that Escha reported, it seems to be that the back end ends up in the following state which arguably is probably not a reasonable state to be in (if register renaming is to be allowed):<br><br></div>- There are constraints added to the virtual registers that restrict which register class the assigned physical register must come from<br></div>- The register allocator respects those constraints and selects a register from the correct class<br></div>- The selected physical register is marked as renamable<br></div>- Calling MachineInstr::getRegClassConstraint() on the machine instruction returns a register class that does not take into account the additional constraints<br><br></div>Ultimately, anything that does register renaming with the back end in that state can potentially break the code since it doesn't know what actual class the register rename is allowed to come from.<br></div><br></div>Wouldn't this mean that a target that can be in this state has at least these two reasonable options:<br></div>1. Set some property that will ensure that the renamable flag is never set on any register - essentially what Geoff is suggesting in the latter part of his last email. I would just make it a property of TargetRegisterInfo (perhaps `virtual bool TargetRegisterInfo::allowRegisterRenaming()`).<br></div>2. We make TargetInstrInfo::getRegClass() virtual and allow the target to override it so that the extra constraints can be taken into account if it wants to allow renaming of registers<br><br></div>Not to suggest that the two solutions are mutually exclusive.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 2, 2018 at 5:57 PM,  <span dir="ltr"><<a href="mailto:gberry@codeaurora.org" target="_blank">gberry@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div link="blue" vlink="purple" lang="EN-US"><div class="m_4139097589071889215WordSection1"><p class="MsoNormal">I think the fix for this the way things are currently setup would be for the code that changes the COPY to the target opcode to clear the renamable bits on the operands.<u></u><u></u></p><p class="MsoNormal">If we add a target global “all opcodes are hasExtraRegAllocReq” setting, we could avoid setting any COPY operands as renamable in the first place.<u></u><u></u></p><span class=""><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">-- <u></u><u></u></p><p class="MsoNormal">Geoff Berry<u></u><u></u></p><p class="MsoNormal">Employee of Qualcomm Datacenter Technologies, Inc.<u></u><u></u></p><p class="MsoNormal"> Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.<u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p></span><div><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><span class=""><b>From:</b> <a href="mailto:fglaser@apple.com" target="_blank">fglaser@apple.com</a> [mailto:<a href="mailto:fglaser@apple.com" target="_blank">fglaser@apple.com</a>] <b>On Behalf Of </b><a href="mailto:escha@apple.com" target="_blank">escha@apple.com</a><br></span><b>Sent:</b> Friday, February 2, 2018 5:30 PM<br><b>To:</b> <a href="mailto:escha@apple.com" target="_blank">escha@apple.com</a><br><b>Cc:</b> <a href="mailto:gberry@codeaurora.org" target="_blank">gberry@codeaurora.org</a>; <a href="mailto:junbuml@codeaurora.org" target="_blank">junbuml@codeaurora.org</a>; <a href="mailto:marina.yatsina@intel.com" target="_blank">marina.yatsina@intel.com</a>; <a href="mailto:kannan.narayanan@amd.com" target="_blank">kannan.narayanan@amd.com</a>; <a href="mailto:nhaehnle@gmail.com" target="_blank">nhaehnle@gmail.com</a>; <a href="mailto:wei.ding2@amd.com" target="_blank">wei.ding2@amd.com</a>; Matthias Braun <<a href="mailto:matze@braunis.de" target="_blank">matze@braunis.de</a>>; Nemanja Ivanovic <<a href="mailto:nemanja.i.ibm@gmail.com" target="_blank">nemanja.i.ibm@gmail.com</a>>; llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>>; <a href="mailto:reviews%2BD41835%2Bpublic%2B9c1dec7fb6e75ce0@reviews.llvm.org" target="_blank">reviews+D41835+public+<wbr>9c1dec7fb6e75ce0@reviews.llvm.<wbr>org</a>; <a href="mailto:tpr.llvm@botech.co.uk" target="_blank">tpr.llvm@botech.co.uk</a>; <a href="mailto:javed.absar@arm.com" target="_blank">javed.absar@arm.com</a></p><div><div class="h5"><br><b>Subject:</b> Re: [PATCH] D41835: [MachineCopyPropagation] Extend pass to do COPY source forwarding<u></u><u></u></div></div><p></p></div></div><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">update: it gets worse. i can’t get the tests to pass because a lot of tests fail with this when the verifier is on:<u></u><u></u></p><div><pre style="box-sizing:border-box;white-space:pre-wrap;word-wrap:break-word;font-variant-ligatures:normal"><span style="color:#333333"><u></u> <u></u></span></pre><pre><span style="color:#333333">*** Bad machine code: Illegal isRenamable setting for opcode with extra regalloc requirements ***<u></u><u></u></span></pre><div><p class="MsoNormal"><u></u> <u></u></p></div></div><div><p class="MsoNormal">This occurs on our copy instructions after we expand them into actual machine opcodes, because the machine opcode for the copy instruction isn’t Renamable (none of our instructions are).<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">—escha<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal"><br><br><u></u><u></u></p><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt"><div><p class="MsoNormal">On Feb 2, 2018, at 1:37 PM, via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal">this is probably a reasonable solution. mostly, at this point, i’m worried about the fact that upstream now apparently has a different understanding of register classes than we do (in terms of what is “safe”), which could lead to other future issues for us.<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">—escha<u></u><u></u></p><div><p class="MsoNormal"><br><br><u></u><u></u></p><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt"><div><p class="MsoNormal">On Feb 2, 2018, at 1:36 PM, <a href="mailto:gberry@codeaurora.org" target="_blank">gberry@codeaurora.org</a> wrote:<u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal">Ah, okay.  So I assume you’re okay with disabling the post-RA run of this pass for this particular target to fix this particular issue?<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><div><p class="MsoNormal">--<span class="m_4139097589071889215apple-converted-space"> </span><u></u><u></u></p></div><div><p class="MsoNormal">Geoff Berry<u></u><u></u></p></div><div><p class="MsoNormal">Employee of Qualcomm Datacenter Technologies, Inc.<u></u><u></u></p></div><div><p class="MsoNormal">Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.<u></u><u></u></p></div></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><div><p class="MsoNormal"><b>From:</b><span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:fglaser@apple.com" target="_blank">fglaser@apple.com</a> [<a href="mailto:fglaser@apple.com" target="_blank">mailto:fglaser@apple.com</a>]<span class="m_4139097589071889215apple-converted-space"> </span><b>On Behalf Of<span class="m_4139097589071889215apple-converted-space"> </span></b><a href="mailto:escha@apple.com" target="_blank">escha@apple.com</a><br><b>Sent:</b><span class="m_4139097589071889215apple-converted-space"> </span>Friday, February 2, 2018 4:32 PM<br><b>To:</b><span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:gberry@codeaurora.org" target="_blank">gberry@codeaurora.org</a><br><b>Cc:</b><span class="m_4139097589071889215apple-converted-space"> </span>Quentin Colombet <<a href="mailto:qcolombet@apple.com" target="_blank">qcolombet@apple.com</a>>; <a href="mailto:reviews+D41835+public+9c1dec7fb6e75ce0@reviews.llvm.org" target="_blank">reviews+D41835+public+<wbr>9c1dec7fb6e75ce0@reviews.llvm.<wbr>org</a>; Geoff Berry via Phabricator <<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>>; <a href="mailto:javed.absar@arm.com" target="_blank">javed.absar@arm.com</a>; Matthias Braun <<a href="mailto:matze@braunis.de" target="_blank">matze@braunis.de</a>>; Jonas Paulsson <<a href="mailto:paulsson@linux.vnet.ibm.com" target="_blank">paulsson@linux.vnet.ibm.com</a>>; <a href="mailto:tstellar@redhat.com" target="_blank">tstellar@redhat.com</a>; Matt Arsenault <<a href="mailto:Matthew.Arsenault@amd.com" target="_blank">Matthew.Arsenault@amd.com</a>>; <a href="mailto:junbuml@codeaurora.org" target="_blank">junbuml@codeaurora.org</a>; <a href="mailto:marina.yatsina@intel.com" target="_blank">marina.yatsina@intel.com</a>; <a href="mailto:wei.ding2@amd.com" target="_blank">wei.ding2@amd.com</a>; <a href="mailto:kannan.narayanan@amd.com" target="_blank">kannan.narayanan@amd.com</a>; <a href="mailto:nhaehnle@gmail.com" target="_blank">nhaehnle@gmail.com</a>; Nemanja Ivanovic <<a href="mailto:nemanja.i.ibm@gmail.com" target="_blank">nemanja.i.ibm@gmail.com</a>>; llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>>; <a href="mailto:tpr.llvm@botech.co.uk" target="_blank">tpr.llvm@botech.co.uk</a><br><b>Subject:</b><span class="m_4139097589071889215apple-converted-space"> </span>Re: [PATCH] D41835: [MachineCopyPropagation] Extend pass to do COPY source forwarding<u></u><u></u></p></div></div></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal">looking at it again, it’s making more sense: your patch enabled MachineCopyPropagation in the RA pipeline. the pass might have *already* been broken, but it wasn’t running for us, and now it is, so it broke things in that way too.<u></u><u></u></p></div><div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><div><p class="MsoNormal">—escha<u></u><u></u></p></div><div><div><p class="MsoNormal"><br><br><br><u></u><u></u></p></div><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt"><div><div><p class="MsoNormal">On Feb 2, 2018, at 1:26 PM,<span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:gberry@codeaurora.org" target="_blank"><span style="color:purple">gberry@codeaurora.org</span></a><span class="m_4139097589071889215apple-converted-space"> </span>wrot<wbr>e:<u></u><u></u></p></div></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><div><div><p class="MsoNormal">escha,<u></u><u></u></p></div></div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><div><p class="MsoNormal">I’m confused by your comment about bundles.  It was known that this patch doesn’t handle forwarding into bundles, but it sounds like to me you are seeing problems with the dead COPY removal part of this pass, which was not intentionally changed by this patch (other than adding a DEBUG statement when it happens).<u></u><u></u></p></div></div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><div><div><p class="MsoNormal">--<span class="m_4139097589071889215apple-converted-space"> </span><u></u><u></u></p></div></div><div><div><p class="MsoNormal">Geoff Berry<u></u><u></u></p></div></div><div><div><p class="MsoNormal">Employee of Qualcomm Datacenter Technologies, Inc.<u></u><u></u></p></div></div><div><div><p class="MsoNormal">Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.<u></u><u></u></p></div></div></div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><div><div><p class="MsoNormal"><b>From:</b><span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:fglaser@apple.com" target="_blank"><span style="color:purple">fglaser@apple.com</span></a><span class="m_4139097589071889215apple-converted-space"> </span>[<a href="mailto:fglaser@apple.com" target="_blank"><span style="color:purple">mailt<wbr>o:fglaser@apple.com</span></a>]<span class="m_4139097589071889215apple-converted-space"> </span><b>On Behalf Of<span class="m_4139097589071889215apple-converted-space"> </span></b><a href="mailto:escha@apple.com" target="_blank"><span style="color:purple">escha@apple.com</span></a><br><b>Sent:</b><span class="m_4139097589071889215apple-converted-space"> </span>Friday, February 2, 2018 4:10 PM<br><b>To:</b><span class="m_4139097589071889215apple-converted-space"> </span>Quentin Colombet <<a href="mailto:qcolombet@apple.com" target="_blank"><span style="color:purple">qcolombet@apple.com</span></a>><br><b>Cc:</b><span class="m_4139097589071889215apple-converted-space"> </span>Geoff Berry <<a href="mailto:gberry@codeaurora.org" target="_blank"><span style="color:purple">gberry@codeaurora.org</span></a>>;<span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:reviews+D41835+public+9c1dec7fb6e75ce0@reviews.llvm.org" target="_blank"><span style="color:purple">revie<wbr>ws+D41835+public+<wbr>9c1dec7fb6e75ce0@reviews.llvm.<wbr>org</span></a>; Geoff Berry via Phabricator <<a href="mailto:reviews@reviews.llvm.org" target="_blank"><span style="color:purple">reviews@reviews.llvm.org</span></a>>;<span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:javed.absar@arm.com" target="_blank"><span style="color:purple">ja<wbr>ved.absar@arm.com</span></a>; Matthias Braun <<a href="mailto:matze@braunis.de" target="_blank"><span style="color:purple">matze@braunis.de</span></a>>; Jonas Paulsson <<a href="mailto:paulsson@linux.vnet.ibm.com" target="_blank"><span style="color:purple">paulsson@linux.vnet.ibm.com</span></a>>;<span class="m_4139097589071889215apple-converted-space"><wbr> </span><a href="mailto:tstellar@redhat.com" target="_blank"><span style="color:purple">tstellar@redhat.com</span></a>; Matt Arsenault <<a href="mailto:Matthew.Arsenault@amd.com" target="_blank"><span style="color:purple">Matthew.Arsenault@amd.com</span></a>>;<span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:junbuml@codeaurora.org" target="_blank"><span style="color:purple">j<wbr>unbuml@codeaurora.org</span></a>;<span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:marina.yatsina@intel.com" target="_blank"><span style="color:purple">marina.<wbr>yatsina@intel.com</span></a>;<span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:wei.ding2@amd.com" target="_blank"><span style="color:purple">wei.ding2@<wbr>amd.com</span></a>;<span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:kannan.narayanan@amd.com" target="_blank"><span style="color:purple">kannan.narayanan@amd.<wbr>com</span></a>;<span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:nhaehnle@gmail.com" target="_blank"><span style="color:purple">nhaehnle@gmail.com</span></a>; Nemanja Ivanovic <<a href="mailto:nemanja.i.ibm@gmail.com" target="_blank"><span style="color:purple">nemanja.i.ibm@gmail.com</span></a>>; llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank"><span style="color:purple">llvm-commits@lists.llvm.org</span></a>>;<span class="m_4139097589071889215apple-converted-space"><wbr> </span><a href="mailto:tpr.llvm@botech.co.uk" target="_blank"><span style="color:purple">tpr.llvm@botech.co.uk</span></a><br><b>Subject:</b><span class="m_4139097589071889215apple-converted-space"> </span>Re: [PATCH] D41835: [MachineCopyPropagation] Extend pass to do COPY source forwarding<u></u><u></u></p></div></div></div></div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><div><div><p class="MsoNormal"><br><br><br><br><u></u><u></u></p></div></div><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt"><div><div><div><p class="MsoNormal">On Feb 2, 2018, at 12:55 PM, Quentin Colombet <<a href="mailto:qcolombet@apple.com" target="_blank"><span style="color:purple">qcolombet@apple.com</span></a>> wrote:<u></u><u></u></p></div></div></div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><div><div><p class="MsoNormal"><br><br><br><br><u></u><u></u></p></div></div><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt"><div><div><div><p class="MsoNormal">On Feb 2, 2018, at 12:21 PM,<span class="m_4139097589071889215apple-converted-space"> </span><a href="mailto:escha@apple.com" target="_blank"><span style="color:purple">escha@apple.com</span></a><span class="m_4139097589071889215apple-converted-space"> </span>wrote:<u></u><u></u></p></div></div></div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><div><div><div><p class="MsoNormal">I mean, in that case we are likely to have to mark every single opcode (all 12,000 or so) with this requirement. At that point we might as well just opt out of the pass, I think? At least, it feels like a gross hack that papers over the fact that LLVM has changed how register classes work such that our entire approach is no longer valid.<u></u><u></u></p></div></div><div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal">Also, it seems very weird to make this constraint-violating behavior *opt-out*. Maybe it should be opt-in, i.e. put doesNotHaveExtraSrcRegAllocReq on all instructions it’s okay for?<u></u><u></u></p></div></div></div></div></div></blockquote><div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal">That sounds like a better approach to me.<u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal">After talking with escha, I agree that TableGen is not necessarily expressive enough to model all the constraints that need to be met and I would err on the safe side of being opt-in instead of opt-out.<u></u><u></u></p></div></div></div></div></div></div></blockquote><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal">this is actually worse than i initially realized. one of our targets is VLIW and is completely broken by this patch, *even if we opt out as described*, because it doesn’t iterate over the operands of a bundle. so for example:<u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal">r3 = COPY foo<u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal">BUNDLE_TYPE_FOO<u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal"><thing that uses r3><u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal">END<u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal">it believes that r3 is dead because it doesn’t iterate over the bundle operands, so it never sees the use of r3.<u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div></div><div><div><div><p class="MsoNormal">—escha<u></u><u></u></p></div></div></div></div></blockquote></div></div></div></div></blockquote></div><p class="MsoNormal"><u></u> <u></u></p></div></div><p class="MsoNormal">______________________________<wbr>_________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><u></u><u></u></p></div></blockquote></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div></blockquote></div><br></div>