------- Comment #12 from rask at gcc dot gnu dot org  2007-08-19 13:00 -------
 void *foo(unsigned a, unsigned b) {
     unsigned sum = a + b;
     if (sum < a) return 0;
     if (sum == 0) sum = 1;

To be able to optimize both comparisons, we need to have the same comparison
operands. The only way I can see this happening is to canonicalize the overflow
check as "a + b < 0" with the obvious fear that since a and b are both
unsigned, GCC will optimize the comparison away as always false - unless taught
not to do so. I'll see what I can do.

Additionally, the resulting asm seems to be a bit stupid:

        testl   %edx,   %edx
        movl    $1,     %eax
        cmove   %eax,   %edx

should be just

        testl   %edx,   %edx
        sete    %dl


-- 

rask at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rask at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-08-19 13:00:47
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30315

Reply via email to