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

--- Comment #112 from Oleg Endo <olegendo at gcc dot gnu.org> ---
I had a quick look at the gcc.target/sh/hiconst.c test case:

int rab (char *pt, int *pti)
{
  pt[2] = 0;
  pti[3] = 0;

  return 0;
}

without LRA:
        mov     #0,r0
        mov.b   r0,@(2,r4)
        rts     
        mov.l   r0,@(12,r5)


with LRA:
        mov     #0,r0
        mov.b   r0,@(2,r4)
        mov     #0,r1
        mov.l   r1,@(12,r5)
        rts     
        mov     #0,r0

Without LRA it seems some of the constant loads are CSE'ed, but the return
value constant load remains and reload-something figures it out.  With LRA it
seems that for the SImode store it wants to use R1, but for the QImode store it
needs to use R0.  It then rematerializes the constant load.  Increasing the
costs of constants:

@@ -3574,7 +3574,7 @@
          return true;
        }
       if (CONST_OK_FOR_I08 (INTVAL (x)))
-        *total = 0;
+        *total = 4;
       else if ((outer_code == AND || outer_code == IOR || outer_code == XOR)
               && CONST_OK_FOR_K08 (INTVAL (x)))
         *total = 1;

results in:
        mov     #0,r1
        mov     r1,r0
        mov.b   r0,@(2,r4)
        mov.l   r1,@(12,r5)
        rts     
        mov     r1,r0

That would make the hiconst test pass again of course, but is not much better. 
Probably a combination of constant optimization (PR 65069, PR 63390, PR 51708,
PR 54682) and an R0 pre-alloc would give optimal results.

Reply via email to