[Bug target/63390] [SH] Hoist/schedule constant pool loads

2014-09-28 Thread olegendo at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63390

--- Comment #1 from Oleg Endo olegendo at gcc dot gnu.org ---
Adding a loop to the example above shows that function address loads are
hoisted already out of loops, but constant loads are not.

void foo (unsigned int, int);
void test (unsigned int* x, int c)
{
  while (--c)
  if (__builtin_expect ((*x  1) != 0, 1))
foo (*x  1, 123456);
}

results in:
mov.l   r8,@-r15
mov r5,r8
mov.l   r9,@-r15
mov r4,r9
mov.l   r10,@-r15
mov.l   .L11,r10function address load
sts.l   pr,@-r15
.L2:
dt  r8
bt  .L10
.align 2
.L4:
mov.l   @r9,r4  constant load
shlrr4
tst r4,r4
bt  .L2
mov.l   .L12,r5
jsr @r10
nop
dt  r8
bf  .L4
.L10:
lds.l   @r15+,pr
mov.l   @r15+,r10
mov.l   @r15+,r9
rts
mov.l   @r15+,r8


[Bug target/63390] [SH] Hoist/schedule constant pool loads

2014-09-28 Thread olegendo at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63390

--- Comment #2 from Oleg Endo olegendo at gcc dot gnu.org ---
(In reply to Oleg Endo from comment #1)

 .L4:
 mov.l   @r9,r4  constant load
 shlrr4
 tst r4,r4
 bt  .L2
 mov.l   .L12,r5
 jsr @r10
 nop
 dt  r8
 bf  .L4
 .L10:
 lds.l   @r15+,pr
 mov.l   @r15+,r10
 mov.l   @r15+,r9
 rts
 mov.l   @r15+,r8

I've marked the wrong load insn as constant load.  In this case hoisting it out
of the loop wouldn't make lots of sense, since it's loaded into the call
clobbered register r5.  Bad example.  But it would still be better to hoist the
load into the preceding basic block.