From b936b23b658a0fdee7eec3f35a036ce1816dd57d Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Mon, 15 May 2006 16:14:46 +0000 Subject: [PATCH] re PR middle-end/26729 (bad bitops folding) 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 | 6 ++++++ gcc/fold-const.c | 16 ++++++++-------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr26729-1.c | 16 ++++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr26729-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 07e672a2aa67..9e1574084729 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2006-05-15 Roger Sayle + + 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 PR rtl-optimization/27335 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 3b4404e461ba..7a645c3569bd 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5883d5525dbc..0ed0913452ce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-05-15 Roger Sayle + + PR middle-end/26729 + * gcc.dg/pr26729-1.c: New test case. + 2006-05-15 Volker Reichelt 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 index 000000000000..2f55ef7f4f09 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr26729-1.c @@ -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; +} + -- 2.47.2