From patchwork Mon Nov 8 07:03:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 47196 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA7B3385843D for ; Mon, 8 Nov 2021 07:04:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA7B3385843D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636355050; bh=I/YZThrEpO6lCqmPZYgHv00zBoRyEM5fhXG95bjcwqQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mauSPkpwhzRggp7ljFWjCN6TwwKdIqAumwWwBMIqZpNKmeI90+ywU92jxMrp0p6aX uC7ly60QK8OE2fJXxOTqbunSr5T++ZBz9222AqmHu8lEzs3D9lXd1CxgRSVpB9szJN Ea/M1n5zwDxI3+rRwqDMQqKOCTQVT0ZuLWpdTZUY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id A10953858401 for ; Mon, 8 Nov 2021 07:03:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A10953858401 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 41682281D88; Mon, 8 Nov 2021 08:03:40 +0100 (CET) Date: Mon, 8 Nov 2021 08:03:40 +0100 To: gcc-patches@gcc.gnu.org Subject: Improve optimization of some builtins Message-ID: <20211108070340.GA86621@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, for nested functions we output call to builtin_dwarf_cfa which initializes frame entry used only for debugging. This however prevents us from detecting functions containing nested functions as const/pure or analyze side effects in modref. builtin_dwarf_cfa is not documented and I wonder if it should be turned to internal function. But I think we could consider functions using it const even if in theory one can do things like test the return address and see the difference between different frame addreses. While doing so I also noticed that special_buitin_state handles quite few builtins that are not special cased by ipa-modref. They do not make user visible loads/stores and thus I think they shoul dbe annotated by ".c" to make this explicit for both modref and PTA. Finally I aded dwarf_cfa and similar return_address to list of simple bulitins since it compiles to simple stack frame load and we consider several other builtins doing so simple. lto-bootstrapped/regtested all languages on x86_64-linux, seems sane? Honza * builtins.c (is_simple_builtin): Add builitin_dwarf_cfa and builtin_return_address. (builtin_fnspec): Annotate builtin_return, bulitin_eh_pointer, builtin_eh_filter, builtin_unwind_resume, builtin_cxa_end_cleanup, builtin_eh_copy_values, builtin_frame_address, builtin_apply_args, builtin_asan_before_dynamic_init, builtin_asan_after_dynamic_init, builtin_prefetch, builtin_dwarf_cfa, builtin_return_addrss as ".c" * ipa-pure-const.c (special_builtin_state): Add builtin_dwarf_cfa and builtin_return_address. diff --git a/gcc/builtins.c b/gcc/builtins.c index 7d0f61fc98b..43433e8d6ce 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -10711,6 +10711,8 @@ is_simple_builtin (tree decl) case BUILT_IN_VA_END: case BUILT_IN_STACK_SAVE: case BUILT_IN_STACK_RESTORE: + case BUILT_IN_DWARF_CFA: + case BUILT_IN_RETURN_ADDRESS: /* Exception state returns or moves registers around. */ case BUILT_IN_EH_FILTER: case BUILT_IN_EH_POINTER: @@ -11099,6 +11099,19 @@ builtin_fnspec (tree callee) CASE_BUILT_IN_TM_STORE (M256): return ".cO "; case BUILT_IN_STACK_SAVE: + case BUILT_IN_RETURN: + 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_ARGS: + case BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT: + case BUILT_IN_ASAN_AFTER_DYNAMIC_INIT: + case BUILT_IN_PREFETCH: + case BUILT_IN_DWARF_CFA: + case BUILT_IN_RETURN_ADDRESS: return ".c"; case BUILT_IN_ASSUME_ALIGNED: return "1cX "; diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index a84a4eb7ac0..e5048092939 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -529,6 +529,8 @@ special_builtin_state (enum pure_const_state_e *state, bool *looping, case BUILT_IN_APPLY_ARGS: case BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT: case BUILT_IN_ASAN_AFTER_DYNAMIC_INIT: + case BUILT_IN_DWARF_CFA: + case BUILT_IN_RETURN_ADDRESS: *looping = false; *state = IPA_CONST; return true;