aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-phiopt.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2016-07-13 13:57:05 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2016-07-13 13:57:05 +0000
commit9737f35bba5f6dd73a19b8877ecf5b4fc37b7921 (patch)
tree743755983303d6111684311ede069768ee2eb566 /gcc/tree-ssa-phiopt.c
parent62c0ea4b14d5cc56b9a2a4c85f8d77f136434680 (diff)
downloadgcc-9737f35bba5f6dd73a19b8877ecf5b4fc37b7921.zip
gcc-9737f35bba5f6dd73a19b8877ecf5b4fc37b7921.tar.gz
gcc-9737f35bba5f6dd73a19b8877ecf5b4fc37b7921.tar.bz2
re PR tree-optimization/24574 (a!=0?a/10:0 is not reduced to a/10)
2016-07-13 Richard Biener <rguenther@suse.de> PR tree-optimization/24574 * tree-ssa-phiopt.c (absorbing_element_p): Pass in argument position and add shift, rotate, divison and modulo support for left zero. (value_replacement): Pass in argument position to absorbing_element_p. * gcc.dg/pr24574.c: New testcase. From-SVN: r238299
Diffstat (limited to 'gcc/tree-ssa-phiopt.c')
-rw-r--r--gcc/tree-ssa-phiopt.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index caf591b..dd9aa01 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -812,7 +812,7 @@ neutral_element_p (tree_code code, tree arg, bool right)
/* Returns true if ARG is an absorbing element for operation CODE. */
static bool
-absorbing_element_p (tree_code code, tree arg)
+absorbing_element_p (tree_code code, tree arg, bool right)
{
switch (code)
{
@@ -823,6 +823,21 @@ absorbing_element_p (tree_code code, tree arg)
case BIT_AND_EXPR:
return integer_zerop (arg);
+ case LSHIFT_EXPR:
+ case RSHIFT_EXPR:
+ case LROTATE_EXPR:
+ case RROTATE_EXPR:
+ case TRUNC_DIV_EXPR:
+ case CEIL_DIV_EXPR:
+ case FLOOR_DIV_EXPR:
+ case ROUND_DIV_EXPR:
+ case EXACT_DIV_EXPR:
+ case TRUNC_MOD_EXPR:
+ case CEIL_MOD_EXPR:
+ case FLOOR_MOD_EXPR:
+ case ROUND_MOD_EXPR:
+ return !right && integer_zerop (arg);
+
default:
return false;
}
@@ -994,9 +1009,10 @@ value_replacement (basic_block cond_bb, basic_block middle_bb,
&& operand_equal_for_phi_arg_p (rhs1, cond_lhs)
&& neutral_element_p (code_def, cond_rhs, false))
|| (operand_equal_for_phi_arg_p (arg1, cond_rhs)
- && (operand_equal_for_phi_arg_p (rhs2, cond_lhs)
- || operand_equal_for_phi_arg_p (rhs1, cond_lhs))
- && absorbing_element_p (code_def, cond_rhs))))
+ && ((operand_equal_for_phi_arg_p (rhs2, cond_lhs)
+ && absorbing_element_p (code_def, cond_rhs, true))
+ || (operand_equal_for_phi_arg_p (rhs1, cond_lhs)
+ && absorbing_element_p (code_def, cond_rhs, false))))))
{
gsi = gsi_for_stmt (cond);
if (INTEGRAL_TYPE_P (TREE_TYPE (lhs)))