summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-ifcombine.c
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2008-04-30 15:06:16 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2008-04-30 15:06:16 +0000
commitc9686d0691b6f1786d48a85ccbc1e5f7a03c27f5 (patch)
treedd5256063c954d6124c39527db2f7d903cd8c3ad /gcc/tree-ssa-ifcombine.c
parentc1f194edce3cf8c485367024be8cef780be2a854 (diff)
downloadgcc-c9686d0691b6f1786d48a85ccbc1e5f7a03c27f5.tar.gz
2008-04-30 Richard Guenther <rguenther@suse.de>
PR tree-optimization/14847 * tree-ssa-ifcombine.c (get_name_for_bit_test): New helper function. (recognize_bits_test): Use it. (recognize_single_bit_test): Likewise. * gcc.dg/tree-ssa/ssa-ifcombine-6.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@134825 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-ifcombine.c')
-rw-r--r--gcc/tree-ssa-ifcombine.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/gcc/tree-ssa-ifcombine.c b/gcc/tree-ssa-ifcombine.c
index cec5868c636..3a28fadd792 100644
--- a/gcc/tree-ssa-ifcombine.c
+++ b/gcc/tree-ssa-ifcombine.c
@@ -135,6 +135,32 @@ same_phi_args_p (basic_block bb1, basic_block bb2, basic_block dest)
return true;
}
+/* Return the best representative SSA name for CANDIDATE which is used
+ in a bit test. */
+
+static tree
+get_name_for_bit_test (tree candidate)
+{
+ /* Skip single-use names in favor of using the name from a
+ non-widening conversion definition. */
+ if (TREE_CODE (candidate) == SSA_NAME
+ && has_single_use (candidate))
+ {
+ tree def_stmt = SSA_NAME_DEF_STMT (candidate);
+ if (TREE_CODE (def_stmt) == GIMPLE_MODIFY_STMT
+ && (TREE_CODE (GIMPLE_STMT_OPERAND (def_stmt, 1)) == NOP_EXPR
+ || TREE_CODE (GIMPLE_STMT_OPERAND (def_stmt, 1)) == CONVERT_EXPR))
+ {
+ tree rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
+ if (TYPE_PRECISION (TREE_TYPE (rhs))
+ <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (rhs, 0))))
+ return TREE_OPERAND (rhs, 0);
+ }
+ }
+
+ return candidate;
+}
+
/* Recognize a single bit test pattern in COND_EXPR and its defining
statements. Store the name being tested in *NAME and the bit
in *BIT. The COND_EXPR computes *NAME & (1 << *BIT).
@@ -192,7 +218,7 @@ recognize_single_bit_test (tree cond_expr, tree *name, tree *bit)
{
/* t & 1 */
*bit = integer_zero_node;
- *name = orig_name;
+ *name = get_name_for_bit_test (orig_name);
}
return true;
@@ -272,7 +298,7 @@ recognize_bits_test (tree cond_expr, tree *name, tree *bits)
if (TREE_CODE (t) != BIT_AND_EXPR)
return false;
- *name = TREE_OPERAND (t, 0);
+ *name = get_name_for_bit_test (TREE_OPERAND (t, 0));
*bits = TREE_OPERAND (t, 1);
return true;