]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/26729 (bad bitops folding)
authorRoger Sayle <roger@eyesopen.com>
Mon, 15 May 2006 16:14:46 +0000 (16:14 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Mon, 15 May 2006 16:14:46 +0000 (16:14 +0000)
PR middle-end/26729
* fold-const.c (fold_truthop): Check integer_nonzerop instead of
!integer_zerop to avoid problems with TREE_OVERFLOW.

* gcc.dg/pr26729-1.c: New test case.

From-SVN: r113795

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr26729-1.c [new file with mode: 0644]

index 07e672a2aa672bf2611b94cc9d93189f35e00bc7..9e15740847293b68e83ffad34cc1afc0c16bf91f 100644 (file)
@@ -1,3 +1,9 @@
+2006-05-15  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/26729
+       * fold-const.c (fold_truthop): Check integer_nonzerop instead of
+       !integer_zerop to avoid problems with TREE_OVERFLOW.
+
 2005-05-13  Zdenek Dvorak  <dvorakz@suse.cz>
 
        PR rtl-optimization/27335
index 3b4404e461badd9a88a5d79825d29403020f4ada..7a645c3569bd3dfb11973d38b9ece7ca2dd8574b 100644 (file)
@@ -4808,10 +4808,10 @@ fold_truthop (enum tree_code code, tree truth_type, tree lhs, tree rhs)
       l_const = fold_convert (lntype, l_const);
       l_const = unextend (l_const, ll_bitsize, ll_unsignedp, ll_and_mask);
       l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos), 0);
-      if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const,
-                                       fold (build1 (BIT_NOT_EXPR,
-                                                     lntype, ll_mask)),
-                                       0)))
+      if (integer_nonzerop (const_binop (BIT_AND_EXPR, l_const,
+                                        fold (build1 (BIT_NOT_EXPR,
+                                                      lntype, ll_mask)),
+                                        0)))
        {
          warning ("comparison is always %d", wanted_code == NE_EXPR);
 
@@ -4823,10 +4823,10 @@ fold_truthop (enum tree_code code, tree truth_type, tree lhs, tree rhs)
       r_const = fold_convert (lntype, r_const);
       r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask);
       r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos), 0);
-      if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const,
-                                       fold (build1 (BIT_NOT_EXPR,
-                                                     lntype, rl_mask)),
-                                       0)))
+      if (integer_nonzerop (const_binop (BIT_AND_EXPR, r_const,
+                                        fold (build1 (BIT_NOT_EXPR,
+                                                      lntype, rl_mask)),
+                                        0)))
        {
          warning ("comparison is always %d", wanted_code == NE_EXPR);
 
index 5883d5525dbc160991b7f0928778e1c69d6244cf..0ed0913452cec7b000ce582a0122941a336122d9 100644 (file)
@@ -1,3 +1,8 @@
+2006-05-15  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/26729
+       * gcc.dg/pr26729-1.c: New test case.
+
 2006-05-15  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/27582
diff --git a/gcc/testsuite/gcc.dg/pr26729-1.c b/gcc/testsuite/gcc.dg/pr26729-1.c
new file mode 100644 (file)
index 0000000..2f55ef7
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+void abort(void);
+
+__attribute__((noinline))
+int f (unsigned short word) {  
+  return (word & 0x1) && (((unsigned short) (word & 0x8000)) == 0x8000);
+}
+
+int main(void) {
+  if (!f(0x8001))
+    abort();
+  return 0;
+}
+