aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2016-06-25 19:20:15 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2016-06-25 19:20:15 +0200
commit2a65e70bcfb000b229a2cbf54b06956108443598 (patch)
treee8e53d72f842bb86f62249822f10a715435f81e8
parent7805417a5d2a9a79a3858b82d60169178f59c6f1 (diff)
downloadgcc-2a65e70bcfb000b229a2cbf54b06956108443598.zip
gcc-2a65e70bcfb000b229a2cbf54b06956108443598.tar.gz
gcc-2a65e70bcfb000b229a2cbf54b06956108443598.tar.bz2
re PR tree-optimization/71631 (Wrong constant folding)
PR tree-optimization/71631 * tree-ssa-reassoc.c (reassociate_bb): Pass true as last argument to rewrite_expr_tree even if negate_result, move new_lhs var declaration and initialization earlier, for powi_result set afterwards new_lhs to lhs. For negate_result, use new_lhs instead of tmp if new_lhs != lhs, and don't shadow gsi var. * gcc.c-torture/execute/pr71631.c: New test. From-SVN: r237782
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr71631.c32
-rw-r--r--gcc/tree-ssa-reassoc.c13
4 files changed, 55 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 48a2291..b4d4b0b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2016-06-25 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/71631
+ * tree-ssa-reassoc.c (reassociate_bb): Pass true as last argument
+ to rewrite_expr_tree even if negate_result, move new_lhs var
+ declaration and initialization earlier, for powi_result set afterwards
+ new_lhs to lhs. For negate_result, use new_lhs instead of tmp
+ if new_lhs != lhs, and don't shadow gsi var.
+
2016-06-24 Jan Hubicka <hubicka@ucw.cz>
* predict.c (predict_paths_leading_to, predict_paths_leading_to_edge):
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4a10bf4..105f81f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-06-25 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/71631
+ * gcc.c-torture/execute/pr71631.c: New test.
+
2016-06-24 Jan Hubicka <hubicka@ucw.cz>
* gcc.dg/predict-11.c: New testcase.
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr71631.c b/gcc/testsuite/gcc.c-torture/execute/pr71631.c
new file mode 100644
index 0000000..f27c03e
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr71631.c
@@ -0,0 +1,32 @@
+/* PR tree-optimization/71631 */
+
+volatile char v;
+int a = 1, b = 1, c = 1;
+
+void
+foo (const char *s)
+{
+ while (*s++)
+ v = *s;
+}
+
+int
+main ()
+{
+ volatile int d = 1;
+ volatile int e = 1;
+ int f = 1 / a;
+ int g = 1U < f;
+ int h = 2 + g;
+ int i = 3 % h;
+ int j = e && b;
+ int k = 1 == c;
+ int l = d != 0;
+ short m = (short) (-1 * i * l);
+ short x = j * (k * m);
+ if (i == 1)
+ foo ("AB");
+ if (x != -1)
+ __builtin_abort ();
+ return 0;
+}
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index cdfe06f..9264e0b 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -5314,6 +5314,7 @@ reassociate_bb (basic_block bb)
}
}
+ tree new_lhs = lhs;
/* If the operand vector is now empty, all operands were
consumed by the __builtin_powi optimization. */
if (ops.length () == 0)
@@ -5337,7 +5338,6 @@ reassociate_bb (basic_block bb)
machine_mode mode = TYPE_MODE (TREE_TYPE (lhs));
int ops_num = ops.length ();
int width = get_reassociation_width (ops_num, rhs_code, mode);
- tree new_lhs = lhs;
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file,
@@ -5357,7 +5357,8 @@ reassociate_bb (basic_block bb)
swap_ops_for_binary_stmt (ops, len - 3, stmt);
new_lhs = rewrite_expr_tree (stmt, 0, ops,
- powi_result != NULL);
+ powi_result != NULL
+ || negate_result);
}
/* If we combined some repeated factors into a
@@ -5372,7 +5373,10 @@ reassociate_bb (basic_block bb)
gimple_set_lhs (lhs_stmt, target_ssa);
update_stmt (lhs_stmt);
if (lhs != new_lhs)
- target_ssa = new_lhs;
+ {
+ target_ssa = new_lhs;
+ new_lhs = lhs;
+ }
mul_stmt = gimple_build_assign (lhs, MULT_EXPR,
powi_result, target_ssa);
gimple_set_location (mul_stmt, gimple_location (stmt));
@@ -5386,10 +5390,11 @@ reassociate_bb (basic_block bb)
stmt = SSA_NAME_DEF_STMT (lhs);
tree tmp = make_ssa_name (TREE_TYPE (lhs));
gimple_set_lhs (stmt, tmp);
+ if (lhs != new_lhs)
+ tmp = new_lhs;
gassign *neg_stmt = gimple_build_assign (lhs, NEGATE_EXPR,
tmp);
gimple_set_uid (neg_stmt, gimple_uid (stmt));
- gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
gsi_insert_after (&gsi, neg_stmt, GSI_NEW_STMT);
update_stmt (stmt);
}