Commit c9ef86a1 by Zhenqiang Chen Committed by Jeff Law

tree-ssa-phiopts.c (rhs_is_fed_for_value_replacement): New function.

	* tree-ssa-phiopts.c (rhs_is_fed_for_value_replacement): New function.
	(operand_equal_for_value_replacement): New function, extracted from
	value_replacement and enhanced to catch more cases.
	(value_replacement): Use operand_equal_for_value_replacement.

	* gcc.dg/tree-ssa/phi-opt-11.c: New test.

From-SVN: r203327
parent fd673f29
2013-10-09 Zhenqiang Chen <zhenqiang.chen@arm.com>
* tree-ssa-phiopts.c (rhs_is_fed_for_value_replacement): New function.
(operand_equal_for_value_replacement): New function, extracted from
value_replacement and enhanced to catch more cases.
(value_replacement): Use operand_equal_for_value_replacement.
2013-10-09 Andrew MacLeod <amacleod@redhat.com>
* loop-doloop.c (doloop_modify, doloop_optimize): Use
......
2013-10-09 Zhenqiang Chen <zhenqiang.chen@arm.com>
* gcc.dg/tree-ssa/phi-opt-11.c: New test.
2013-10-09 Marek Polacek <polacek@redhat.com>
PR c++/58635
......
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
int f(int a, int b, int c)
{
if (a == 0 && b > c)
return 0;
return a;
}
int g(int a, int b, int c)
{
if (a == 42 && b > c)
return 42;
return a;
}
int h(int a, int b, int c, int d)
{
if (a == d && b > c)
return d;
return a;
}
/* { dg-final { scan-tree-dump-times "if" 0 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
......@@ -110,6 +110,26 @@ static bool gate_hoist_loads (void);
This opportunity can sometimes occur as a result of other
optimizations.
Another case caught by value replacement looks like this:
bb0:
t1 = a == CONST;
t2 = b > c;
t3 = t1 & t2;
if (t3 != 0) goto bb1; else goto bb2;
bb1:
bb2:
x = PHI (CONST, a)
Gets replaced with:
bb0:
bb2:
t1 = a == CONST;
t2 = b > c;
t3 = t1 & t2;
x = a;
ABS Replacement
---------------
......@@ -672,6 +692,93 @@ jump_function_from_stmt (tree *arg, gimple stmt)
return false;
}
/* RHS is a source argument in a BIT_AND_EXPR which feeds a conditional
of the form SSA_NAME NE 0.
If RHS is fed by a simple EQ_EXPR comparison of two values, see if
the two input values of the EQ_EXPR match arg0 and arg1.
If so update *code and return TRUE. Otherwise return FALSE. */
static bool
rhs_is_fed_for_value_replacement (const_tree arg0, const_tree arg1,
enum tree_code *code, const_tree rhs)
{
/* Obviously if RHS is not an SSA_NAME, we can't look at the defining
statement. */
if (TREE_CODE (rhs) == SSA_NAME)
{
gimple def1 = SSA_NAME_DEF_STMT (rhs);
/* Verify the defining statement has an EQ_EXPR on the RHS. */
if (is_gimple_assign (def1) && gimple_assign_rhs_code (def1) == EQ_EXPR)
{
/* Finally verify the source operands of the EQ_EXPR are equal
to arg0 and arg1. */
tree op0 = gimple_assign_rhs1 (def1);
tree op1 = gimple_assign_rhs2 (def1);
if ((operand_equal_for_phi_arg_p (arg0, op0)
&& operand_equal_for_phi_arg_p (arg1, op1))
|| (operand_equal_for_phi_arg_p (arg0, op1)
&& operand_equal_for_phi_arg_p (arg1, op0)))
{
/* We will perform the optimization. */
*code = gimple_assign_rhs_code (def1);
return true;
}
}
}
return false;
}
/* Return TRUE if arg0/arg1 are equal to the rhs/lhs or lhs/rhs of COND.
Also return TRUE if arg0/arg1 are equal to the source arguments of a
an EQ comparison feeding a BIT_AND_EXPR which feeds COND.
Return FALSE otherwise. */
static bool
operand_equal_for_value_replacement (const_tree arg0, const_tree arg1,
enum tree_code *code, gimple cond)
{
gimple def;
tree lhs = gimple_cond_lhs (cond);
tree rhs = gimple_cond_rhs (cond);
if ((operand_equal_for_phi_arg_p (arg0, lhs)
&& operand_equal_for_phi_arg_p (arg1, rhs))
|| (operand_equal_for_phi_arg_p (arg1, lhs)
&& operand_equal_for_phi_arg_p (arg0, rhs)))
return true;
/* Now handle more complex case where we have an EQ comparison
which feeds a BIT_AND_EXPR which feeds COND.
First verify that COND is of the form SSA_NAME NE 0. */
if (*code != NE_EXPR || !integer_zerop (rhs)
|| TREE_CODE (lhs) != SSA_NAME)
return false;
/* Now ensure that SSA_NAME is set by a BIT_AND_EXPR. */
def = SSA_NAME_DEF_STMT (lhs);
if (!is_gimple_assign (def) || gimple_assign_rhs_code (def) != BIT_AND_EXPR)
return false;
/* Now verify arg0/arg1 correspond to the source arguments of an
EQ comparison feeding the BIT_AND_EXPR. */
tree tmp = gimple_assign_rhs1 (def);
if (rhs_is_fed_for_value_replacement (arg0, arg1, code, tmp))
return true;
tmp = gimple_assign_rhs2 (def);
if (rhs_is_fed_for_value_replacement (arg0, arg1, code, tmp))
return true;
return false;
}
/* The function value_replacement does the main work of doing the value
replacement. Return non-zero if the replacement is done. Otherwise return
0. If we remove the middle basic block, return 2.
......@@ -741,10 +848,7 @@ value_replacement (basic_block cond_bb, basic_block middle_bb,
We now need to verify that the two arguments in the PHI node match
the two arguments to the equality comparison. */
if ((operand_equal_for_phi_arg_p (arg0, gimple_cond_lhs (cond))
&& operand_equal_for_phi_arg_p (arg1, gimple_cond_rhs (cond)))
|| (operand_equal_for_phi_arg_p (arg1, gimple_cond_lhs (cond))
&& operand_equal_for_phi_arg_p (arg0, gimple_cond_rhs (cond))))
if (operand_equal_for_value_replacement (arg0, arg1, &code, cond))
{
edge e;
tree arg;
......
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