[PATCH] Remove duplicate code from fold_binary

Richard Guenther rguenther@suse.de
Mon Mar 5 14:46:00 GMT 2007

This removes duplicate functionality to fold &a != 0 for &a we know to be
non-null.  We do this already with 

      if (integer_zerop (arg1)
          && tree_expr_nonzero_p (arg0))
          tree res = constant_boolean_node (code==NE_EXPR, type);
          return omit_one_operand (type, res, arg0);

which catches even more cases because it looks at the effective base
of the ADDR_EXPR.

Bootstrapped and tested on x86_64-unknown-linux-gnu, committed to 


2007-03-05  Richard Guenther  <rguenther@suse.de>

	* fold-const.c (fold_binary): Remove duplicate folding
	of comparison of non-null ADDR_EXPR against null.

Index: fold-const.c
*** fold-const.c	(revision 122543)
--- fold-const.c	(working copy)
*************** fold_binary (enum tree_code code, tree t
*** 11159,11172 ****
            && code == EQ_EXPR)
          return fold_build1 (TRUTH_NOT_EXPR, type, arg0);
-       /* If this is an equality comparison of the address of a non-weak
- 	 object against zero, then we know the result.  */
-       if (TREE_CODE (arg0) == ADDR_EXPR
- 	  && ! DECL_WEAK (TREE_OPERAND (arg0, 0))
- 	  && integer_zerop (arg1))
- 	return constant_boolean_node (code != EQ_EXPR, type);
        /* If this is an equality comparison of the address of two non-weak,
  	 unaliased symbols neither of which are extern (since we do not
  	 have access to attributes for externs), then we know the result.  */
--- 11159,11164 ----

More information about the Gcc-patches mailing list