From 6987b50fcccc174f2854870353ee337f111e1ac4 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 3 May 2017 11:22:34 +0000 Subject: [PATCH] backport: [multiple changes] 2017-05-03 Richard Biener Backport from mainline 2017-04-20 Richard Biener PR tree-optimization/80453 * tree-ssa-sccvn.h (struct vn_phi_s): Add cclhs and ccrhs members. * tree-ssa-sccvn.c (cond_stmts_equal_p): Use recorded lhs and rhs from the conditions. (vn_phi_eq): Pass them down. (vn_phi_lookup): Record them. (vn_phi_insert): Likewise. 2017-04-25 Richard Biener PR tree-optimization/80492 * alias.c (compare_base_decls): Handle registers with asm specification conservatively. * gcc.dg/pr80492.c: New testcase. 2017-04-27 Richard Biener PR middle-end/80539 * tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not being in loop-closed SSA form conservatively. (chrec_fold_multiply_poly_poly): Likewise. * gcc.dg/torture/pr80539.c: New testcase. From-SVN: r247545 --- gcc/ChangeLog | 26 +++++++++++++++++++ gcc/alias.c | 12 +++++++++ gcc/testsuite/ChangeLog | 13 ++++++++++ gcc/testsuite/gcc.dg/pr80492.c | 20 ++++++++++++++ gcc/testsuite/gcc.dg/torture/pr80539.c | 22 ++++++++++++++++ gcc/tree-chrec.c | 14 ++++++++-- gcc/tree-ssa-sccvn.c | 36 +++++++++++++++++++------- gcc/tree-ssa-sccvn.h | 3 +++ 8 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr80492.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr80539.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8faa790e7e4..9ab83758041 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,29 @@ +2017-05-03 Richard Biener + + Backport from mainline + 2017-04-20 Richard Biener + + PR tree-optimization/80453 + * tree-ssa-sccvn.h (struct vn_phi_s): Add cclhs and ccrhs members. + * tree-ssa-sccvn.c (cond_stmts_equal_p): Use recorded lhs and rhs + from the conditions. + (vn_phi_eq): Pass them down. + (vn_phi_lookup): Record them. + (vn_phi_insert): Likewise. + + 2017-04-25 Richard Biener + + PR tree-optimization/80492 + * alias.c (compare_base_decls): Handle registers with asm + specification conservatively. + + 2017-04-27 Richard Biener + + PR middle-end/80539 + * tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not + being in loop-closed SSA form conservatively. + (chrec_fold_multiply_poly_poly): Likewise. + 2017-05-02 Uros Bizjak Backport from mainline diff --git a/gcc/alias.c b/gcc/alias.c index efd89ce1679..e16e3501522 100644 --- a/gcc/alias.c +++ b/gcc/alias.c @@ -2046,6 +2046,18 @@ compare_base_decls (tree base1, tree base2) if (base1 == base2) return 1; + /* If we have two register decls with register specification we + cannot decide unless their assembler name is the same. */ + if (DECL_REGISTER (base1) + && DECL_REGISTER (base2) + && DECL_ASSEMBLER_NAME_SET_P (base1) + && DECL_ASSEMBLER_NAME_SET_P (base2)) + { + if (DECL_ASSEMBLER_NAME (base1) == DECL_ASSEMBLER_NAME (base2)) + return 1; + return -1; + } + /* Declarations of non-automatic variables may have aliases. All other decls are unique. */ if (!decl_in_symtab_p (base1) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fb64261976a..9382179ebd3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2017-05-03 Richard Biener + + Backport from mainline + 2017-04-25 Richard Biener + + PR tree-optimization/80492 + * gcc.dg/pr80492.c: New testcase. + + 2017-04-27 Richard Biener + + PR middle-end/80539 + * gcc.dg/torture/pr80539.c: New testcase. + 2017-05-03 Jakub Jelinek Backported from mainline diff --git a/gcc/testsuite/gcc.dg/pr80492.c b/gcc/testsuite/gcc.dg/pr80492.c new file mode 100644 index 00000000000..1721b2dee39 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr80492.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-w -O2 -fdump-tree-optimized" } */ + +static __inline__ __attribute__((__always_inline__)) +void syscall_7 (int val) +{ + register int reg __asm ("4") = val; + __asm __volatile__ ("/* Some Code %0 */" :: "r" (reg)); +} + +void do_syscalls (void) +{ + for (int s = 0; s < 2; s++) + { + syscall_7 (0); + syscall_7 (1); + } +} + +/* { dg-final { scan-tree-dump-times "reg = " 4 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/pr80539.c b/gcc/testsuite/gcc.dg/torture/pr80539.c new file mode 100644 index 00000000000..a66767814d3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr80539.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ + +signed char a, b; +void fn1() +{ + signed char c, e; + short d; + if (0) { + for (; d;) { +l1: + for (c = 7; a; c++) + ; + e = 6; + for (; b; e++) + ; + } + c -= e; + } + if (d == 7) + goto l1; + a = c; +} diff --git a/gcc/tree-chrec.c b/gcc/tree-chrec.c index 80a1bbd2327..28c08e7115c 100644 --- a/gcc/tree-chrec.c +++ b/gcc/tree-chrec.c @@ -149,7 +149,12 @@ chrec_fold_plus_poly_poly (enum tree_code code, /* This function should never be called for chrecs of loops that do not belong to the same loop nest. */ - gcc_assert (loop0 == loop1); + if (loop0 != loop1) + { + /* It still can happen if we are not in loop-closed SSA form. */ + gcc_assert (! loops_state_satisfies_p (LOOP_CLOSED_SSA)); + return chrec_dont_know; + } if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR) { @@ -211,7 +216,12 @@ chrec_fold_multiply_poly_poly (tree type, chrec_fold_multiply (type, CHREC_LEFT (poly0), poly1), CHREC_RIGHT (poly0)); - gcc_assert (loop0 == loop1); + if (loop0 != loop1) + { + /* It still can happen if we are not in loop-closed SSA form. */ + gcc_assert (! loops_state_satisfies_p (LOOP_CLOSED_SSA)); + return chrec_dont_know; + } /* poly0 and poly1 are two polynomials in the same variable, {a, +, b}_x * {c, +, d}_x -> {a*c, +, a*d + b*c + b*d, +, 2*b*d}_x. */ diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index bce247a1489..36386cf3e60 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -2916,14 +2916,11 @@ vn_phi_compute_hash (vn_phi_t vp1) the other. */ static bool -cond_stmts_equal_p (gcond *cond1, gcond *cond2, bool *inverted_p) +cond_stmts_equal_p (gcond *cond1, tree lhs1, tree rhs1, + gcond *cond2, tree lhs2, tree rhs2, bool *inverted_p) { enum tree_code code1 = gimple_cond_code (cond1); enum tree_code code2 = gimple_cond_code (cond2); - tree lhs1 = gimple_cond_lhs (cond1); - tree lhs2 = gimple_cond_lhs (cond2); - tree rhs1 = gimple_cond_rhs (cond1); - tree rhs2 = gimple_cond_rhs (cond2); *inverted_p = false; if (code1 == code2) @@ -2941,10 +2938,6 @@ cond_stmts_equal_p (gcond *cond1, gcond *cond2, bool *inverted_p) else return false; - lhs1 = vn_valueize (lhs1); - rhs1 = vn_valueize (rhs1); - lhs2 = vn_valueize (lhs2); - rhs2 = vn_valueize (rhs2); return ((expressions_equal_p (lhs1, lhs2) && expressions_equal_p (rhs1, rhs2)) || (commutative_tree_code (code1) @@ -3002,7 +2995,10 @@ vn_phi_eq (const_vn_phi_t const vp1, const_vn_phi_t const vp2) return false; bool inverted_p; if (! cond_stmts_equal_p (as_a (last1), - as_a (last2), &inverted_p)) + vp1->cclhs, vp1->ccrhs, + as_a (last2), + vp2->cclhs, vp2->ccrhs, + &inverted_p)) return false; /* Get at true/false controlled edges into the PHI. */ @@ -3081,6 +3077,16 @@ vn_phi_lookup (gimple *phi) vp1.type = TREE_TYPE (gimple_phi_result (phi)); vp1.phiargs = shared_lookup_phiargs; vp1.block = gimple_bb (phi); + /* Extract values of the controlling condition. */ + vp1.cclhs = NULL_TREE; + vp1.ccrhs = NULL_TREE; + basic_block idom1 = get_immediate_dominator (CDI_DOMINATORS, vp1.block); + if (EDGE_COUNT (idom1->succs) == 2) + if (gcond *last1 = dyn_cast (last_stmt (idom1))) + { + vp1.cclhs = vn_valueize (gimple_cond_lhs (last1)); + vp1.ccrhs = vn_valueize (gimple_cond_rhs (last1)); + } vp1.hashcode = vn_phi_compute_hash (&vp1); slot = current_info->phis->find_slot_with_hash (&vp1, vp1.hashcode, NO_INSERT); @@ -3117,6 +3123,16 @@ vn_phi_insert (gimple *phi, tree result) vp1->type = TREE_TYPE (gimple_phi_result (phi)); vp1->phiargs = args; vp1->block = gimple_bb (phi); + /* Extract values of the controlling condition. */ + vp1->cclhs = NULL_TREE; + vp1->ccrhs = NULL_TREE; + basic_block idom1 = get_immediate_dominator (CDI_DOMINATORS, vp1->block); + if (EDGE_COUNT (idom1->succs) == 2) + if (gcond *last1 = dyn_cast (last_stmt (idom1))) + { + vp1->cclhs = vn_valueize (gimple_cond_lhs (last1)); + vp1->ccrhs = vn_valueize (gimple_cond_rhs (last1)); + } vp1->result = result; vp1->hashcode = vn_phi_compute_hash (vp1); diff --git a/gcc/tree-ssa-sccvn.h b/gcc/tree-ssa-sccvn.h index 4e63ad746c6..ec00c37cca2 100644 --- a/gcc/tree-ssa-sccvn.h +++ b/gcc/tree-ssa-sccvn.h @@ -67,6 +67,9 @@ typedef struct vn_phi_s hashval_t hashcode; vec phiargs; basic_block block; + /* Controlling condition lhs/rhs. */ + tree cclhs; + tree ccrhs; tree type; tree result; } *vn_phi_t;