aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2016-11-17 08:39:33 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2016-11-17 08:39:33 +0000
commitf8294131788cec4ca520032073e92928fbbb06a2 (patch)
tree51735ece6cbb2b9b1ce2bad7559b4555a93ffb61 /gcc
parent04f1c83099aab49f530f492b9d8119cf9d5ffcdd (diff)
downloadgcc-f8294131788cec4ca520032073e92928fbbb06a2.zip
gcc-f8294131788cec4ca520032073e92928fbbb06a2.tar.gz
gcc-f8294131788cec4ca520032073e92928fbbb06a2.tar.bz2
re PR tree-optimization/78305 (Wrong constant folding)
2016-11-17 Richard Biener <rguenther@suse.de> PR middle-end/78305 * fold-const.c (negate_expr_p): Fix multiplication case. * gcc.dg/torture/pr78305.c: New testcase. From-SVN: r242536
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/fold-const.c6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr78305.c14
4 files changed, 27 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c1c5b8b..b8e527a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2016-11-17 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/78305
+ * fold-const.c (negate_expr_p): Fix multiplication case.
+
2016-11-17 Chung-Lin Tang <cltang@codesourcery.com>
PR target/78357
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index c597414..f4b2cfa 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 abfea507..c142b4b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-11-17 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/78305
+ * gcc.dg/torture/pr78305.c: New testcase.
+
2016-11-17 Janus Weil <janus@gcc.gnu.org>
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 0000000..ccb8c6f
--- /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;
+}