This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]