This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Buggy peephole prevents bootstrap (i386)
> On Fri, 13 Oct 2000, Zack Weinberg wrote:
>
> > This transformation was done to save space - the add instruction is
> > three bytes shorter than the corresponding compare. However, add
> > doesn't set the condition codes the same way cmp and sub do. It
> > appears (from staring at the confusing Intel reference manual) that
> > add's condition codes are usable only with the signed conditional
This don't seems to be right case. My understanding is that
cmp is equivalent to sub
add is equivalent to sub with one operand negated (the second one)
For unsigned comparisons, the carry flag is only important and this one has
to work as expected, otherwise DImode arithmetics is broken.
I believe that we are just negating the wrong argument and thats why condition
code needs to be reversed when it is eq/ne. I've changed this in the md file
and this prevents problems with Jakub's testcase (it may be worthwile to
introduce new CC mode to be able to swap condition when needed).
I am just in the middle of bootstrap to see whether it fixes this problem as
well.
When I was writting the patch (it was actually bugfix to other condition
code missunderstanding in gcc), I did wrong assumption about symetricity
of add and swapped operands to be in canonical form.
>
> Actually, it's the other way around. You can replace
> cmp $val,%reg
> j<cc> ; cc is one of a,b,ae,be or their aliases
>
> with
> add $-val,%reg
> jn<cc>
>
> only for _unsigned_ comparisons (and val != 0). Signed comparisons get
> the overflow bit wrong. If you don't believe me, run a few cases through
> a debugger - I had to do so to make sure I was correct. ;-)
I will verify this once again...
Honza
>
> Regards, Alan Modra
> --
> Linuxcare. Support for the Revolution.
>