Commit e944354e by Robin Dapp Committed by Robin Dapp

[PATCH 1/2] Allow folding all statements.

This patch allows users of the substitute_and_fold_engine to
enable folding all statements.  It is now enabled for VRP which
is needed for the match.pd pattern in patch 2/2.

The loop versioning pass was missing one case when
deconstructing addresses that would only be triggered after
this patch for me:
It could handle addition and subsequent convert/nop but not
a convert/nop directly.  This would cause the hash to be
calculated differently and, in turn, cause the pass to miss
a versioning opportunity.  Fixed this by adding the missing
case.

--

gcc/ChangeLog:

2019-08-26  Robin Dapp  <rdapp@linux.ibm.com>

        * gimple-loop-versioning.cc (loop_versioning::record_address_fragment):
        Add nop_convert case.
        * tree-ssa-propagate.c (substitute_and_fold_dom_walker::before_dom_children):
        Fold all statements if requested.
        * tree-ssa-propagate.h (class substitute_and_fold_engine):
        Allow to fold all statements.
        * tree-vrp.c (class vrp_folder):
        Let substitute_and_fold_engine fold all statements.

From-SVN: r274923
parent bf05a3bb
2019-08-26 Robin Dapp <rdapp@linux.ibm.com>
* gimple-loop-versioning.cc (loop_versioning::record_address_fragment):
Add nop_convert case.
* tree-ssa-propagate.c (substitute_and_fold_dom_walker::before_dom_children):
Fold all statements if requested.
* tree-ssa-propagate.h (class substitute_and_fold_engine):
Allow to fold all statements.
* tree-vrp.c (class vrp_folder):
Let substitute_and_fold_engine fold all statements.
2019-08-26 Richard Biener <rguenther@suse.de> 2019-08-26 Richard Biener <rguenther@suse.de>
PR tree-optimization/91526 PR tree-optimization/91526
......
...@@ -1266,6 +1266,12 @@ loop_versioning::record_address_fragment (gimple *stmt, ...@@ -1266,6 +1266,12 @@ loop_versioning::record_address_fragment (gimple *stmt,
continue; continue;
} }
} }
if (CONVERT_EXPR_CODE_P (code))
{
tree op1 = gimple_assign_rhs1 (assign);
address->terms[i].expr = strip_casts (op1);
continue;
}
} }
i += 1; i += 1;
} }
......
...@@ -814,7 +814,6 @@ ssa_propagation_engine::ssa_propagate (void) ...@@ -814,7 +814,6 @@ ssa_propagation_engine::ssa_propagate (void)
ssa_prop_fini (); ssa_prop_fini ();
} }
/* Return true if STMT is of the form 'mem_ref = RHS', where 'mem_ref' /* Return true if STMT is of the form 'mem_ref = RHS', where 'mem_ref'
is a non-volatile pointer dereference, a structure reference or a is a non-volatile pointer dereference, a structure reference or a
reference to a single _DECL. Ignore volatile memory references reference to a single _DECL. Ignore volatile memory references
...@@ -1071,6 +1070,14 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb) ...@@ -1071,6 +1070,14 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb)
stmt = gsi_stmt (i); stmt = gsi_stmt (i);
gimple_set_modified (stmt, true); gimple_set_modified (stmt, true);
} }
/* Also fold if we want to fold all statements. */
else if (substitute_and_fold_engine->fold_all_stmts
&& fold_stmt (&i, follow_single_use_edges))
{
did_replace = true;
stmt = gsi_stmt (i);
gimple_set_modified (stmt, true);
}
/* Some statements may be simplified using propagator /* Some statements may be simplified using propagator
specific information. Do this before propagating specific information. Do this before propagating
......
...@@ -100,6 +100,8 @@ class ssa_propagation_engine ...@@ -100,6 +100,8 @@ class ssa_propagation_engine
class substitute_and_fold_engine class substitute_and_fold_engine
{ {
public: public:
substitute_and_fold_engine (bool fold_all_stmts = false)
: fold_all_stmts (fold_all_stmts) { }
virtual ~substitute_and_fold_engine (void) { } virtual ~substitute_and_fold_engine (void) { }
virtual bool fold_stmt (gimple_stmt_iterator *) { return false; } virtual bool fold_stmt (gimple_stmt_iterator *) { return false; }
virtual tree get_value (tree) { return NULL_TREE; } virtual tree get_value (tree) { return NULL_TREE; }
...@@ -107,6 +109,10 @@ class substitute_and_fold_engine ...@@ -107,6 +109,10 @@ class substitute_and_fold_engine
bool substitute_and_fold (basic_block = NULL); bool substitute_and_fold (basic_block = NULL);
bool replace_uses_in (gimple *); bool replace_uses_in (gimple *);
bool replace_phi_args_in (gphi *); bool replace_phi_args_in (gphi *);
/* Users like VRP can set this when they want to perform
folding for every propagation. */
bool fold_all_stmts;
}; };
#endif /* _TREE_SSA_PROPAGATE_H */ #endif /* _TREE_SSA_PROPAGATE_H */
...@@ -6415,6 +6415,7 @@ vrp_prop::visit_phi (gphi *phi) ...@@ -6415,6 +6415,7 @@ vrp_prop::visit_phi (gphi *phi)
class vrp_folder : public substitute_and_fold_engine class vrp_folder : public substitute_and_fold_engine
{ {
public: public:
vrp_folder () : substitute_and_fold_engine (/* Fold all stmts. */ true) { }
tree get_value (tree) FINAL OVERRIDE; tree get_value (tree) FINAL OVERRIDE;
bool fold_stmt (gimple_stmt_iterator *) FINAL OVERRIDE; bool fold_stmt (gimple_stmt_iterator *) FINAL OVERRIDE;
bool fold_predicate_in (gimple_stmt_iterator *); bool fold_predicate_in (gimple_stmt_iterator *);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment