This is the mail archive of the
mailing list for the GCC project.
PATCH for bogus loop optimization, part 2
- To: egcs-patches at cygnus dot com
- Subject: PATCH for bogus loop optimization, part 2
- From: Mark Mitchell <mark at markmitchell dot com>
- Date: Thu, 16 Jul 1998 10:44:13 -0700
- Cc: Jeff Law <law at cygnus dot com>
- Reply-to: mark at markmitchell dot com
movb $3,(%eax) # s[i] = 3
incl %eax # EAX = &s[i+1]
cmpl %edx,%eax # if (&s[i] >= &s)
jae .L3 # break;
cmpl %ebx,%eax # if (&s[i] >= (signed!) &s)
jge .L5 # continue;
Note the signed comparison of the two addresses on the penultimate
line. The patch consists mostly of a large comments explaining what's
going wrong, so I'll omit that here.
BTW, one way to fix this problem, and retain the optimization, might
be along the lines of:
o Pointers can never overflow in a conformant program. (Neither
can integers, but people do make use of this wrap-around behavior
o Any comparison between pointers should be unsigned.
Thus a fixup pass could go through at the end of loop and replace and
signed comparisons of pointers (SYMBOL_REFs, LABEL_REFs, REG's with
REGNO_POINTER_FLAG) registers with unsigned comparisons.
Then, as long we only replace things which inducntion variables that
are pointers (by the same definition), we should be OK.
Mark Mitchell firstname.lastname@example.org
Mark Mitchell Consulting http://www.markmitchell.com