From patchwork Sun Sep 11 11:48:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takayuki 'January June' Suwa X-Patchwork-Id: 57540 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 21C053852763 for ; Sun, 11 Sep 2022 20:50:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 21C053852763 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662929455; bh=eUT02LjkikW8lfg5oY/sgEafGYt5A8r+2+4VJBBvn8w=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kouaINaTot4AefDoon3Tyizw+w1YjRqq4gBbzlX9QhgE/3wrr23EwLa0rc7Rolmfb 8KG2xNse149sMoi743CZRHXa5+nto2GXsQNK4rU+GWpCKwA0i+RWEhCTgTataBZnFe EDxNJ/xm8DrC25BgGelJqW5ONV+UIpOvOFgswdzU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh505-vm10.bullet.mail.kks.yahoo.co.jp (nh505-vm10.bullet.mail.kks.yahoo.co.jp [183.79.57.112]) by sourceware.org (Postfix) with SMTP id E2EDC3858C50 for ; Sun, 11 Sep 2022 20:50:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E2EDC3858C50 Received: from [183.79.100.138] by nh505.bullet.mail.kks.yahoo.co.jp with NNFMP; 11 Sep 2022 20:50:21 -0000 Received: from [183.79.100.133] by t501.bullet.mail.kks.yahoo.co.jp with NNFMP; 11 Sep 2022 20:50:21 -0000 Received: from [127.0.0.1] by omp502.mail.kks.yahoo.co.jp with NNFMP; 11 Sep 2022 20:50:21 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 496620.57777.bm@omp502.mail.kks.yahoo.co.jp Received: (qmail 52139 invoked by alias); 11 Sep 2022 20:50:21 -0000 Received: from unknown (HELO ?192.168.150.64?) (183.77.162.44 with ) by smtp6002.mail.ssk.ynwp.yahoo.co.jp with SMTP; 11 Sep 2022 20:50:21 -0000 X-YMail-JAS: 3LPpq8YVM1m_E6ESkMg6pp1nkJDTwq9uce9FWXGJt0zBaAcOgiXRo_y3bK8Jc7N8IxDGMBawjDS1pqylPQGHMRitYxBhd8800XWLcMQGetnaJsTvSWoyIEqeU3wqFGvAo45S.zmcKg-- X-Apparently-From: X-YMail-OSG: sKLai58VM1notqUec3Df6jhVxue5U3p_nVXC07ES_y8fJKg jBh8ZqF8eoJ1tJZSWjEe2e5W1yIqFGej6NXsVs8bApetaXy95qIQRp7UE1aa apOVbnM9f6PAxI4vqz1XsymVmYMr02_TFhTi000lVe7QRI5dfTxrZBX4tNgK v3iJWWMKHNTudY66K66BG9H9CVxWnrAsV8o9PFis8g_jIq_RPWTE1uTEZNXD 2XkEkU_m2YOfDD4dy29s1utsMZVGKKbU8fLRxRj7Slf3safPKTYP7hAyAnnn zTe4kTKFcVnyB2tm9lWjhAO5bIXShsI3Ek0fYdITiSBmXlO61UQYL6amIhR9 QfBeTHzZCM46.hEL38k0Vg5QJ9CFI8Q5oSha3MP8YVSEfvgRyshUo_cUYM2z KxVWR0eJNiefAsGLs4DdrO8d9BaKwNOXlDjavXm9YuEUx1f7Je8XttYzSxPH _XCIZAHNyPHKsQ0sLT81FgXxLoUKOU7N7ZlRa7NknUKswd0lVzA1ERxVn.WE 7TOBArjGj3Lj5Qbp0h9iWgzW7ttBYoAbaQad7KVKk.X62jD_fxnoaoHq33yH FfIj4_xnvDVn0ZQXMOLcl9muYvm.b98.BC1_PDkcPV4zS9.hW0rSq3N4dRXm H2bdngsW2_W6_d_QTPd3twEedet3iQajuReO0NcgOCOHpEGzpeIw9iIjs8zF 3oHyovMuiEzMlSWzV2Be4PYNTQgLacADLa.393VsbD8UEB5rk9YUf2ZUjoGH tfdGQZ2hkK78U0ofSdLVeb410Lx2wJ6nJjbDqxYzl6VQDy1I4tsKPlv0Bh9w ZMwqCoysBFNaV7HiLBlEVcCF2EfEIeEDOM5LF8u9o9SeS7_iZEE2Jgh558HM INISHKMyXan7WaA.qb9esKaM_KPIjAaqT45NdM_9WSsdKU5ecoKDHY.nWeiC eOwoUpCkMfYZ2Zhw- Message-ID: <8220176b-a7db-6ef5-9994-e4744806aafd@yahoo.co.jp> Date: Sun, 11 Sep 2022 20:48:09 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 To: GCC Patches Subject: [PATCH 1/2] Add new target hook: constant_ok_for_cprop_p X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Takayuki 'January June' Suwa via Gcc-patches From: Takayuki 'January June' Suwa Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, Many RISC machines, as we know, have some restrictions on placing register-width constants in the source of load-immediate machine instructions, so the target must provide a solution for that in the machine description. A naive way would be to solve it early, ie. to replace with read constants pooled in memory when expanding to RTL. Alternatively, a more fancy approach would be to forgo placement in the constant pool until somewhere before the reload/LRA eg. the "split1" pass to give the optimization passes that involve immediates a chance to work. If we choose the latter, we can expect better results with RTL if-conversion, constant folding, etc., but it often propagates constants that are too large in size to resolve to a simple load-immediate instruction. This is because constant propagation has no way of telling about it, so this patch provides it. === This new target hook can be used to tell cprop whether or not to propagate a constant depending on its contents. For backwards compatibility, the default setting for this hook retains the old behavior. gcc/ChangeLog: * hooks.h (hook_bool_const_rtx_true): New prototype. * hooks.cc (hook_bool_const_rtx_true): New default hook. * target.def (constant_ok_for_cprop_p): New target hook. * cprop.cc (cprop_constant_p): Change to use the hook. * doc/tm.texi.in, (TARGET_CONSTANT_OK_FOR_CPROP_P): New @hook. * doc/tm.texi (TARGET_CONSTANT_OK_FOR_CPROP_P): New document. --- gcc/cprop.cc | 4 +++- gcc/doc/tm.texi | 12 ++++++++++++ gcc/doc/tm.texi.in | 2 ++ gcc/hooks.cc | 7 +++++++ gcc/hooks.h | 1 + gcc/target.def | 14 ++++++++++++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gcc/cprop.cc b/gcc/cprop.cc index 580f811545d..dfb1e88e9b4 100644 --- a/gcc/cprop.cc +++ b/gcc/cprop.cc @@ -40,6 +40,7 @@ along with GCC; see the file COPYING3. If not see #include "dbgcnt.h" #include "cfgloop.h" #include "gcse.h" +#include "target.h" /* An obstack for our working variables. */ @@ -249,7 +250,8 @@ insert_set_in_table (rtx dest, rtx src, rtx_insn *insn, static bool cprop_constant_p (const_rtx x) { - return CONSTANT_P (x) && (GET_CODE (x) != CONST || shared_const_p (x)); + return CONSTANT_P (x) && targetm.constant_ok_for_cprop_p (x) + && (GET_CODE (x) != CONST || shared_const_p (x)); } /* Determine whether the rtx X should be treated as a register that can diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 858bfb80cec..83151626a71 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -12187,6 +12187,18 @@ MIPS, where add-immediate takes a 16-bit signed value, is zero, which disables this optimization. @end deftypevr +@deftypefn {Target Hook} bool TARGET_CONSTANT_OK_FOR_CPROP_P (const_rtx @var{cst}) +On some target machines, such as RISC ones, load-immediate instructions +often have a limited range (for example, within signed 12 bits or less). +Because they will be typically placed into the constant pool, +unconditionally propagating constants that exceed such limit can lead to +increased number of instruction and/or memory read access. +This target hook should return @code{false} if @var{cst}, a candidate for +constant propagation, is undesirable as a source for load-immediate +instructions. +The default version of this hook always returns @code{true}. +@end deftypefn + @deftypefn {Target Hook} {unsigned HOST_WIDE_INT} TARGET_ASAN_SHADOW_OFFSET (void) Return the offset bitwise ored into shifted address to get corresponding Address Sanitizer shadow memory address. NULL if Address Sanitizer is not diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 21b849ea32a..147331b0f53 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -7887,6 +7887,8 @@ and the associated definitions of those functions. @hook TARGET_CONST_ANCHOR +@hook TARGET_CONSTANT_OK_FOR_CPROP_P + @hook TARGET_ASAN_SHADOW_OFFSET @hook TARGET_MEMMODEL_CHECK diff --git a/gcc/hooks.cc b/gcc/hooks.cc index b29233f4f85..67bf3553d26 100644 --- a/gcc/hooks.cc +++ b/gcc/hooks.cc @@ -82,6 +82,13 @@ hook_bool_mode_true (machine_mode) return true; } +/* Generic hook that takes (const_rtx) and returns true. */ +bool +hook_bool_const_rtx_true (const_rtx) +{ + return true; +} + /* Generic hook that takes (machine_mode, machine_mode) and returns true. */ bool hook_bool_mode_mode_true (machine_mode, machine_mode) diff --git a/gcc/hooks.h b/gcc/hooks.h index 1056e1e9e4d..d001f8fb9dc 100644 --- a/gcc/hooks.h +++ b/gcc/hooks.h @@ -30,6 +30,7 @@ extern bool hook_bool_bool_gcc_optionsp_false (bool, struct gcc_options *); extern bool hook_bool_const_int_const_int_true (const int, const int); extern bool hook_bool_mode_false (machine_mode); extern bool hook_bool_mode_true (machine_mode); +extern bool hook_bool_const_rtx_true (const_rtx); extern bool hook_bool_mode_mode_true (machine_mode, machine_mode); extern bool hook_bool_mode_const_rtx_false (machine_mode, const_rtx); extern bool hook_bool_mode_const_rtx_true (machine_mode, const_rtx); diff --git a/gcc/target.def b/gcc/target.def index 4d49ffc2c88..8bf093ab0dc 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -4510,6 +4510,20 @@ MIPS, where add-immediate takes a 16-bit signed value,\n\ is zero, which disables this optimization.", unsigned HOST_WIDE_INT, 0) +DEFHOOK +(constant_ok_for_cprop_p, + "On some target machines, such as RISC ones, load-immediate instructions\n\ +often have a limited range (for example, within signed 12 bits or less).\n\ +Because they will be typically placed into the constant pool,\n\ +unconditionally propagating constants that exceed such limit can lead to\n\ +increased number of instruction and/or memory read access.\n\ +This target hook should return @code{false} if @var{cst}, a candidate for\n\ +constant propagation, is undesirable as a source for load-immediate\n\ +instructions.\n\ +The default version of this hook always returns @code{true}.", + bool, (const_rtx cst), + hook_bool_const_rtx_true) + /* Defines, which target-dependent bits (upper 16) are used by port */ DEFHOOK (memmodel_check, From patchwork Sun Sep 11 11:51:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takayuki 'January June' Suwa X-Patchwork-Id: 57541 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 D1021385695E for ; Sun, 11 Sep 2022 20:50:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1021385695E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662929455; bh=5NNFUpZ4k5ulHsFq4ngYMil40y9j7wCEQsl4PRKF+w0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=TfwSlENz3nYMvNd4w2SuIxyxt0qrU9St+OyKpd9e7QiNFneqv0ggg9IuDjffksX/m kIos50t2+QgRQ1Wy5Bbwz+t22NA/iEyZVq8L5NKeqgL1yAaD7JBc3fsgqu79U507wf ta/3gw7CrWwgtFKCd7GOAB6jfbzf8Dk4srMR9+8w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh503-vm7.bullet.mail.kks.yahoo.co.jp (nh503-vm7.bullet.mail.kks.yahoo.co.jp [183.79.56.193]) by sourceware.org (Postfix) with SMTP id D0B703858D32 for ; Sun, 11 Sep 2022 20:50:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D0B703858D32 Received: from [183.79.100.141] by nh503.bullet.mail.kks.yahoo.co.jp with NNFMP; 11 Sep 2022 20:50:22 -0000 Received: from [183.79.100.134] by t504.bullet.mail.kks.yahoo.co.jp with NNFMP; 11 Sep 2022 20:50:22 -0000 Received: from [127.0.0.1] by omp503.mail.kks.yahoo.co.jp with NNFMP; 11 Sep 2022 20:50:22 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 234846.89823.bm@omp503.mail.kks.yahoo.co.jp Received: (qmail 93248 invoked by alias); 11 Sep 2022 20:50:22 -0000 Received: from unknown (HELO ?192.168.150.64?) (183.77.162.44 with ) by smtp6008.mail.ssk.ynwp.yahoo.co.jp with SMTP; 11 Sep 2022 20:50:22 -0000 X-YMail-JAS: Xi.m5TEVM1kdlzywUlIASHA1DcLlBtH9EUNKqM.4a0sUH6Ar26FYfdpM2XZo.ZMCUg7y3661PZ57.wsFd_ZfL5RNMyTV4AOx3CPvGsRtTXXyuwgw1V1bHGbIkthB.bjkpk6Gf_loMg-- X-Apparently-From: X-YMail-OSG: 6owLQwQVM1kH9FYTx7.WISVj.pC6SfUN02QesP_tLF.X3XL Jo3Fg3LOYk_0jnVTeDJmpqKpwyTtCxnpfnz6SCqYz.xHw2tTPLmWeqTszJbB Fc689uWdEWlrdjz8QTOfuqm4i_hOv..aVJ.LqNMTSOaBjhqh4Ltclv7BZ.XC _cHuFE3ihup9qK.IzaHhfl.yrtfPRtmsarPXjzlrtxVC_zVMhKtdje.Tlpxa fUPdRzWgu6Iwdszxrl_ME55R24QMeHg0sO49anXinmYHguOnQhH5PLErRjp. PK22eh_fCdQIPGnkWSaSiC6oQs7uzMwpIkWXz9g6X8F9SWylqd1oTj2mkWPw rpp60pZlqwRHPNAEkzPtb56s6aVRfjvHPWOtA27GpNsFMJt9apBZEMFGqzUK BY6YnW8olIewutruqHiP.eeJkWVC5kUv.SEZmCrjDD0gWlDwNQQ9D3I.ezqW ub9QVeaourw7zeJR5ZGIH.jp9LbzRG_goG.nJkEuLbaN2tk1DPWSJX6Cbjkz z2TU.llkZHTS3sFQPXgL5nXlPYTIF6I13g1t3g6.UlArXm_t.KyqycggadFf JXCkXViszgkQwl2ELIiNswfoP_B2pFE.qn.iN1cmJfZgNF.MlEyjDxMBJ4CD uxalMu9qRpteR_idW4PNEqe5iND.WDTBSS3MC5ApR0wHoTxJpRcsme7yiXHG 3E3P3u3cB25UVwPXwR0GXr.vR.EwE.Yt_NHlDTwFlQAb0NjvLC_8c7aFR1Jv Zc06anezpEXvY_Fuiqf_vKBtwrbHkxC1b0Rc7ZUyHcjCHrwfGH_Iv2MDzmWJ .0ka.2hsFiKB6sFNxyP.haMvJ0kHT5lIteU_kkMLRMx5PO2oTN7yyLztn0Sm q4_l6mfoM8ZSmBZhcFTyQOGB6A_H.vFI33r75o1bXfPFtArJP7ZaMYwkO2IX XM15UUEzLhx8F1CJ3 Message-ID: <1e87f131-93eb-0d37-d0f4-a9a69a5dc61f@yahoo.co.jp> Date: Sun, 11 Sep 2022 20:51:15 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 To: GCC Patches Subject: [PATCH 2/2] xtensa: Implement new target hook: TARGET_CONSTANT_OK_FOR_CPROP_P X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Takayuki 'January June' Suwa via Gcc-patches From: Takayuki 'January June' Suwa Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch implements new target hook TARGET_CONSTANT_OK_FOR_CPROP_P in order to exclude CONST_INTs that cannot fit into a MOVI machine instruction from cprop. gcc/ChangeLog: * config/xtensa/xtensa.c (TARGET_CONSTANT_OK_FOR_CPROP_P): New macro definition. (xtensa_constant_ok_for_cprop_p): Implement the hook as mentioned above. --- gcc/config/xtensa/xtensa.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index ac52c015a94..5c432cc65aa 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -191,6 +191,7 @@ static bool xtensa_can_eliminate (const int from ATTRIBUTE_UNUSED, static HOST_WIDE_INT xtensa_starting_frame_offset (void); static unsigned HOST_WIDE_INT xtensa_asan_shadow_offset (void); static bool xtensa_function_ok_for_sibcall (tree, tree); +static bool xtensa_constant_ok_for_cprop_p (const_rtx); static rtx xtensa_delegitimize_address (rtx); @@ -345,12 +346,15 @@ static rtx xtensa_delegitimize_address (rtx); #undef TARGET_HAVE_SPECULATION_SAFE_VALUE #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed -#undef TARGET_DELEGITIMIZE_ADDRESS -#define TARGET_DELEGITIMIZE_ADDRESS xtensa_delegitimize_address - #undef TARGET_FUNCTION_OK_FOR_SIBCALL #define TARGET_FUNCTION_OK_FOR_SIBCALL xtensa_function_ok_for_sibcall +#undef TARGET_CONSTANT_OK_FOR_CPROP_P +#define TARGET_CONSTANT_OK_FOR_CPROP_P xtensa_constant_ok_for_cprop_p + +#undef TARGET_DELEGITIMIZE_ADDRESS +#define TARGET_DELEGITIMIZE_ADDRESS xtensa_delegitimize_address + struct gcc_target targetm = TARGET_INITIALIZER; @@ -4983,6 +4987,16 @@ xtensa_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED, tree exp ATTRIBUTE_U return true; } +/* Implement TARGET_CONSTANT_OK_FOR_CPROP_P. */ +static bool +xtensa_constant_ok_for_cprop_p (const_rtx x) +{ + if (CONST_INT_P (x) && ! xtensa_simm12b (INTVAL (x))) + return false; + + return true; +} + static rtx xtensa_delegitimize_address (rtx op) {