From e373dd067e6f29cd333cddd741611f5979718c58 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 12 Aug 2016 12:58:15 +0000 Subject: [PATCH] re PR tree-optimization/57326 (Piecewise folding of operations on PHI nodes) 2016-08-12 Richard Biener PR tree-optimization/57326 * tree-ssa-pre.c (fully_constant_expression): Handle simplification returning an SSA name. (phi_translate_1): When fully_constant_expression returns a NAME make sure we have a leader for it. * gcc.dg/tree-ssa/ssa-pre-32.c: New testcase. * gcc.dg/tree-ssa/loadpre14.c: Adjust. * gcc.dg/tree-ssa/pr35287.c: Likewise. * gcc.target/i386/pr45685.c: Likewise. * gcc.dg/tree-ssa/predcom-1.c: Disable PRE. * gcc.dg/tree-ssa/predcom-2.c: Likewise. * gcc.dg/tree-ssa/predcom-3.c: Likewise. * gcc.dg/tree-ssa/ssa-sink-10.c: Likewise. * gfortran.dg/pr34163.f90: Likewise. From-SVN: r239414 --- gcc/ChangeLog | 8 +++++++ gcc/testsuite/ChangeLog | 13 ++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/loadpre14.c | 5 +++-- gcc/testsuite/gcc.dg/tree-ssa/pr35287.c | 5 +++-- gcc/testsuite/gcc.dg/tree-ssa/predcom-1.c | 8 +++---- gcc/testsuite/gcc.dg/tree-ssa/predcom-2.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/predcom-3.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-32.c | 11 ++++++++++ gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-10.c | 2 +- gcc/testsuite/gcc.target/i386/pr45685.c | 2 +- gcc/testsuite/gfortran.dg/pr34163.f90 | 2 +- gcc/tree-ssa-pre.c | 23 +++++++++++++++------ 12 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-32.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 14f95cf1a92..355f80d20dc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2016-08-12 Richard Biener + + PR tree-optimization/57326 + * tree-ssa-pre.c (fully_constant_expression): Handle simplification + returning an SSA name. + (phi_translate_1): When fully_constant_expression returns a NAME + make sure we have a leader for it. + 2016-08-12 Martin Liska Adam Fineman diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7700cec8b2d..1691c25a767 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2016-08-12 Richard Biener + + PR tree-optimization/57326 + * gcc.dg/tree-ssa/ssa-pre-32.c: New testcase. + * gcc.dg/tree-ssa/loadpre14.c: Adjust. + * gcc.dg/tree-ssa/pr35287.c: Likewise. + * gcc.target/i386/pr45685.c: Likewise. + * gcc.dg/tree-ssa/predcom-1.c: Disable PRE. + * gcc.dg/tree-ssa/predcom-2.c: Likewise. + * gcc.dg/tree-ssa/predcom-3.c: Likewise. + * gcc.dg/tree-ssa/ssa-sink-10.c: Likewise. + * gfortran.dg/pr34163.f90: Likewise. + 2016-08-12 Martin Liska * g++.dg/gcov/gcov-16.C: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/loadpre14.c b/gcc/testsuite/gcc.dg/tree-ssa/loadpre14.c index 989d9332662..456c89f9941 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/loadpre14.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/loadpre14.c @@ -6,7 +6,8 @@ int foo(type *a, int argc) type c = {0, 1}; int d, e; - /* Should be able to eliminate the second load of *a along the main path. */ + /* Should be able to eliminate the second load of *a and the add of zero + along the main path. */ d = (*a)[0]; if (argc) { @@ -15,4 +16,4 @@ int foo(type *a, int argc) e = (*a)[0]; return d + e; } -/* { dg-final { scan-tree-dump-times "Eliminated: 1" 1 "pre"} } */ +/* { dg-final { scan-tree-dump-times "Eliminated: 2" 1 "pre"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr35287.c b/gcc/testsuite/gcc.dg/tree-ssa/pr35287.c index b091ba85cc3..f7cc5c04262 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr35287.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr35287.c @@ -10,5 +10,6 @@ int foo(int p) return (*gp + t); } -/* We will eliminate one load of gp and one indirect load of *gp. */ -/* { dg-final { scan-tree-dump-times "Eliminated: 2" 1 "pre"} } */ +/* We will eliminate one load of gp and one indirect load of *gp and + the add of zero. */ +/* { dg-final { scan-tree-dump-times "Eliminated: 3" 1 "pre"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/predcom-1.c b/gcc/testsuite/gcc.dg/tree-ssa/predcom-1.c index 062b3da71ce..4bc2ea5659b 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/predcom-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/predcom-1.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-do run } */ -/* { dg-options "-O2 -funroll-loops --param max-unroll-times=8 -fpredictive-commoning -fdump-tree-pcom-details" } */ +/* { dg-options "-O2 -funroll-loops --param max-unroll-times=8 -fpredictive-commoning -fdump-tree-pcom-details -fno-tree-pre" } */ void abort (void); @@ -45,6 +45,6 @@ int main(void) /* Verify that both loops were transformed and unrolled. */ /* { dg-final { scan-tree-dump-times "Unrolling 2 times." 2 "pcom"} } */ -/* Also check that we undid the transformation previously made by PRE. */ -/* { dg-final { scan-tree-dump-times "looparound ref" 1 "pcom"} } */ - +/* Also check that we undid the transformation previously made by PRE. + ??? PRE now does the predictive commoning in count_averages. */ +/* dg-final { scan-tree-dump-times "looparound ref" 1 "pcom" } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/predcom-2.c b/gcc/testsuite/gcc.dg/tree-ssa/predcom-2.c index 0d92f8e2307..d8fe51c5a6c 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/predcom-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/predcom-2.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O2 -funroll-loops --param max-unroll-times=8 -fpredictive-commoning -fdump-tree-pcom-details" } */ +/* { dg-options "-O2 -funroll-loops --param max-unroll-times=8 -fpredictive-commoning -fdump-tree-pcom-details -fno-tree-pre" } */ void abort (void); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/predcom-3.c b/gcc/testsuite/gcc.dg/tree-ssa/predcom-3.c index bfddb793e53..1174cd17eec 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/predcom-3.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/predcom-3.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -funroll-loops --param max-unroll-times=8 -fpredictive-commoning -fdump-tree-pcom-details" } */ +/* { dg-options "-O2 -funroll-loops --param max-unroll-times=8 -fpredictive-commoning -fdump-tree-pcom-details -fno-tree-pre" } */ int a[1000], b[1000]; diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-32.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-32.c new file mode 100644 index 00000000000..d9bd3a95755 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-32.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-pre" } */ + +unsigned f(unsigned x, unsigned y, _Bool b) +{ +#define m (b?-1:0) + return (x&m)|(y&~m); +#undef m +} + +/* { dg-final { scan-tree-dump "# prephitmp_\[0-9\]+ = PHI <\[xy\]_\[0-9\]+\\(D\\)\[^,\]*, \[xy\]_\[0-9\]+\\(D\\)" "pre" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-10.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-10.c index 4031e10289d..37e4d2fe687 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-10.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-10.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-sink-details" } */ +/* { dg-options "-O2 -fdump-tree-sink-details -fno-tree-pre" } */ int x[1024], y[1024], z[1024], w[1024]; void foo (void) diff --git a/gcc/testsuite/gcc.target/i386/pr45685.c b/gcc/testsuite/gcc.target/i386/pr45685.c index 93c6686b8cb..f9ed973dd5f 100644 --- a/gcc/testsuite/gcc.target/i386/pr45685.c +++ b/gcc/testsuite/gcc.target/i386/pr45685.c @@ -36,4 +36,4 @@ int summation_helper_2(int64_t* products, uint64_t count) return s; } -/* { dg-final { scan-assembler-times "cmov" 4 } } */ +/* { dg-final { scan-assembler-times "cmov" 6 } } */ diff --git a/gcc/testsuite/gfortran.dg/pr34163.f90 b/gcc/testsuite/gfortran.dg/pr34163.f90 index 1c948961ed9..5ce8d00e4c5 100644 --- a/gcc/testsuite/gfortran.dg/pr34163.f90 +++ b/gcc/testsuite/gfortran.dg/pr34163.f90 @@ -1,5 +1,5 @@ ! { dg-do compile } -! { dg-options "-O2 -fpredictive-commoning -fdump-tree-pcom-details" } +! { dg-options "-O2 -fno-tree-pre -fpredictive-commoning -fdump-tree-pcom-details" } subroutine trisolve2(x,i1,i2,nxyz) integer :: nxyz real,dimension(nxyz):: au1 diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index c2c7495d02d..edc3fdf2a79 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -1201,7 +1201,7 @@ get_or_alloc_expr_for (tree t) } /* Return the folded version of T if T, when folded, is a gimple - min_invariant. Otherwise, return T. */ + min_invariant or an SSA name. Otherwise, return T. */ static pre_expr fully_constant_expression (pre_expr e) @@ -1218,10 +1218,8 @@ fully_constant_expression (pre_expr e) return e; if (is_gimple_min_invariant (res)) return get_or_alloc_expr_for_constant (res); - /* We might have simplified the expression to a - SSA_NAME for example from x_1 * 1. But we cannot - insert a PHI for x_1 unconditionally as x_1 might - not be available readily. */ + if (TREE_CODE (res) == SSA_NAME) + return get_or_alloc_expr_for_name (res); return e; } case REFERENCE: @@ -1464,7 +1462,20 @@ phi_translate_1 (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, constant = fully_constant_expression (expr); PRE_EXPR_NARY (expr) = nary; if (constant != expr) - return constant; + { + /* For non-CONSTANTs we have to make sure we can eventually + insert the expression. Which means we need to have a + leader for it. */ + if (constant->kind != CONSTANT) + { + unsigned value_id = get_expr_value_id (constant); + constant = find_leader_in_sets (value_id, set1, set2); + if (constant) + return constant; + } + else + return constant; + } tree result = vn_nary_op_lookup_pieces (newnary->length, newnary->opcode, -- 2.30.2