+2005-05-13 Zdenek Dvorak <dvorakz@suse.cz>
+
+ PR tree-optimization/27003
+ * tree.c (build_int_cst_type): Avoid shift by size of type.
+
2006-05-11 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR target/27421
+2005-05-13 Zdenek Dvorak <dvorakz@suse.cz>
+
+ PR tree-optimization/27003
+ * gcc.dg/pr27003.c: New test.
+
2006-05-11 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR target/27421
--- /dev/null
+/* { dg-do compile } */
+/* { dg-do run } */
+/* { dg-options "-Os" } */
+
+unsigned int
+foo (unsigned int x)
+{
+ unsigned int r = x;
+ while (--x)
+ r *= x;
+ return r;
+}
+
+unsigned long long
+bar (unsigned long long x)
+{
+ unsigned long long r = x;
+ while (--x)
+ r *= x;
+ return r;
+}
+
+extern void abort (void);
+
+int
+main (void)
+{
+ if (foo (5) != 120 || bar (5) != 120)
+ abort ();
+ return 0;
+}
build_int_cst_type (tree type, HOST_WIDE_INT low)
{
unsigned HOST_WIDE_INT val = (unsigned HOST_WIDE_INT) low;
- unsigned HOST_WIDE_INT hi;
+ unsigned HOST_WIDE_INT hi, mask;
unsigned bits;
bool signed_p;
bool negative;
negative = ((val >> (bits - 1)) & 1) != 0;
/* Mask out the bits outside of the precision of the constant. */
+ mask = (((unsigned HOST_WIDE_INT) 2) << (bits - 1)) - 1;
+
if (signed_p && negative)
- val = val | ((~(unsigned HOST_WIDE_INT) 0) << bits);
+ val |= ~mask;
else
- val = val & ~((~(unsigned HOST_WIDE_INT) 0) << bits);
+ val &= mask;
}
/* Determine the high bits. */
else
{
bits -= HOST_BITS_PER_WIDE_INT;
- hi = hi & ~((~(unsigned HOST_WIDE_INT) 0) << bits);
+ mask = (((unsigned HOST_WIDE_INT) 2) << (bits - 1)) - 1;
+ hi &= mask;
}
}