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]
Other format: [Raw text]

Re: Fold constant shifts in combine


This patch causes the following code to be miscompiled:

Wed Feb 19 18:45:45 CET 2003  Jan Hubicka  <jh at suse dot cz>
	* combine.c (simplify_shift_const):  Simplify few special cases
	into constants.

#define GET_FIELD(X, FROM, TO) \
  ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
#define SIGN_EXTEND(VAL,BITS) \
  ((int) ((VAL) >> ((BITS) - 1) ? (-1 << (BITS)) | (VAL) : (VAL)))

unsigned int *
foo (unsigned int val)
{
  unsigned int *p = (unsigned int *) 0x4000c51c;

  p += SIGN_EXTEND (GET_FIELD (val, 19, 28) |
                    GET_FIELD (val, 29, 29) << 10 |
                    GET_FIELD (val, 11, 15) << 11 |
                    GET_FIELD (val, 31, 31) << 16, 17);

  return p;
}
int
main ()
{
  printf ("p = 0x%x\n", foo (0xe85f1845));
  exit (0);
}

The sign extension is not handled correctly.

Dave


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