This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/30315] optimize unsigned-add overflow test on x86 to use cpu flags from addl
- From: "rask at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Aug 2007 13:00:47 -0000
- Subject: [Bug target/30315] optimize unsigned-add overflow test on x86 to use cpu flags from addl
- References: <bug-30315-11337@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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