aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-threadedge.c
diff options
context:
space:
mode:
authorJeff Law <law@redhat.com>2015-10-12 21:39:35 +0000
committerJeff Law <law@redhat.com>2015-10-12 21:39:35 +0000
commitc02fa571511982e9666600c9e893a1483c7ebd33 (patch)
tree175480cddd480785cb6eb725aa212724d5416228 /gcc/tree-ssa-threadedge.c
parent2926a09a8886949e4b6844d49dc6c948fef5d4d5 (diff)
[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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@228739 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-threadedge.c')
-rw-r--r--gcc/tree-ssa-threadedge.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 5ca945864e7..da2fb1fde46 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. */