Hello, I've noticed the following issue while testing some codegen tests, i would like to know if it's a missed optimization or i missed something out here. This is for an out of tree backend im writing. I managed to reduce it to the following C function:<br>
<br>void foo(int *a) // int here is 16bits<br>{<br>  *a &= 0xFF;<br>}<br><br>This is the code before regalloc:<br>    Live Ins: %R25R24<br>    %vreg0<def> = COPY %R25R24; DREGS:%vreg0<br>    %vreg2<def> = COPY %vreg0; PTRREGS:%vreg2 DREGS:%vreg0<br>
    %vreg1<def> = LDWRd %vreg2; mem:LD2[%a](align=1)(tbaa=!"int") DLDREGS:%vreg1 PTRREGS:%vreg2<br>    %vreg3<def> = ANDIWRdK %vreg1, 255; DLDREGS:%vreg3,%vreg1<br>    %vreg5<def> = COPY %vreg0; PTRREGS:%vreg5 DREGS:%vreg0<br>
    STWRr %vreg5, %vreg3<kill>; mem:ST2[%a](align=1)(tbaa=!"int") PTRREGS:%vreg5 DLDREGS:%vreg3<br>    RET<br><br>From above, the 3rd COPY instruction is redundant since it does exactly the same thing as the second COPY instruction, so the stw (store) instr should take %vreg2 instead of %vreg5. After regalloc we get this code:<br>
    Live Ins: %R25R24<br>    %R27R26<def> = COPY %R25R24<br>    %R19R18<def> = LDWRd %R27R26<kill>; mem:LD2[%a](align=1)(tbaa=!"int") // <---------- why is R27:R26 killed?<br>    %R19R18<def> = ANDIWRdK %R19R18, 255<br>
    %R27R26<def> = COPY %R25R24<kill> // <------------------ why is this emitted?<br>    STWRr %R27R26<kill>, %R19R18<kill>; mem:ST2[%a](align=1)(tbaa=!"int")<br>    RET<br><br>The last copy instruction should be removed as pointed out above, but since R27R26 is killed in the load instruction it has to be emitted. About the insane amount of regclasses there, the load/store and the andi instructions take subsets of regs from the main register class, they cant work with all registers, that's why STW and LDW needs R27R26 since it belongs to the ptr reg class and not R25R24 where the "a" ptr is. As a test i made the load/store instructions work with the DREGS which is the main class and the problem was solved, but of course this is illegal code :)<br>
<br>Thanks<br>