aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2018-05-04 07:25:54 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2018-05-04 07:25:54 +0000
commit9b5713f7ce06d6f4c0df7410352623573d2506ea (patch)
treeeba13e4f2bd5af58b7b12a026ef0d945237cb5f8 /gcc
parent047823853d8324eab7d6ad8f266ee5395c4a76ff (diff)
downloadgcc-9b5713f7ce06d6f4c0df7410352623573d2506ea.zip
gcc-9b5713f7ce06d6f4c0df7410352623573d2506ea.tar.gz
gcc-9b5713f7ce06d6f4c0df7410352623573d2506ea.tar.bz2
re PR lto/85574 (LTO bootstapped binaries differ)
2018-05-04 Richard Biener <rguenther@suse.de> PR middle-end/85574 * fold-const.c (negate_expr_p): Restrict negation of operand zero of a division to when we know that can happen without overflow. (fold_negate_expr_1): Likewise. * gcc.dg/torture/pr85574.c: New testcase. * gcc.dg/torture/pr57656.c: Use dg-additional-options. From-SVN: r259922
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/fold-const.c14
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr57656.c2
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr85574.c4
5 files changed, 29 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 229e095..3e769f5 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2018-05-04 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/85574
+ * fold-const.c (negate_expr_p): Restrict negation of operand
+ zero of a division to when we know that can happen without
+ overflow.
+ (fold_negate_expr_1): Likewise.
+
2018-05-04 Jakub Jelinek <jakub@redhat.com>
PR libstdc++/85466
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 6472f10..faa184a 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -474,12 +474,15 @@ negate_expr_p (tree t)
case EXACT_DIV_EXPR:
if (TYPE_UNSIGNED (type))
break;
- if (negate_expr_p (TREE_OPERAND (t, 0)))
+ /* In general we can't negate A in A / B, because if A is INT_MIN and
+ B is not 1 we change the sign of the result. */
+ if (TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
+ && negate_expr_p (TREE_OPERAND (t, 0)))
return true;
/* In general we can't negate B in A / B, because if A is INT_MIN and
B is 1, we may turn this into INT_MIN / -1 which is undefined
and actually traps on some architectures. */
- if (! INTEGRAL_TYPE_P (TREE_TYPE (t))
+ if (! ANY_INTEGRAL_TYPE_P (TREE_TYPE (t))
|| TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
|| (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
&& ! integer_onep (TREE_OPERAND (t, 1))))
@@ -652,14 +655,17 @@ fold_negate_expr_1 (location_t loc, tree t)
case EXACT_DIV_EXPR:
if (TYPE_UNSIGNED (type))
break;
- if (negate_expr_p (TREE_OPERAND (t, 0)))
+ /* In general we can't negate A in A / B, because if A is INT_MIN and
+ B is not 1 we change the sign of the result. */
+ if (TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
+ && negate_expr_p (TREE_OPERAND (t, 0)))
return fold_build2_loc (loc, TREE_CODE (t), type,
negate_expr (TREE_OPERAND (t, 0)),
TREE_OPERAND (t, 1));
/* In general we can't negate B in A / B, because if A is INT_MIN and
B is 1, we may turn this into INT_MIN / -1 which is undefined
and actually traps on some architectures. */
- if ((! INTEGRAL_TYPE_P (TREE_TYPE (t))
+ if ((! ANY_INTEGRAL_TYPE_P (TREE_TYPE (t))
|| TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
|| (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
&& ! integer_onep (TREE_OPERAND (t, 1))))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6b50775..9e5784e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-05-04 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/85574
+ * gcc.dg/torture/pr85574.c: New testcase.
+ * gcc.dg/torture/pr57656.c: Use dg-additional-options.
+
2018-05-04 Jakub Jelinek <jakub@redhat.com>
PR libstdc++/85466
diff --git a/gcc/testsuite/gcc.dg/torture/pr57656.c b/gcc/testsuite/gcc.dg/torture/pr57656.c
index 4f3645e..0249014 100644
--- a/gcc/testsuite/gcc.dg/torture/pr57656.c
+++ b/gcc/testsuite/gcc.dg/torture/pr57656.c
@@ -1,5 +1,5 @@
/* { dg-do run } */
-/* { dg-options "-fstrict-overflow" } */
+/* { dg-additional-options "-fstrict-overflow" } */
int main (void)
{
diff --git a/gcc/testsuite/gcc.dg/torture/pr85574.c b/gcc/testsuite/gcc.dg/torture/pr85574.c
new file mode 100644
index 0000000..5d95c96
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr85574.c
@@ -0,0 +1,4 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fwrapv" } */
+
+#include "pr57656.c"