<div dir="ltr"><div class="gmail_quote"><div dir="ltr">I'm building a backend based on LLVM 3.6 (because that was the head when I started) for a target architecture with instructions for copying between registers of different classes and also for copying literal values to registers, e.g. roughly:<div><br></div><div>TAX X A  ; copy from A to X</div><div>TXA A X  ; copy from X to A</div><div>TIX 42 X  ; set X to 42</div><div><div>TIA 42 A  ; set A to 42</div></div><div><br></div><div>with the instructions .TD contents roughly (omitting instruction formats, etc)</div><div><br></div><div>def TAX { ins aRegs:$A, outs xRegs:$X, [(set xRegs:$X, aRegs:$A)]</div><div>def TXA { ins xRegs:$X, outs aRegs:$A, [(set aRegs:$A, xRegs:$X)]</div><div>def TIX { ins imm:$val, outs xRegs:$X, [(set xRegs:$X, (imm:$val))]<br></div><div><div>def TIA { ins imm:$val, outs aRegs:$A, [(set aRegs:$A, (imm:$val))]<br></div></div><div><br></div><div>then when doing instruction selection for a CopyToReg(X, val) node (produced by an IR "ret i8"; calling convention has result in X0 register):</div><div><br></div><div>(a) with the immediate instructions TIX+TIA defined first it works, though sub-optimally:</div><div>   </div><div><div>        %vreg0<def> = TIX 42; aRegs:%vreg0</div><div>        %X0<def> = COPY %vreg0; aRegs:%vreg0</div></div><div><br></div><div>(b) but when TAX+TAX are defined first it selects this circular pair:</div><div><br></div><div>        %vreg1<def> = COPY %vreg0; xRegs:%vreg1 aRegs:%vreg0
<br>        %vreg0<def> = TAX %vreg1; aRegs:%vreg0 xRegs:%vreg1 <br></div><div><br></div><div>and subsequently aborts when determining liveness ("Use not jointly dominated 
by defs").</div><div><br></div><div>Very naively I'm surprised that the order of the rule definitions matters, i.e. that it chooses the inter-register copy at all rather than finding the better-fitting literal copy. Adding cost hints such as isAsCheapAsAMove didn't change this behaviour.</div><div><br></div><div>Is this the expected behaviour, or is defining TIX first just a crude workaround for some deeper problem with my code?</div><div><br></div><div>Thanks for whatever light you can shed...</div></div>
</div><br><div>/Tyro</div></div>