<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Apr 22, 2014, at 7:24 AM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Mon, Apr 21, 2014 at 09:38:02AM -0700, Quentin Colombet wrote:<br><blockquote type="cite"><br>On Apr 21, 2014, at 6:49 AM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:<br><br><blockquote type="cite">On Fri, Apr 18, 2014 at 03:43:55PM -0700, Quentin Colombet wrote:<br><blockquote type="cite">Hi Tom,<br><br>I’ve looked at your patch and it looks like a workaround to a more general issue.<br><br>I’ve applied your second patch and looked at what happen with the rematerialization in that case.<br><br>Unless I am not looking at the right fragment, the copy you are trying to avoid to rematerialize is:<br>%vreg169<def> = COPY %vreg91:sub0_sub1; SReg_64:%vreg169 SReg_128:%vreg91<br><br>And the related rematerializable definition is:<br>%vreg91:sub0_sub1<def,read-undef> = S_MOV_B64 0; SReg_128:%vreg91<br><br>Thus, one would expect to rematerialize this into:<br>%vreg169:sub0_sub1<def,read-undef> = S_MOV_B64 0; SReg_128:%vreg169<br><br>Which the current code should correctly handle.<br><br>However, in your case, the instruction that have been picked up for rematerialization is:<br>%vreg91:sub3<def> = S_MOV_B32 61440; SReg_128:%vreg91<br><br>Which is the same vreg91, but not the right subregister. So looks like there is a liveness or liveness-update bug with the subregisters.<br><br></blockquote><br>Are you sure LLVM ToT does sub-register liveness tracking?<br></blockquote>No, I am not sure, but the root cause of the bug is this liveness tracking.<br>So I’d suggest, go for your workaround (with the fixed typo) and file a PR.<br><br></blockquote><br>I can commit this fix, but I've found another issue that needs to be resolved<br>first.<br><br>There is an assertion at RegisterCoalescer.cpp:823, which prevents rematerialzed<br>instructions from having implicit uses.  Why is this necessary?</div></blockquote><div>The rematerialization mechanism assumes that each argument is a constant of some sort.</div><div>If that is not the case, e.g., with an implicit use, you cannot guarantee that rematerializing is correct.</div><div><br></div><div>E.g.,</div><div><br></div><div>v1 = remat <imp-use R1></div><div>R1 = something</div><div>v2 = copy v1</div><div>=></div><div><div>R1 = something</div><div>v2 = remat <imp-use R1> ; # the value in R1 is not the same than the value used to rematerialize v1. Therefore this may not be correct.</div><div><br></div></div><br><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">  Can this be removed?<br></div></blockquote><div>No, it shouldn’t be removed.</div><div>If the implicit use does not change the rematerialized value, maybe you shouldn’t have an implicit use on that instruction in the first place.</div><div><br></div><div>What about the original issue, the liveness problem, did you sort it out?</div><div><br></div><div>Thanks,</div><div>-Quentin</div><div><br></div><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I have attached a patch which gets rid of it, but I'm not sure it is correct.<br><br>-Tom<br><br><blockquote type="cite">Thanks,<br>-Quentin<br><br><blockquote type="cite">I thought liveness was<br>tracked by super-register only.<br><br>-Tom<br><br><blockquote type="cite">Could you please track this down to make sure we understand the problem?<br><br>Now, in the mean time, we may want to provide a workaround (and fix a PR to remember we added a workaround).<br>Your workaround is appropriate with the following fix:<br>+  // The COPY src reg and the DefMI dst reg must have the same subreg index<br>+  if (CopyMI->getOperand(1).getSubReg() != DefMI->getOperand(0).getSubReg())<br>+    return false;<br><br>I.e., instead of checking the sub register of CopyDstOperand, you have to check the sub register of copy *src* operand (like you said in your comment), i.e., 1 instead of 0.<br><br>Thanks,<br>-Quentin<br><br>On Apr 16, 2014, at 3:13 PM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:<br><br><blockquote type="cite">Hi,<br><br>This patch fixes a bug in the register coalescer where it was incorrectly<br>rematerializing instructions that define sub-regs.<br><br>I've also attached the R600 patch which uncovers this bug.<br><br>Please Review.<br><br>-Tom<br><0001-RegisterCoalescer-Fix-bug-when-rematerializing-insts.patch><0002-R600-SI-Improve-chances-of-rematerializing-during-re.patch>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></blockquote></blockquote></blockquote><br></blockquote><span><0001-XXX-Fix-assertion-in-coalescer.patch></span></div></blockquote></div><br></body></html>