<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thanks for the details Matt, now I think I can suggest an alternative or provide more reasonable explanation why what you’re doing is right!<div class=""><br class=""></div><div class="">Assuming we stick to your current approach, it makes sense to mark the operation legal for vgpr because from RBS point of view the boundaries of the expansion of the instruction are indeed vgpr.<br class=""><div class=""><div class=""><br class=""></div><div class="">Now, if we want to leverage the infrastructure provided by RBS for this case, a possible alternative would require to unroll the loop (or use a pseudo that would fake the loop unrolling).</div><div class="">Here is what it would look like:</div><div class="">Essentially we would replace:</div><div class="">```</div><div class=""><font face="Menlo" style="font-size: 11px;" class="">= use <NxsM> vgpr</font></div><div class="">```</div><div class="">into</div><div class="">```</div><div class=""><font face="Menlo" style="font-size: 11px;" class="">sgpr1, …, sgprN = extract_reg vgpr</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">= use sM sgpr1</font></div><div class=""><div class=""><font face="Menlo" style="font-size: 11px;" class="">…</font></div><div><font face="Menlo" style="font-size: 11px;" class="">= use sM sgprN</font></div><div>```</div><div>In terms of mapping, you would describe vgpr as being broken down in N element of sgpr. The applyMapping would insert the `<font face="Menlo" style="font-size: 11px;" class="">extract_reg</font>` for repairing and expand the vector use into the scalar uses (or one pseudo with N sgpr as input).</div><div><br class=""></div><div>Honestly, I don’t know how much benefit you would get to expose these details to RBS today.</div><div>The advantages I see moving forward are:</div><div>- At some point I wanted to teach RBS to materialize the repairing code next to the definition (as opposed to the use like we do right now) so that we can reuse that repairing for something else (what you’ve pointed out in your previous reply)</div><div>- In the future RBS is supposed to be smart enough to decide that something needs to be scalarized because its uses are cheaper that way. I.e., in your case, the definition of vgpr could be scalarized from the start and we wouldn’t have to insert this repairing code (in other words, RBS would have chosen to scalarize the def of the the vgpr into sgpr instead of repairing the use of the vgpr into sgpr).</div><div><br class=""></div><div>Therefore, if we choose not to expose these details to RBS, we shut the door to potential improvements on how the repairing points are inserted/shared and how the cost model is able to deal with choosing the best instructions based on its uses.</div><div><br class=""></div><div>Obviously, I haven’t spent a lot of time thinking about for your case, hence it could be completely bogus!</div><div><br class=""></div><div>Cheers,</div><div>-Quentin</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On Feb 26, 2019, at 4:58 PM, Matt Arsenault <<a href="mailto:arsenm2@gmail.com" class="">arsenm2@gmail.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; line-break: after-white-space;" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Feb 26, 2019, at 7:46 PM, Quentin Colombet <<a href="mailto:qcolombet@apple.com" class="">qcolombet@apple.com</a>> wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""> The only  use I would have for the copy is as as a means of passing which registers were already created for the new mapping, after which point I would need to delete it.</div></div></blockquote><div class=""><br class=""></div><div class="">Could you describe in pseudo code what the expansion of vgpr into sgpr looks like?</div><div class="">e.g., = use vgpr</div><div class="">And you only support = use sgpr </div><div class=""><br class=""></div></div></div></div></blockquote><br class=""></div><div class="">It’s serializing the vector operation. There’s an additional optimization to reduce the number of loop iterations when multiple work items/lanes/threads have the same value in them which happens in practice, but essentially it does:</div><div class=""><br class=""></div><div class="">Save Execution Mask</div><div class="">For (Lane : Wavefront/Warp) {</div><div class="">  Enable Lane, Disable all other lanes</div><div class="">  SGPR = read SGPR value for current lane from VGPR</div><div class="">  VGPRResult[Lane] = use_op SGPR</div><div class="">}</div>Restore Execution Mask<div class=""><br class=""></div><div class="">Eventually it might be nice to have optimizations to only emit one of these loops when multiple consecutive instructions need the same register handled (which I suspect will happen frequently with image samplers), but I haven’t really thought about what that should look like yet.<br class=""><div class=""><br class=""></div><div class="">-Matt</div></div></div></div></blockquote></div><br class=""></div></div></div></body></html>