diff options
author | Jeff Law <law@redhat.com> | 2015-10-12 15:39:35 -0600 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2015-10-12 15:39:35 -0600 |
commit | 3d466672b1290916bfc75f191787bc7459479ca3 (patch) | |
tree | 175480cddd480785cb6eb725aa212724d5416228 /gcc/tree-ssa-threadedge.c | |
parent | 058a654b30b40d19db1306daa38df363b9bf8a56 (diff) | |
download | gcc-3d466672b1290916bfc75f191787bc7459479ca3.zip gcc-3d466672b1290916bfc75f191787bc7459479ca3.tar.gz gcc-3d466672b1290916bfc75f191787bc7459479ca3.tar.bz2 |
[PATCH] Allow FSM threader to thread more complex conditions
* tree-ssa-threadbackward.c (get_gimple_control_stmt): New function.
(fsm_find_control_stmt_paths): Change name of first argument to
more accurately relfect what it really is. Handle simplification
of GIMPLE_COND after finding a thread path for NAME.
* tree-ssa-threadedge.c (simplify_control_stmt_condition): Allow
nontrivial conditions to be handled by FSM threader.
(thread_through_normal_block): Extract the name to looup via
FSM threader from COND_EXPR.
* gcc.dg/tree-ssa/ssa-thread-12.c: New test.
* gcc.dg/tree-ssa/ssa-dom-thread-7.c: Update expected output.
* gcc.dg/tree-ssa/ssa-thread-11.c: Renamed from
ssa-dom-thread-11.c.
From-SVN: r228739
Diffstat (limited to 'gcc/tree-ssa-threadedge.c')
-rw-r--r-- | gcc/tree-ssa-threadedge.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c index 5ca9458..da2fb1f 100644 --- a/gcc/tree-ssa-threadedge.c +++ b/gcc/tree-ssa-threadedge.c @@ -551,11 +551,13 @@ simplify_control_stmt_condition (edge e, || !is_gimple_min_invariant (cached_lhs)) cached_lhs = (*simplify) (dummy_cond, stmt, avail_exprs_stack); - /* If we were just testing that an integral type was != 0, and that - failed, just return the first operand. This gives the FSM code a - chance to optimize the path. */ - if (cached_lhs == NULL - && cond_code == NE_EXPR) + /* If we were testing an integer/pointer against a constant, then + we can use the FSM code to trace the value of the SSA_NAME. If + a value is found, then the condition will collapse to a constant. + + Return the SSA_NAME we want to trace back rather than the full + expression and give the FSM threader a chance to find its value. */ + if (cached_lhs == NULL) { /* Recover the original operands. They may have been simplified using context sensitive equivalences. Those context sensitive @@ -563,9 +565,10 @@ simplify_control_stmt_condition (edge e, tree op0 = gimple_cond_lhs (stmt); tree op1 = gimple_cond_rhs (stmt); - if (INTEGRAL_TYPE_P (TREE_TYPE (op0)) + if ((INTEGRAL_TYPE_P (TREE_TYPE (op0)) + || POINTER_TYPE_P (TREE_TYPE (op0))) && TREE_CODE (op0) == SSA_NAME - && integer_zerop (op1)) + && TREE_CODE (op1) == INTEGER_CST) return op0; } @@ -1046,11 +1049,19 @@ thread_through_normal_block (edge e, if (!flag_expensive_optimizations || optimize_function_for_size_p (cfun) - || TREE_CODE (cond) != SSA_NAME + || !(TREE_CODE (cond) == SSA_NAME + || (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison + && TREE_CODE (TREE_OPERAND (cond, 0)) == SSA_NAME + && TREE_CODE (TREE_OPERAND (cond, 1)) == INTEGER_CST)) || e->dest->loop_father != e->src->loop_father || loop_depth (e->dest->loop_father) == 0) return 0; + /* Extract the SSA_NAME we want to trace backwards if COND is not + already a bare SSA_NAME. */ + if (TREE_CODE (cond) != SSA_NAME) + cond = TREE_OPERAND (cond, 0); + /* When COND cannot be simplified, try to find paths from a control statement back through the PHI nodes which would affect that control statement. */ |