From patchwork Fri Jun 11 15:16:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 55336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 2EC63B7D61 for ; Sat, 12 Jun 2010 01:16:23 +1000 (EST) Received: (qmail 9812 invoked by alias); 11 Jun 2010 15:16:20 -0000 Received: (qmail 9782 invoked by uid 22791); 11 Jun 2010 15:16:13 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 Jun 2010 15:16:09 +0000 Received: from localhost (occam.ms.mff.cuni.cz [195.113.18.121]) by nikam.ms.mff.cuni.cz (Postfix) with ESMTP id 692939AC850 for ; Fri, 11 Jun 2010 17:16:04 +0200 (CEST) Received: by localhost (Postfix, from userid 16202) id 638355641AD; Fri, 11 Jun 2010 17:16:04 +0200 (CEST) Date: Fri, 11 Jun 2010 17:16:04 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Improve ipa-pure-const handling of builtins Message-ID: <20100611151604.GC7958@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, while looking on statistics, I noticed that quite large portion of functions are not pure/const because they call alloca or __builtin_unreachable. This patch adds code to ipa-pure-const.c to recognize builtins that are special in a way that they can not be const/pure, but function calling them can. Bootstrapped/regtested x86_64-linux, commited. Honza * ipa-pure-const.c (special_builtlin_state): New function. (check_call): Use it instead of special casign BUILT_IN_RETURN. (propagate_pure_const): Use it. * gcc.dg/ipa/pure-const-2.c: New testcase. Index: ipa-pure-const.c =================================================================== --- ipa-pure-const.c (revision 160547) +++ ipa-pure-const.c (working copy) @@ -410,6 +410,40 @@ worse_state (enum pure_const_state_e *st *looping = MAX (*looping, looping2); } +/* Recognize special cases of builtins that are by themself not pure or const + but function using them is. */ +static bool +special_builtlin_state (enum pure_const_state_e *state, bool *looping, + tree callee) +{ + if (DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL) + switch (DECL_FUNCTION_CODE (callee)) + { + case BUILT_IN_RETURN: + case BUILT_IN_UNREACHABLE: + case BUILT_IN_ALLOCA: + case BUILT_IN_STACK_SAVE: + case BUILT_IN_STACK_RESTORE: + case BUILT_IN_EH_POINTER: + case BUILT_IN_EH_FILTER: + case BUILT_IN_UNWIND_RESUME: + case BUILT_IN_CXA_END_CLEANUP: + case BUILT_IN_EH_COPY_VALUES: + case BUILT_IN_FRAME_ADDRESS: + case BUILT_IN_APPLY: + case BUILT_IN_APPLY_ARGS: + case BUILT_IN_ARGS_INFO: + *looping = false; + *state = IPA_CONST; + return true; + case BUILT_IN_PREFETCH: + *looping = true; + *state = IPA_CONST; + return true; + } + return false; +} + /* Check the parameters of a function call to CALL_EXPR to see if there are any references in the parameters that are not allowed for pure or const functions. Also check to see if this is either an @@ -460,9 +494,15 @@ check_call (funct_state local, gimple ca graph. */ if (callee_t) { - /* built_in_return is really just an return statemnt. */ - if (gimple_call_builtin_p (call, BUILT_IN_RETURN)) - return; + enum pure_const_state_e call_state; + bool call_looping; + + if (special_builtlin_state (&call_state, &call_looping, callee_t)) + { + worse_state (&local->pure_const_state, &local->looping, + call_state, call_looping); + return; + } /* When bad things happen to bad functions, they cannot be const or pure. */ if (setjmp_call_p (callee_t)) @@ -1143,10 +1183,13 @@ propagate_pure_const (void) edge_looping = y_l->looping; } } + else if (special_builtlin_state (&edge_state, &edge_looping, + y->decl)) + ; else state_from_flags (&edge_state, &edge_looping, - flags_from_decl_or_type (y->decl), - cgraph_edge_cannot_lead_to_return (e)); + flags_from_decl_or_type (y->decl), + cgraph_edge_cannot_lead_to_return (e)); /* Merge the results with what we already know. */ better_state (&edge_state, &edge_looping, Index: testsuite/gcc.dg/ipa/pure-const-2.c =================================================================== --- testsuite/gcc.dg/ipa/pure-const-2.c (revision 0) +++ testsuite/gcc.dg/ipa/pure-const-2.c (revision 0) @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-local-pure-const1 -fdump-tree-optimized" } */ +static __attribute__ ((noinline, noclone)) +int i_am_pure(char *c, int n) +{ + char *d=__builtin_alloca (n); + int i; + int sum; + for (i=0;i