<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=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Feb 21, 2019, at 12:18 AM, Quentin Colombet via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</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="">Hi Matt,<div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Feb 20, 2019, at 4:49 PM, Arsenault, Matthew via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; 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;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">Hi,<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">Some operations on AMDGPU require operands which must be in a register bank that is impossible to copy from another. The operation needs to be rewritten in a complex way to avoid the illegal copy.<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">Currently if I correctly report the required register banks in the operand mapping, RegBankSelect happily inserts the illegal copies, somehow concluding they are cheap (I would at least hope there’s an assert or something).</span></div></div></div></blockquote><div class=""><br class=""></div><div class="">I would have hoped that we end up with a huge cost.</div><div class="">The assumption is that you can copy to/from any pair of register bank, then the idea is that the copy should be lowered in something that makes sense (e.g., a pair of store/load) by the target.</div><div class="">I am guessing that we could directly ask the target what pseudo-copy should be inserted instead of always adding plain copy.</div><div class=""><br class=""></div><div class="">Would that work for you?</div></div></div></div></div></blockquote><div><br class=""></div>You can’t legitimately copy from vector to scalar. It conceptually doesn’t work, and going through memory doesn’t help. The use instruction needs to be rewritten to (in the worst case) scalarize the operation for every workitem. A pseudocopy would still be some illegal operation which cannot exist which would need to be guaranteed to be removed, so I don’t think this would be any cleaner than allowing the illegal copies.<br class=""><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="WordSection1" style="page: WordSection1; 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;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""> So far I’ve worked around this by lying and reporting all of the invalid source register banks as legal. </span><span style="font-size: 11pt;" class="">applyMapping then checks these registers and creates the new vregs and rewrites as necessary. Is this the way this is intended to work?</span></div></div></div></blockquote><div class=""><br class=""></div><div class="">I am not sure I understand the work around.</div><div class="">Let me try to illustrate this with an example.</div><div class="">Let say we have:</div><div class="">= inst a(bank1)</div><div class="">And inst only accepts bank2.</div><div class="">Are you saying that you lie by saying that bank1 is legal in that case?</div><div class="">If so, why applyMapping would do any rewriting since this is legal.</div></div></div></div></div></blockquote><div><br class=""></div><div>Yes. It’s what happens here: <a href="https://reviews.llvm.org/D58511" class="">https://reviews.llvm.org/D58511</a></div><div><br class=""></div><div>For extract_vector_elt, the indirect register index type must be an SGPR. I’ve implemented the mapping as just copying the original source bank and allowing applyMapping to deal with it. There might be cases that aren’t correctly being rewritten, but I haven’t finished handling every case to run into them yet.</div><div><br class=""></div><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="WordSection1" style="page: WordSection1; 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;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">This sort of makes sense, since it is legal in the sense that applyMapping can deal with it. The cases that need to be rewritten can then have a very high, but not impossible cost in the case of getInstrAlternativeMappings.</span></div></div></div></blockquote><blockquote type="cite" class=""><div class="WordSection1" style="page: WordSection1; 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;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class="">Lying about the actually legal banks seems counterintuitive to me.</span></div></div></blockquote><div class=""><br class=""></div><div class="">Agree, that’s not the way it’s supposed to work.</div><br class=""><blockquote type="cite" class=""><div class="WordSection1" style="page: WordSection1; 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;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 11pt;" class=""> Should there be something like a new RepairingPlacement type for this to just create the vregs without inserting the copy?</span></div></div></blockquote><div class=""><br class=""></div><div class="">See my previous comment on what the copies are supposed to mean. I guess we could imagine a new kind of repairing placement but I am not sure what it would bring us, in the sense of lowering the (pseudo) copy differently should already do what we want.</div><div class=""><br class=""></div></div></div></div></blockquote><br class=""></div><div>It would avoid producing a totally illegal operation that something would need to be responsible for ensuring is deleted</div><div><br class=""></div><div>-Matt</div></body></html>