<div dir="ltr"><div>Hi all,</div><div>I'm trying to figure out why llvm(llvm 3.1, can't easilly try it with other version) inserts an unnecessary load for one register.</div><div> </div><div>The following is the code before instruction selection:</div>
<div>----------------------------------------------------------------------------</div><div> %call = tail call i32 @_Z7zahlIntv()<br> %0 = inttoptr i32 %call to i32*<br> %1 = load i32* %0, align 4, !tbaa !0<br> %arrayidx1 = getelementptr inbounds i32* %0, i32 1<br>
%2 = load i32* %arrayidx1, align 4, !tbaa !0<br> %mul = mul nsw i32 %2, %1<br> ret i32 %mul</div><div>----------------------------------------------------------------------------</div><div> </div><div>After instruction selection I get the following:</div>
<div> </div><div>----------------------------------------------------------------------------<br> BB#0: derived from LLVM BB %entry<br> ADJCALLSTACKDOWN 8, %SP<imp-def,dead>, %SP<imp-use><br> JSUB <ga:@_Z7zahlIntv>, 1, <fi#-2>, 0, <fi#0>, 0, ...<br>
ADJCALLSTACKUP 8, 0, %SP<imp-def,dead>, %SP<imp-use><br> %vreg0<def> = LDrid <fi#-2>, 4; mem:LD4[FixedStack-2] AkkuDRegs:%vreg0<br> %vreg2<def> = COPY %vreg0; PointerAdrRegs:%vreg2 AkkuDRegs:%vreg0<br>
%vreg1<def> = LDridAddr %vreg2, 4; mem:LD4[%arrayidx1](tbaa=!"int") AkkuDRegs:%vreg1 PointerAdrRegs:%vreg2<br> %vreg4<def> = COPY %vreg0; PointerAdrRegs:%vreg4 AkkuDRegs:%vreg0<br> %vreg3<def> = MULINTDLDridAddr %vreg1<kill>, %vreg4, 0; mem:LD4[%0](tbaa=!"int") AkkuDRegs:%vreg3,%vreg1 PointerAdrRegs:%vreg4</div>
<div> STrid <fi#-, 0, %vreg3<kill>; mem:ST4[FixedStack-1] AkkuDRegs:%vreg3<br>----------------------------------------------------------------------------</div><div> </div><div>So far everything seems to look fine. But I don't understand why there is a %vreg4 as it has the same value as %vreg2.</div>
<div> </div><div>At the end I get the following:</div><div> </div><div>----------------------------------------------------------------------------<br> JSUB <ga:@_Z7zahlIntv>, 1, %SP, 24, %SP, 0, %AKKU1D<imp-def,dead>, %AR2<imp-def,dead><br>
%AKKU1D<def> = LDrid %SP, 28; mem:LD4[FixedStack-2]<br> STrid %SP, 8, %AKKU1D<kill><br> %AKKU1D<def> = LDrid %SP, 8<br> %AR2<def> = LAR2d %AKKU1D<kill><br> %AKKU1D<def> = LDridAddr %AR2<kill>, 4; mem:LD4[%arrayidx1](tbaa=!"int")<br>
STrid %SP, 12, %AKKU1D<kill><br> %AKKU1D<def> = LDrid %SP, 8<br> %AR2<def> = LAR2d %AKKU1D<kill><br> %AKKU1D<def> = LDrid %SP, 12<br> %AKKU1D<def> = MULINTDLDridAddr %AKKU1D<kill>, %AR2<kill>, 0; mem:LD4[%0](tbaa=!"int")<br>
STrid %SP, 0, %AKKU1D<kill>; mem:ST4[FixedStack-1]<br>----------------------------------------------------------------------------</div><div> </div><div>It should be obvious that the second " %AR2<def> = LAR2d %AKKU1D<kill>" is unneccessary. I've no idea why llvm thinks it needs to fill the register with the prober value again. No instruction in the whole block is destroying the value in AR2. Might it be because %AR2 is marked kill in the LDridAddr instruction? If so, how can I mark the instruction that it isn't destroying the register value? The following is the definition of the instruction:</div>
<div> </div><div>----------------------------------------------------------------------------</div><div><font face="Consolas"><font face="Consolas"><p>def MEMirPtr : Operand<i32> {</p>
<p> let PrintMethod = "printMemOperand";</p>
<p> let MIOperandInfo = (ops PointerAdrRegs, i64imm);</p>
<p>}</p><font face="Consolas"><font face="Consolas"><p>class AwlInst<dag outs, dag ins, string asmstr, list<dag> pattern, int size = 0> : Instruction {</p><p>
</p><p> field bits<32> Inst;</p><p>
</p><p> let Namespace = "Awl0";</p><p>
</p><p> dag OutOperandList = outs;</p><p>
</p><p> dag InOperandList = ins;</p><p>
</p><p> let AsmString = asmstr;</p><p>
</p><p> let Pattern = pattern;</p><p>
</p><p> let Size = size;</p><p>
</p><p>}</p></font></font><p> </p></font></font></div><div><font face="Consolas"><font face="Consolas"><p> def LDridAddr : AwlInst<(outs AkkuDRegs:$dst), (ins MEMirPtr:$addr),</p>
<p> "L D$addr; \t// LDridAddr $addr -> $dst",</p>
<p> [(set AkkuDRegs:$dst, (load addraddr:$addr))], 4>;</p><p>----------------------------------------------------------------------------</p><p> </p><p> </p><p>The complete output of print-after-all is attached to this mail.</p>
<p>Any hints are appreciated.</p><p>Thanks in advance,</p><p>Markus</p></font></font></div></div>