]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR rtl-optimization/34490 (r128833 causes miscompilation of glibc clock_gettime.c)
authorJakub Jelinek <jakub@redhat.com>
Tue, 18 Dec 2007 00:13:29 +0000 (01:13 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 18 Dec 2007 00:13:29 +0000 (01:13 +0100)
PR rtl-optimization/34490
* simplify-rtx.c (simplify_const_relational_operation): If !sign,
don't reduce mmin/mmax using num_sign_bit_copies.

* gcc.c-torture/execute/20071216-1.c: New test.

From-SVN: r131023

gcc/ChangeLog
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20071216-1.c [new file with mode: 0644]

index c71729dc02c32bcc992f03cabcab53fd5636a5c4..c3595a4dc61f2c0aff4ce185273705050fe5078d 100644 (file)
@@ -1,3 +1,9 @@
+2007-12-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/34490
+       * simplify-rtx.c (simplify_const_relational_operation): If !sign,
+       don't reduce mmin/mmax using num_sign_bit_copies.
+
 2007-12-17  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * doc/install.texi: Change recommended MPFR from 2.2.1 > 2.3.0.
index 0371339d5405ceebf2cf77c0ae07124a4bed6e32..fd14e407dc841f20fbe47665493e3a8fdcac176d 100644 (file)
@@ -4233,15 +4233,17 @@ simplify_const_relational_operation (enum rtx_code code,
       else
        {
          rtx mmin_rtx, mmax_rtx;
-         unsigned int sign_copies = num_sign_bit_copies (trueop0, mode);
          get_mode_bounds (mode, sign, mode, &mmin_rtx, &mmax_rtx);
 
-         /* Since unsigned mmin will never be interpreted as negative, use
-            INTVAL (and an arithmetic right shift).  */
-         mmin = INTVAL (mmin_rtx) >> (sign_copies - 1);
-         /* Since signed mmax will always be positive, use UINTVAL (and
-            a logical right shift).  */
-         mmax = UINTVAL (mmax_rtx) >> (sign_copies - 1);
+         mmin = INTVAL (mmin_rtx);
+         mmax = INTVAL (mmax_rtx);
+         if (sign)
+           {
+             unsigned int sign_copies = num_sign_bit_copies (trueop0, mode);
+
+             mmin >>= (sign_copies - 1);
+             mmax >>= (sign_copies - 1);
+           }
        }
 
       switch (code)
index 1650e37b85c0a484ad989f99a2bfacf44389e4b7..d42c3345884bcd14f2f7e83eb687824a86504182 100644 (file)
@@ -1,3 +1,8 @@
+2007-12-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/34490
+       * gcc.c-torture/execute/20071216-1.c: New test.
+
 2007-12-17  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * gcc.dg/torture/builtin-math-4.c: Remove XFAIL.
diff --git a/gcc/testsuite/gcc.c-torture/execute/20071216-1.c b/gcc/testsuite/gcc.c-torture/execute/20071216-1.c
new file mode 100644 (file)
index 0000000..a337b77
--- /dev/null
@@ -0,0 +1,38 @@
+/* PR rtl-optimization/34490 */
+
+extern void abort (void);
+
+static int x;
+
+int
+__attribute__((noinline))
+bar (void)
+{
+  return x;
+}
+
+int
+foo (void)
+{
+  long int b = bar ();
+  if ((unsigned long) b < -4095L)
+    return b;
+  if (-b != 38)
+    b = -2;
+  return b + 1;
+}
+
+int
+main (void)
+{
+  x = 26;
+  if (foo () != 26)
+    abort ();
+  x = -39;
+  if (foo () != -1)
+    abort ();
+  x = -38;
+  if (foo () != -37)
+    abort ();
+  return 0;
+}