]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR rtl-optimization/41917 (Strange athrithmetic result with -O3)
authorPaolo Bonzini <bonzini@gnu.org>
Tue, 16 Feb 2010 08:15:37 +0000 (08:15 +0000)
committerPaolo Bonzini <bonzini@gcc.gnu.org>
Tue, 16 Feb 2010 08:15:37 +0000 (08:15 +0000)
PR rtl-optimization/41917

* rtlanal.c (num_sign_bit_copies1) <case UMOD>: If sign bit of second
operand isn't known to be 0, return 1.

testsuite:
* gcc.c-torture/execute/pr41917.c: New test.

From-SVN: r156795

gcc/ChangeLog
gcc/rtlanal.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr41917.c [new file with mode: 0644]

index 750cd0b65d207930517749e86174685f9e2145c7..e1acf6202df99d1bc7633bd308830200ab3f1196 100644 (file)
@@ -1,3 +1,9 @@
+2010-02-16  Paolo Bonzini  <bonzini@gnu.org>
+
+       PR rtl-optimization/41917
+       * rtlanal.c (num_sign_bit_copies1) <case UMOD>: If sign bit of second
+       operand isn't known to be 0, return 1.
+
 2010-02-04  Richard Guenther  <rguenther@suse.de>
 
        PR rtl-optimization/42952
index 060ed9e969ca2fe455f205613c4201a527488669..0502850cbe10969d9e99bde07d4d0b0c7dc5c92d 100644 (file)
@@ -4444,8 +4444,16 @@ num_sign_bit_copies1 (const_rtx x, enum machine_mode mode, const_rtx known_x,
                                           known_x, known_mode, known_ret);
 
     case UMOD:
-      /* The result must be <= the second operand.  */
-      return cached_num_sign_bit_copies (XEXP (x, 1), mode,
+      /* The result must be <= the second operand.  If the second operand
+        has (or just might have) the high bit set, we know nothing about
+        the number of sign bit copies.  */
+      if (bitwidth > HOST_BITS_PER_WIDE_INT)
+       return 1;
+      else if ((nonzero_bits (XEXP (x, 1), mode)
+               & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
+       return 1;
+      else
+       return cached_num_sign_bit_copies (XEXP (x, 1), mode,
                                           known_x, known_mode, known_ret);
 
     case DIV:
index 3f12af921e0f7f9c6fba154485c5332e72754799..82618ad8a29029a46f32dbe5d6ff9a8f5452294b 100644 (file)
@@ -1,3 +1,7 @@
+2010-02-16  Paolo Bonzini  <bonzini@gnu.org>
+
+       * gcc.c-torture/execute/pr41917.c: New test.
+
 2010-02-04  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libfortran/42901
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr41917.c b/gcc/testsuite/gcc.c-torture/execute/pr41917.c
new file mode 100644 (file)
index 0000000..4a9ada9
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR rtl-optimization/41917 */
+
+extern void abort (void);
+unsigned int a = 1;
+
+int
+main (void)
+{
+  unsigned int b, c, d;
+
+  if (sizeof (int) != 4 || (int) 0xc7d24b5e > 0)
+    return 0;
+
+  c = 0xc7d24b5e;
+  d = a | -2;
+  b = (d == 0) ? c : (c % d);
+  if (b != c)
+    abort ();
+
+  return 0;
+}