[Bug target/36133] GCC creates suboptimal ASM : Code includes unneeded TST instructions
ams at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Mon Nov 10 12:31:00 GMT 2008
------- Comment #7 from ams at gcc dot gnu dot org 2008-11-10 12:29 -------
(In reply to comment #4)
> There are two causes where GCC generates unneeded TST instructions.
> A) General arithmetic
> lsr.l #1,D0
> tst.l d0
> jbne ...
>
> This tst instruction is unneeded as the LSR is setting the flags correctly
> already.
This is NOT correct. LSL does write to the condition codes, but not all of it.
In particular, the bit involved in the not-equal test is not set.
This TST *is* required.
> B) subq.l #1,D1
> tst.l d1
> jbne ...
>
> This unneeded TST is related to the compile option used.
> If you compile the source with "-O2" then the second unneeded TST instructions
> are not included in the source.
Please check the code mode carefully. This TST is not related to the SUBQ
instruction. This TST is related to the LSL instruction - the TST is a branch
target.
The compiler has combined the initial and subsequent loop condition tests into
one test, thus saving space, as per the -Os requirements. In this case there is
an alternative, more speed efficient solution, but that is a separate problem,
and not a misuse of the TST instruction.
As you say, the compiler gets it right at -O2, so the machine description is
clearly correct, in this respect.
--
ams at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36133
More information about the Gcc-bugs
mailing list