From f8294131788cec4ca520032073e92928fbbb06a2 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 17 Nov 2016 08:39:33 +0000 Subject: [PATCH] re PR tree-optimization/78305 (Wrong constant folding) 2016-11-17 Richard Biener PR middle-end/78305 * fold-const.c (negate_expr_p): Fix multiplication case. * gcc.dg/torture/pr78305.c: New testcase. From-SVN: r242536 --- gcc/ChangeLog | 5 +++++ gcc/fold-const.c | 6 +++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr78305.c | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr78305.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c1c5b8bff48..b8e527aa59a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-11-17 Richard Biener + + PR middle-end/78305 + * fold-const.c (negate_expr_p): Fix multiplication case. + 2016-11-17 Chung-Lin Tang PR target/78357 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c59741440af..f4b2cfa743e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -450,13 +450,13 @@ negate_expr_p (tree t) if (TYPE_UNSIGNED (type)) break; /* INT_MIN/n * n doesn't overflow while negating one operand it does - if n is a power of two. */ + if n is a (negative) power of two. */ if (INTEGRAL_TYPE_P (TREE_TYPE (t)) && ! TYPE_OVERFLOW_WRAPS (TREE_TYPE (t)) && ! ((TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST - && ! integer_pow2p (TREE_OPERAND (t, 0))) + && wi::popcount (wi::abs (TREE_OPERAND (t, 0))) != 1) || (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST - && ! integer_pow2p (TREE_OPERAND (t, 1))))) + && wi::popcount (wi::abs (TREE_OPERAND (t, 1))) != 1))) break; /* Fall through. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index abfea5077fb..c142b4b013d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-17 Richard Biener + + PR middle-end/78305 + * gcc.dg/torture/pr78305.c: New testcase. + 2016-11-17 Janus Weil PR fortran/66227 diff --git a/gcc/testsuite/gcc.dg/torture/pr78305.c b/gcc/testsuite/gcc.dg/torture/pr78305.c new file mode 100644 index 00000000000..ccb8c6faa78 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr78305.c @@ -0,0 +1,14 @@ +/* { dg-require-effective-target int32plus } */ +/* { dg-do run } */ + +int main () +{ + int a = 2; + int b = 1; + + int t = -1 * ( -0x40000000 * a / ( -0x20000000 + b ) ) / -1; + + if (t != 4) __builtin_abort(); + + return 0; +} -- 2.30.2