Instruction scheduler rewriting instructions?
Ramana Radhakrishnan
ramana.gcc@googlemail.com
Thu Dec 3 19:56:00 GMT 2015
On Thu, Dec 3, 2015 at 7:01 PM, Steve Ellcey <sellcey@imgtec.com> wrote:
> Can the instruction scheduler actually rewrite instructions? I didn't
> think so but when I compile some code on MIPS with:
>
> -O2 -fno-ivopts -fno-peephole2 -fno-schedule-insns2
>
> I get:
>
> $L4:
> lbu $3,0($4)
> addiu $4,$4,1
> lbu $2,0($5)
> beq $3,$0,$L7
> addiu $5,$5,1
>
> beq $3,$2,$L4
> subu $2,$3,$2
>
> When I changed -fno-schedule-insns2 to -fschedule-insns2, I get:
>
> $L4:
> lbu $3,0($4)
> addiu $5,$5,1
> lbu $2,-1($5)
> beq $3,$0,$L7
> addiu $4,$4,1
>
> beq $3,$2,$L4
> subu $2,$3,$2
>
> I.e. The addiu of $5 and the load using $5 have been swapped around
> and the load uses a different offset to compensate. I can't see
> where in the instruction scheduler that this would happen. Any
> help? This is on MIPS if that matters, though I didn't see any
> MIPS specific code for this. This issue is related to my earlier
> question about PR 48814 and ivopts (thus the -fno-ivopts option).
IIRC it's because the scheduler *thinks* it can get a tighter schedule
- probably because it thinks it can dual issue the lbu from $4 and the
addiu to $5. Can it think so ? This may be related -
https://gcc.gnu.org/ml/gcc-patches/2012-08/msg00155.html
regards
Ramana
>
> The C code I am looking at is the strcmp function from glibc:
>
> int
> strcmp (const char *p1, const char *p2)
> {
> const unsigned char *s1 = (const unsigned char *) p1;
> const unsigned char *s2 = (const unsigned char *) p2;
> unsigned char c1, c2;
>
> do
> {
> c1 = (unsigned char) *s1++;
> c2 = (unsigned char) *s2++;
> if (c1 == '\0')
> return c1 - c2;
> }
> while (c1 == c2);
>
> return c1 - c2;
> }
>
>
> Steve Ellcey
> sellcey@imgtec.com
More information about the Gcc
mailing list