From bf1cbdc6e43e3a62ef6ecac786ac70ecf5851ef6 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Thu, 2 Apr 2009 09:10:53 +0000 Subject: [PATCH] re PR middle-end/37221 (Missed early loop-unroll optimization - causes 40% degradation on SPU) 2009-04-02 Richard Guenther PR tree-optimization/37221 * tree-flow.h (degenerate_phi_result): Declare. * tree-ssa-dom.c (degenerate_phi_result): Export. * tree-scalar-evolution.c (analyze_initial_condition): If the initial condition is defined by a degenerate PHI node use the degenerate value. * gcc.c-torture/compile/20090331-1.c: New testcase. From-SVN: r145439 --- gcc/ChangeLog | 9 +++++++ gcc/testsuite/ChangeLog | 5 ++++ .../gcc.c-torture/compile/20090331-1.c | 26 +++++++++++++++++++ gcc/tree-flow.h | 1 + gcc/tree-scalar-evolution.c | 14 ++++++++++ gcc/tree-ssa-dom.c | 2 +- 6 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/20090331-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b3b7d78dc80..8305ab11a55 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2009-04-02 Richard Guenther + + PR tree-optimization/37221 + * tree-flow.h (degenerate_phi_result): Declare. + * tree-ssa-dom.c (degenerate_phi_result): Export. + * tree-scalar-evolution.c (analyze_initial_condition): If + the initial condition is defined by a degenerate PHI node + use the degenerate value. + 2009-04-01 Eric Botcazou PR rtl-optimization/39588 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b61f69a82cd..48b2e9d3f65 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-04-02 Richard Guenther + + PR tree-optimization/37221 + * gcc.c-torture/compile/20090331-1.c: New testcase. + 2009-04-01 Eric Botcazou * gcc.c-torture/compile/20090401-1.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/compile/20090331-1.c b/gcc/testsuite/gcc.c-torture/compile/20090331-1.c new file mode 100644 index 00000000000..2db2ee72ecb --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20090331-1.c @@ -0,0 +1,26 @@ +struct re_pattern_buffer { + unsigned char *buffer; + unsigned long int allocated; +}; +void byte_regex_compile (struct re_pattern_buffer *bufp, + unsigned char *begalt, unsigned char *b) +{ + unsigned char *pfrom; + unsigned char *pto; + + while ((unsigned long) (b - bufp->buffer + 3) > bufp->allocated) + { + unsigned char *old_buffer = bufp->buffer; + bufp->allocated <<= 1; + if (old_buffer != bufp->buffer) + { + int incr = bufp->buffer - old_buffer; + b += incr; + } + } + pfrom = b; + pto = b + 3; + while (pfrom != begalt) + *--pto = *--pfrom; +} + diff --git a/gcc/tree-flow.h b/gcc/tree-flow.h index 07fb9be31e8..868b762a85c 100644 --- a/gcc/tree-flow.h +++ b/gcc/tree-flow.h @@ -919,6 +919,7 @@ bool simplify_stmt_using_ranges (gimple_stmt_iterator *); extern void dump_dominator_optimization_stats (FILE *); extern void debug_dominator_optimization_stats (void); int loop_depth_of_name (tree); +tree degenerate_phi_result (gimple); /* In tree-ssa-copy.c */ extern void merge_alias_info (tree, tree); diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c index 8e12c2b32ab..af959b75a3d 100644 --- a/gcc/tree-scalar-evolution.c +++ b/gcc/tree-scalar-evolution.c @@ -1577,6 +1577,20 @@ analyze_initial_condition (gimple loop_phi_node) if (init_cond == chrec_not_analyzed_yet) init_cond = chrec_dont_know; + /* During early loop unrolling we do not have fully constant propagated IL. + Handle degenerate PHIs here to not miss important unrollings. */ + if (TREE_CODE (init_cond) == SSA_NAME) + { + gimple def = SSA_NAME_DEF_STMT (init_cond); + tree res; + if (gimple_code (def) == GIMPLE_PHI + && (res = degenerate_phi_result (def)) != NULL_TREE + /* Only allow invariants here, otherwise we may break + loop-closed SSA form. */ + && is_gimple_min_invariant (res)) + init_cond = res; + } + if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, " (init_cond = "); diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 6d6d02bc305..c252a7257c4 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -2475,7 +2475,7 @@ avail_expr_eq (const void *p1, const void *p2) /* Given PHI, return its RHS if the PHI is a degenerate, otherwise return NULL. */ -static tree +tree degenerate_phi_result (gimple phi) { tree lhs = gimple_phi_result (phi);