<br><br>2016年12月21日星期三,Matt Arsenault <<a href="mailto:arsenm2@gmail.com">arsenm2@gmail.com</a>> 写道:<br>><br>> On Dec 21, 2016, at 10:26, Ruiling Song <<a href="mailto:ruiling.song83@gmail.com">ruiling.song83@gmail.com</a>> wrote:<br>><br>><br>> 2016-12-20 22:14 GMT+08:00 Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>>:<br>>><br>>> On Tue, Dec 20, 2016 at 11:00:09AM +0800, Ruiling Song wrote:<br>>> > Hi,<br>>> ><br>>> > I am working on a new LLVM target for Intel GPU, which also has same kind<br>>> > of scalar/vector register classes used in AMDGPU target. Like for a i32<br>>> > virtual register, it will be held in scalar register if its value is<br>>> > uniform across a wavefront/warp, otherwise it will be in a vector register.<br>>> > Does AMDGPU already done this? I read the code, but I didn't figure out how<br>>> > to do this. Anybody has idea on this?<br>>> ><br>>><br>>> In the AMDGPU backend we select everything we can to scalar<br>>> instructions, and then after instruction selection, we move<br>>> non-uniform values to the vector ALU.  This is done by<br>>> the SIFixSGPRCopiesPass, which relies heavily on<br>>> SIInstrInfo::moveToVALU().<br>><br>> Hi Tom,<br>><br>> I take a look at the code, it looks like a good idea. It really helps me a lot. Thanks Tom! I have a question for the code, why it only pass copy-like instructions as TopInst to moveToALU()? Is there any special reason to do like this? I thought that iterating through all the MIs and fix regClass if needed would be ok. Am I thinking it too simple?<br>>  <br>> - Ruiling<br>>><br>>> -Tom<br>>><br>>> > - Ruiling<br>><br>><br>><br>><br>> --<br>> - Ruiling<br>><br>> The instruction selector will insert these copies to satisfy the register operand constraints, so by finding all users (and users of users) of the illegal copies you find the same thing. <br>Only checking copy-like MIs and their further user sounds more reasonable. if iterating through all MIs and checking all the MIs' the Src&Dst register class to find out instructions that need to fix, which is what I previously thought, would just waste some compile time.<br><br>The instruction set is different, so we’re really replacing the instructions and not exactly just changing the register classes.<br>> I think this process logically makes sense, moving things to vector as forced. However I’m uncertain if this is the best approach. I’ve debated going the other direction and selecting everything to vector instruction, and having an optimization pass move parts to scalars. <br>I don't know what makes you thinking about the change. Is "the other direction" more safe because it only optimize known pattern? Or do you ever meet some situation that you cannot handle it smart using current solution? I will do some try in my target, may be we can have some further discussion after I know more about LLVM on this.<br>- Ruiling<br>This is what the AMD compiler does. There are different trade offs, but one advantage is you immediately have something resembling a legal program to begin with.<br>> -Matt<br><br>-- <br><div dir="ltr">- Ruiling</div><br>