From 1ef33ef304cedbeca446e79d677cd18036a5dc66 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 12 May 2016 13:46:26 +0000 Subject: [PATCH] re PR tree-optimization/71059 (gcc ICE at -O3 on valid code on x86_64-linux-gnu in "vn_nary_op_insert_into") 2016-05-12 Richard Biener PR tree-optimization/71059 * tree-ssa-pre.c (phi_translate_1): Fully fold translated nary before looking up or entering the expression into the VN hashes. * tree-ssa-sccvn.c (vn_nary_build_or_lookup): Fix comment typo. Make sure to re-use NARYs without result as inserted by phi-translation. * gcc.dg/torture/pr71059.c: New testcase. From-SVN: r236175 --- gcc/ChangeLog | 10 ++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr71059.c | 15 +++++++++++++++ gcc/tree-ssa-pre.c | 13 ++++++------- gcc/tree-ssa-sccvn.c | 14 ++++++++++++-- 5 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr71059.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ddea24baf0d..4edaf4ba2a4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2016-05-12 Richard Biener + + PR tree-optimization/71059 + * tree-ssa-pre.c (phi_translate_1): Fully fold translated + nary before looking up or entering the expression into the VN + hashes. + * tree-ssa-sccvn.c (vn_nary_build_or_lookup): Fix comment typo. + Make sure to re-use NARYs without result as inserted by + phi-translation. + 2016-05-12 Richard Biener PR tree-optimization/71062 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6dca22fd182..5ecb1a331e5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-12 Richard Biener + + PR tree-optimization/71059 + * gcc.dg/torture/pr71059.c: New testcase. + 2016-05-12 Richard Biener PR tree-optimization/71062 diff --git a/gcc/testsuite/gcc.dg/torture/pr71059.c b/gcc/testsuite/gcc.dg/torture/pr71059.c new file mode 100644 index 00000000000..7c0ab7f1493 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr71059.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +short a, c; +union { + unsigned f0; + unsigned short f1; +} b; +volatile int d; +short fn1(short p1) { return p1 + a; } +void fn2() +{ + b.f0 = 0; + for (;; b.f0 = fn1(b.f0)) + (c && b.f1) || d; +} diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index 4a771d3b0be..3ce87d9d23f 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -1464,6 +1464,12 @@ phi_translate_1 (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, pre_expr constant; unsigned int new_val_id; + PRE_EXPR_NARY (expr) = newnary; + constant = fully_constant_expression (expr); + PRE_EXPR_NARY (expr) = nary; + if (constant != expr) + return constant; + tree result = vn_nary_op_lookup_pieces (newnary->length, newnary->opcode, newnary->type, @@ -1478,10 +1484,6 @@ phi_translate_1 (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, if (nary) { PRE_EXPR_NARY (expr) = nary; - constant = fully_constant_expression (expr); - if (constant != expr) - return constant; - new_val_id = nary->value_id; get_or_alloc_expression_id (expr); } @@ -1495,9 +1497,6 @@ phi_translate_1 (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, &newnary->op[0], result, new_val_id); PRE_EXPR_NARY (expr) = nary; - constant = fully_constant_expression (expr); - if (constant != expr) - return constant; get_or_alloc_expression_id (expr); } add_to_value (new_val_id, expr); diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 1567fb96afb..730db04ff8b 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1632,7 +1632,7 @@ vn_nary_build_or_lookup (code_helper rcode, tree type, tree *ops) { tree result = NULL_TREE; /* We will be creating a value number for - ROCDE (OPS...). + RCODE (OPS...). So first simplify and lookup this expression to see if it is already available. */ mprts_hook = vn_lookup_simplify_result; @@ -1682,6 +1682,16 @@ vn_nary_build_or_lookup (code_helper rcode, tree type, tree *ops) gimple_seq_add_stmt_without_update (&VN_INFO (result)->expr, new_stmt); VN_INFO (result)->needs_insertion = true; + /* ??? PRE phi-translation inserts NARYs without corresponding + SSA name result. Re-use those but set their result according + to the stmt we just built. */ + vn_nary_op_t nary = NULL; + vn_nary_op_lookup_stmt (new_stmt, &nary); + if (nary) + { + gcc_assert (nary->result == NULL_TREE); + nary->result = gimple_assign_lhs (new_stmt); + } /* As all "inserted" statements are singleton SCCs, insert to the valid table. This is strictly needed to avoid re-generating new value SSA_NAMEs for the same @@ -1689,7 +1699,7 @@ vn_nary_build_or_lookup (code_helper rcode, tree type, tree *ops) optimistic table gets cleared after each iteration). We do not need to insert into the optimistic table, as lookups there will fall back to the valid table. */ - if (current_info == optimistic_info) + else if (current_info == optimistic_info) { current_info = valid_info; vn_nary_op_insert_stmt (new_stmt, result);