From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20982 invoked by alias); 25 Mar 2008 14:47:27 -0000 Received: (qmail 20969 invoked by uid 22791); 25 Mar 2008 14:47:26 -0000 X-Spam-Check-By: sourceware.org Received: from cantor.suse.de (HELO mx1.suse.de) (195.135.220.2) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 25 Mar 2008 14:46:59 +0000 Received: from Relay2.suse.de (mail2.suse.de [195.135.221.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id E14893869B for ; Tue, 25 Mar 2008 15:46:52 +0100 (CET) Date: Tue, 25 Mar 2008 15:25:00 -0000 From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fold comparison of local addresses Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2008-03/txt/msg01486.txt.bz2 I was surprised we don't handle this yet. Bootstrap & regtest in progress, I'll apply it after that succeeded. Richard. 2008-03-25 Richard Guenther * Makefile.in (fold-const.o): Add $(TARGET_H) dependency. * fold-const.c (target.h): Include. (fold_comparison): Fold comparison of addresses of two decls that bind locally. * gcc.dg/fold-addr-1.c: New testcase. Index: Makefile.in =================================================================== *** Makefile.in (revision 133506) --- Makefile.in (working copy) *************** tree-pretty-print.o : tree-pretty-print. *** 2321,2327 **** value-prof.h fixed-value.h output.h fold-const.o : fold-const.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ $(TREE_H) $(FLAGS_H) $(REAL_H) toplev.h $(HASHTAB_H) $(EXPR_H) $(RTL_H) \ ! $(GGC_H) $(TM_P_H) langhooks.h $(MD5_H) intl.h fixed-value.h diagnostic.o : diagnostic.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ $(TREE_H) version.h $(TM_P_H) $(FLAGS_H) input.h toplev.h intl.h \ $(DIAGNOSTIC_H) langhooks.h $(LANGHOOKS_DEF_H) diagnostic.def opts.h --- 2321,2327 ---- value-prof.h fixed-value.h output.h fold-const.o : fold-const.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ $(TREE_H) $(FLAGS_H) $(REAL_H) toplev.h $(HASHTAB_H) $(EXPR_H) $(RTL_H) \ ! $(GGC_H) $(TM_P_H) langhooks.h $(MD5_H) intl.h fixed-value.h $(TARGET_H) diagnostic.o : diagnostic.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ $(TREE_H) version.h $(TM_P_H) $(FLAGS_H) input.h toplev.h intl.h \ $(DIAGNOSTIC_H) langhooks.h $(LANGHOOKS_DEF_H) diagnostic.def opts.h Index: fold-const.c =================================================================== *** fold-const.c (revision 133506) --- fold-const.c (working copy) *************** along with GCC; see the file COPYING3. *** 58,63 **** --- 58,64 ---- #include "rtl.h" #include "expr.h" #include "tm_p.h" + #include "target.h" #include "toplev.h" #include "intl.h" #include "ggc.h" *************** fold_comparison (enum tree_code code, tr *** 8581,8586 **** --- 8582,8598 ---- return fold_build2 (code, type, offset0, offset1); } } + /* For non-equal bases we can simplify if they are plain decls. */ + else if (base0 && base1 + && DECL_P (base0) && DECL_P (base1) + && targetm.binds_local_p (base0) + && targetm.binds_local_p (base1)) + { + if (code == EQ_EXPR) + return omit_two_operands (type, boolean_false_node, arg0, arg1); + else if (code == NE_EXPR) + return omit_two_operands (type, boolean_true_node, arg0, arg1); + } } /* Transform comparisons of the form X +- C1 CMP Y +- C2 to Index: testsuite/gcc.dg/fold-addr-1.c =================================================================== *** testsuite/gcc.dg/fold-addr-1.c (revision 0) --- testsuite/gcc.dg/fold-addr-1.c (revision 0) *************** *** 0 **** --- 1,10 ---- + /* { dg-do compile } */ + /* { dg-options "-fdump-tree-original" } */ + + int bar(char p1, char p2) + { + return &p1 == &p2; + } + + /* { dg-final { scan-tree-dump "return 0;" "original" } } */ + /* { dg-final { cleanup-tree-dump "original" } } */