This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH for bogus loop optimization, part 2



    .L5:
	    movb $3,(%eax)           # s[i] = 3
	    incl %eax                # EAX = &s[i+1]
	    cmpl %edx,%eax           # if (&s[i] >= &s[40])
	    jae .L3                  #   break;
	    cmpl %ebx,%eax           # if (&s[i] >= (signed!) &s[0])
	    jge .L5                  #  continue;
    .L3:

  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
    for integers.)

  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 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]