public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [tuples] handle TRUTH_NOT EXPR in gimple_build_cond_from_tree
@ 2008-06-27 16:51 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2008-06-27 16:51 UTC (permalink / raw)
  To: dnovillo, gcc-patches

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-06-27 16:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-27 16:51 [tuples] handle TRUTH_NOT EXPR in gimple_build_cond_from_tree Aldy Hernandez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).