[Bug optimization/9196] [3.4 regression] Inlining of function with void * arithmetic is misoptimized

pinskia at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Mon Aug 11 02:55:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2003-07-28 01:17:21         |2003-08-11 02:55:06
               date|                            |


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-08-11 02:55 -------
It is not the char * arithmetic that is being miscompiled as if I replace the void* inside __memrchr 
with char*, I still get the miscompile.  Also the code is wrong it uses D when it really meant to use 
d and it should be using "+" instead of "=" aqnd it has enouns additions of accesing the memory.
__inline void *
__memrchr (__const char *__s, int __c, size_t __n)
{
  register unsigned long int __d0;

  register char *__res;
  if (__n == 0)
    return ((void *)0);
  __res = __s + __n - 1;
  __d0 = __n;

  __asm__ __volatile__
    ("std\n\t"
     "repne; scasb\n\t"
     "je 1f\n\t"
     "orl $-1,%0\n"
     "1:\tcld"
     : "+d" (__res), "+c" (__d0)
     : "a" (__c)
     : "cc");

  return (void*)(__res + 1);
}

If I change "register char *__res;" to "register int __res;", it works so it looks like it is the pointer 
which causes this.

Also it goes wrong in combine (GCC sets __res dead after asm for some reason).



More information about the Gcc-bugs mailing list