gcc/gcc43-pr37924.patch

107 lines
2.7 KiB
Diff
Raw Normal View History

2008-11-05 10:15:48 +00:00
2008-10-28 Jakub Jelinek <jakub@redhat.com>
PR c/37924
* combine.c (make_compound_operation): Don't call make_extraction with
non-positive length.
(simplify_shift_const_1): Canonicalize count even if complement_p.
* gcc.c-torture/execute/pr37924.c: New test.
--- gcc/combine.c (revision 141412)
+++ gcc/combine.c (revision 141413)
@@ -7024,7 +7024,8 @@ make_compound_operation (rtx x, enum rtx
if (GET_CODE (rhs) == CONST_INT
&& GET_CODE (lhs) == ASHIFT
&& GET_CODE (XEXP (lhs, 1)) == CONST_INT
- && INTVAL (rhs) >= INTVAL (XEXP (lhs, 1)))
+ && INTVAL (rhs) >= INTVAL (XEXP (lhs, 1))
+ && INTVAL (rhs) < mode_width)
{
new = make_compound_operation (XEXP (lhs, 0), next_code);
new = make_extraction (mode, new,
@@ -7044,6 +7045,7 @@ make_compound_operation (rtx x, enum rtx
&& (OBJECT_P (SUBREG_REG (lhs))))
&& GET_CODE (rhs) == CONST_INT
&& INTVAL (rhs) < HOST_BITS_PER_WIDE_INT
+ && INTVAL (rhs) < mode_width
&& (new = extract_left_shift (lhs, INTVAL (rhs))) != 0)
new = make_extraction (mode, make_compound_operation (new, next_code),
0, NULL_RTX, mode_width - INTVAL (rhs),
@@ -9023,11 +9025,6 @@ simplify_shift_const_1 (enum rtx_code co
if (GET_CODE (varop) == CLOBBER)
return NULL_RTX;
- /* If we discovered we had to complement VAROP, leave. Making a NOT
- here would cause an infinite loop. */
- if (complement_p)
- break;
-
/* Convert ROTATERT to ROTATE. */
if (code == ROTATERT)
{
@@ -9073,6 +9070,11 @@ simplify_shift_const_1 (enum rtx_code co
}
}
+ /* If we discovered we had to complement VAROP, leave. Making a NOT
+ here would cause an infinite loop. */
+ if (complement_p)
+ break;
+
/* An arithmetic right shift of a quantity known to be -1 or 0
is a no-op. */
if (code == ASHIFTRT
--- gcc/testsuite/gcc.c-torture/execute/pr37924.c (revision 0)
+++ gcc/testsuite/gcc.c-torture/execute/pr37924.c (revision 141413)
@@ -0,0 +1,50 @@
+/* PR c/37924 */
+
+extern void abort (void);
+
+signed char a;
+unsigned char b;
+
+int
+test1 (void)
+{
+ int c = -1;
+ return ((unsigned int) (a ^ c)) >> 9;
+}
+
+int
+test2 (void)
+{
+ int c = -1;
+ return ((unsigned int) (b ^ c)) >> 9;
+}
+
+int
+main (void)
+{
+ a = 0;
+ if (test1 () != (-1U >> 9))
+ abort ();
+ a = 0x40;
+ if (test1 () != (-1U >> 9))
+ abort ();
+ a = 0x80;
+ if (test1 () != (a < 0) ? 0 : (-1U >> 9))
+ abort ();
+ a = 0xff;
+ if (test1 () != (a < 0) ? 0 : (-1U >> 9))
+ abort ();
+ b = 0;
+ if (test2 () != (-1U >> 9))
+ abort ();
+ b = 0x40;
+ if (test2 () != (-1U >> 9))
+ abort ();
+ b = 0x80;
+ if (test2 () != (-1U >> 9))
+ abort ();
+ b = 0xff;
+ if (test2 () != (-1U >> 9))
+ abort ();
+ return 0;
+}