diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-07-27 10:49:16 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-07-27 10:49:16 +0200 |
commit | 7d25ac209de8262e39e5551585da5094a4c5c317 (patch) | |
tree | 59aeb2fb78941197a712558842d5f67b1da78303 /gcc | |
parent | 036ea39917b0ef6f07a7c3c3c06002c73fd238f5 (diff) | |
download | gcc-7d25ac209de8262e39e5551585da5094a4c5c317.zip gcc-7d25ac209de8262e39e5551585da5094a4c5c317.tar.gz gcc-7d25ac209de8262e39e5551585da5094a4c5c317.tar.bz2 |
re PR tree-optimization/81555 (Wrong code at -O1)
PR tree-optimization/81555
PR tree-optimization/81556
* tree-ssa-reassoc.c (rewrite_expr_tree): Add NEXT_CHANGED argument,
if true, force CHANGED for the recursive invocation.
(reassociate_bb): Remember original length of ops array, pass
len != orig_len as NEXT_CHANGED in rewrite_expr_tree call.
* gcc.c-torture/execute/pr81555.c: New test.
* gcc.c-torture/execute/pr81556.c: New test.
From-SVN: r250609
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/pr81555.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/pr81556.c | 23 | ||||
-rw-r--r-- | gcc/tree-ssa-reassoc.c | 15 |
5 files changed, 70 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 89180b7..345034d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,12 @@ 2017-07-27 Jakub Jelinek <jakub@redhat.com> + PR tree-optimization/81555 + PR tree-optimization/81556 + * tree-ssa-reassoc.c (rewrite_expr_tree): Add NEXT_CHANGED argument, + if true, force CHANGED for the recursive invocation. + (reassociate_bb): Remember original length of ops array, pass + len != orig_len as NEXT_CHANGED in rewrite_expr_tree call. + * attribs.c (decl_attributes): Imply noinline, noclone and no_icf attributes for noipa attribute. For naked attribute use lookup_attribute first before lookup_attribute_spec. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 532870c..fd606e0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2017-07-27 Jakub Jelinek <jakub@redhat.com> + PR tree-optimization/81555 + PR tree-optimization/81556 + * gcc.c-torture/execute/pr81555.c: New test. + * gcc.c-torture/execute/pr81556.c: New test. + * gcc.dg/attr-noipa.c: New test. * gcc.dg/ipa/ipa-pta-18.c: New test. * gcc.dg/ipa/ipa-sra-11.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr81555.c b/gcc/testsuite/gcc.c-torture/execute/pr81555.c new file mode 100644 index 0000000..d546368 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr81555.c @@ -0,0 +1,24 @@ +/* PR tree-optimization/81555 */ + +unsigned int a = 1, d = 0xfaeU, e = 0xe376U; +_Bool b = 0, f = 1; +unsigned char g = 1; + +void +foo (void) +{ + _Bool c = a != b; + if (c) + f = 0; + if (e & c & (unsigned char)d & c) + g = 0; +} + +int +main () +{ + foo (); + if (f || g != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr81556.c b/gcc/testsuite/gcc.c-torture/execute/pr81556.c new file mode 100644 index 0000000..cfbc75f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr81556.c @@ -0,0 +1,23 @@ +/* PR tree-optimization/81556 */ + +unsigned long long int b = 0xb82ff73c5c020599ULL; +unsigned long long int c = 0xd4e8188733a29d8eULL; +unsigned long long int d = 2, f = 1, g = 0, h = 0; +unsigned long long int e = 0xf27771784749f32bULL; + +__attribute__((noinline, noclone)) void +foo (void) +{ + _Bool a = d > 1; + g = f % ((d > 1) << 9); + h = a & (e & (a & b & c)); +} + +int +main () +{ + foo (); + if (g != 1 || h != 0) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 2f49ba1..7c3007f 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -4205,11 +4205,15 @@ insert_stmt_before_use (gimple *stmt, gimple *stmt_to_insert) /* Recursively rewrite our linearized statements so that the operators match those in OPS[OPINDEX], putting the computation in rank - order. Return new lhs. */ + order. Return new lhs. + CHANGED is true if we shouldn't reuse the lhs SSA_NAME both in + the current stmt and during recursive invocations. + NEXT_CHANGED is true if we shouldn't reuse the lhs SSA_NAME in + recursive invocations. */ static tree rewrite_expr_tree (gimple *stmt, unsigned int opindex, - vec<operand_entry *> ops, bool changed) + vec<operand_entry *> ops, bool changed, bool next_changed) { tree rhs1 = gimple_assign_rhs1 (stmt); tree rhs2 = gimple_assign_rhs2 (stmt); @@ -4300,7 +4304,8 @@ rewrite_expr_tree (gimple *stmt, unsigned int opindex, be the non-leaf side. */ tree new_rhs1 = rewrite_expr_tree (SSA_NAME_DEF_STMT (rhs1), opindex + 1, ops, - changed || oe->op != rhs2); + changed || oe->op != rhs2 || next_changed, + false); if (oe->op != rhs2 || new_rhs1 != rhs1) { @@ -5654,6 +5659,7 @@ reassociate_bb (basic_block bb) gimple_set_visited (stmt, true); linearize_expr_tree (&ops, stmt, true, true); ops.qsort (sort_by_operand_rank); + int orig_len = ops.length (); optimize_ops_list (rhs_code, &ops); if (undistribute_ops_list (rhs_code, &ops, loop_containing_stmt (stmt))) @@ -5744,7 +5750,8 @@ reassociate_bb (basic_block bb) new_lhs = rewrite_expr_tree (stmt, 0, ops, powi_result != NULL - || negate_result); + || negate_result, + len != orig_len); } /* If we combined some repeated factors into a |