This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tuples] handle TRUTH_NOT EXPR in gimple_build_cond_from_tree
- From: Aldy Hernandez <aldyh at redhat dot com>
- To: dnovillo at google dot com, gcc-patches at gcc dot gnu dot org
- Date: Fri, 27 Jun 2008 12:49:19 -0400
- Subject: [tuples] handle TRUTH_NOT EXPR in gimple_build_cond_from_tree
gimple_build_cond_from_tree should handle TRUTH_NOT_EXPR because
sometimes fold2 will uncanonicalize a GIMPLE_COND's condition into a
TRUTH_NOT_EXPR. The patch below handles TRUTH_NOT_EXPR correctly.
This patch fixes a latent bug in gimple_cond_get_ops_from_tree() that
surfaced while testing the forward propagation pass.
Committing to branch.
Tested on x86-64.
* gimple.c (gimple_cond_get_ops_from_tree): Handle TRUTH_NOT_EXPR.
Index: gimple.c
===================================================================
--- gimple.c (revision 137150)
+++ gimple.c (working copy)
@@ -472,13 +472,21 @@ gimple_cond_get_ops_from_tree (tree cond
tree *lhs_p, tree *rhs_p)
{
gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond)) == tcc_comparison
+ || TREE_CODE (cond) == TRUTH_NOT_EXPR
|| is_gimple_min_invariant (cond)
|| SSA_VAR_P (cond));
extract_ops_from_tree (cond, code_p, lhs_p, rhs_p);
+ /* Canonicalize conditionals of the form 'if (!VAL)'. */
+ if (*code_p == TRUTH_NOT_EXPR)
+ {
+ *code_p = EQ_EXPR;
+ gcc_assert (*lhs_p && *rhs_p == NULL_TREE);
+ *rhs_p = fold_convert (TREE_TYPE (*lhs_p), integer_zero_node);
+ }
/* Canonicalize conditionals of the form 'if (VAL)' */
- if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
+ else if (TREE_CODE_CLASS (*code_p) != tcc_comparison)
{
*code_p = NE_EXPR;
gcc_assert (*lhs_p && *rhs_p == NULL_TREE);