https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63321

--- Comment #5 from Oleg Endo <olegendo at gcc dot gnu.org> ---
(In reply to Oleg Endo from comment #3)
> A more advanced example:
> 
> void test4 (unsigned int x, unsigned int* y)
> {
>   y[0] = (x >> 0) & 1;
>   y[1] = (x >> 1) & 1;
>   y[2] = x >> 2;
> }

Which is just another example of re-using intermediate results of stitched
shifts, only a bit more complex due to the multiple-set insns.

void test5 (unsigned int x, unsigned int* y)
{
  y[0] = x << (2);
  y[1] = x << (2 + 2);
  y[2] = x << (2 + 2 + 8);
}

currently compiles to:
        mov     r4,r1
        shll2   r1
        mov.l   r1,@r5
        mov     r4,r1
        shll2   r1
        shll2   r1
        mov.l   r1,@(4,r5)
        mov     #12,r1
        shld    r1,r4
        rts
        mov.l   r4,@(8,r5)

better:
        shll2   r4
        mov.l   r4,@r5
        shll2   r4
        mov.l   r4,@(4,r5)
        shll8   r4
        rts
        mov.l   r4,@(8,r5)

See also some examples in PR 54089.

Reply via email to