From patchwork Fri Jun 17 13:47:49 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: 1644855 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=RhvZNszP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LPgPs36mvz9s5V for ; Fri, 17 Jun 2022 23:49:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 52C80386C59F for ; Fri, 17 Jun 2022 13:49:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 52C80386C59F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655473755; bh=lzBNu6B3PUUVi232R7bUB+mAl59XPKfUSHOKt+7/kZM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RhvZNszPwbpptyxyojP4sduBiAwQEgpMaWwsI3U0wVTdo6a9Q5e1Ksy6vbZPNmBmi IaWjpxmKlrxLwY/RlhGCRboI4pdgTGKqO4UBTdTmxF/sNYVS0MepFL6PWqs3tLpzzJ O3mA2MBqKbspl1fXeAkyxWdiPn5N3PdwnMFwHXM8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh502-vm12.bullet.mail.kks.yahoo.co.jp (nh502-vm12.bullet.mail.kks.yahoo.co.jp [183.79.56.157]) by sourceware.org (Postfix) with SMTP id 030823857344 for ; Fri, 17 Jun 2022 13:48:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 030823857344 Received: from [183.79.100.141] by nh502.bullet.mail.kks.yahoo.co.jp with NNFMP; 17 Jun 2022 13:48:52 -0000 Received: from [183.79.101.121] by t504.bullet.mail.kks.yahoo.co.jp with NNFMP; 17 Jun 2022 13:48:51 -0000 Received: from [127.0.0.1] by omp508.mail.kks.yahoo.co.jp with NNFMP; 17 Jun 2022 13:48:51 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 889660.97829.bm@omp508.mail.kks.yahoo.co.jp Received: (qmail 38580 invoked by alias); 17 Jun 2022 13:48:51 -0000 Received: from unknown (HELO ?192.168.2.3?) (175.177.45.169 with ) by smtp6007.mail.ssk.ynwp.yahoo.co.jp with SMTP; 17 Jun 2022 13:48:51 -0000 X-YMail-JAS: WAW5AZMVM1mHICV4mZfv84021PCAj6echWTlPfZL_E4x7.9AbUOmhuunIiKEeX6G4JIvVwij62Yp4TapDNlN2eHBZoGenk2cKKYJbxtuoZyUpHIUtFMyUj12ZfDWuLeDtuFDg6g2MQ-- X-Apparently-From: X-YMail-OSG: Oxu0h0QVM1mLoYcfG69uPH_ozALjHlVqhDYdJg9IM.3KLnT 4IwEgUMaMRMMlbqj_OdFijsQ3lPVLYIzsd.FOc5eMc5fIpOyuj9h_su2rFat RPLWTvJWFkS_rPUMPSDkMETgV7qo1661HA.bZxSMNRG83WXNffvVGM4_ZUxd vSo_Aflt9NYNwr9MmRwZF7u4XWLywYZZGWpvomM06VjEOJu_PhKv0z4JCpKC TP_Jz8xeNMZKCBmRR9ASr1XR5V4EBbEQLvlWgvNMf.sBWhKGpnMFDYAy7200 Vugtwy2ThWuvY3VbmOv53APsYkQm3cjZmB90Dg7Akz.Zx17YG8ttsaw03K02 .pB_rStcEvQf.N78q2UmiFHyM6QEYdKbnmTupHvBWtYFrBLn0mL2w_RObLcL eKsl3PNV_Uf9yGRrytwfb3jpfJa4omeosikI8Ff21a90_reO.h4EyMtvRHNK QrtvoykIjBerLprC.HGrEXX2P49YY1j8X3oeh7ApmtGupmyysXhcA7Qo2IKb uxbkNvlTXUObagsKx4B5IXotSiHv1OwZGTchI2YunCm1yTct0eHLp6yT2r3R TKjSxWFLpm_p6.U._MgnCKWJA7nZ5zzmIn9cz8zXPKbpsOMPTm6mDS4ytA57 aaQftADm7C2JR0_hY14z.LBnvqafgRXV6.zHRB2xjHA_pOW2NZYawCiRmZRP SUJK_VorJdeDvYnBuBZQs9KyQRMWLmGiyB0Y4a7w37HPWBwg64MSEO.bdCf4 P9oxjz1cGdo.GnMTA3zUragMbXBwkFXSZNeFp.tiEoBJo0_MqS6TrjHzuJd0 H86cuSgYfEgbwUpKe_n4IzA1QgHKLKYdkD53imq5V6k3ottPaFmu7VTwIqkS j5raxpz9Zx_h8qv_jSEn0GqFT7UYKTGWGE0kK_gbwXTjKk1rwBMwrpTlS3S5 YmhtPIZnbhfIYKKvzeg-- Message-ID: <17c66d91-37c5-7891-5489-955b4dc8a059@yahoo.co.jp> Date: Fri, 17 Jun 2022 22:47:49 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-US To: GCC Patches Subject: [PATCH] xtensa: Defer storing integer constants into litpool until reload X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Storing integer constants into litpool in the early stage of compilation hinders some integer optimizations. In fact, such integer constants are not subject to the constant folding process. For example: extern unsigned int value; extern void foo(void); void test(void) { if (value == 30001) foo(); } .literal_position .literal .LC0, value .literal .LC1, 30001 test: l32r a3, .LC0 l32r a2, .LC1 l16ui a3, a3, 0 extui a2, a2, 0, 16 // runtime zero-extension despite constant bne a3, a2, .L1 j.l foo, a9 .L1: ret.n This patch defers the placement of integer constants into litpool until the start of reload: .literal_position .literal .LC0, value .literal .LC1, 30001 test: l32r a3, .LC0 l32r a2, .LC1 l16ui a3, a3, 0 bne a3, a2, .L1 j.l foo, a9 .L1: ret.n gcc/ChangeLog: * config/xtensa/constraints.md (Y): Change to include integer constants until reload begins. * config/xtensa/predicates.md (move_operand): Ditto. * config/xtensa/xtensa.cc (xtensa_emit_move_sequence): Change to allow storing integer constants into litpool only after reload begins. --- gcc/config/xtensa/constraints.md | 6 ++++-- gcc/config/xtensa/predicates.md | 5 +++-- gcc/config/xtensa/xtensa.cc | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gcc/config/xtensa/constraints.md b/gcc/config/xtensa/constraints.md index e7ac8dbfebf..0b7dcd1440e 100644 --- a/gcc/config/xtensa/constraints.md +++ b/gcc/config/xtensa/constraints.md @@ -113,8 +113,10 @@ (define_constraint "Y" "A constant that can be used in relaxed MOVI instructions." - (and (match_code "const_int,const_double,const,symbol_ref,label_ref") - (match_test "TARGET_AUTO_LITPOOLS"))) + (ior (and (match_code "const_int,const_double,const,symbol_ref,label_ref") + (match_test "TARGET_AUTO_LITPOOLS")) + (and (match_code "const_int") + (match_test "can_create_pseudo_p ()")))) ;; Memory constraints. Do not use define_memory_constraint here. Doing so ;; causes reload to force some constants into the constant pool, but since diff --git a/gcc/config/xtensa/predicates.md b/gcc/config/xtensa/predicates.md index edd13ae41b9..0590c0f81a9 100644 --- a/gcc/config/xtensa/predicates.md +++ b/gcc/config/xtensa/predicates.md @@ -147,8 +147,9 @@ (match_test "!constantpool_mem_p (op) || GET_MODE_SIZE (mode) % UNITS_PER_WORD == 0"))) (ior (and (match_code "const_int") - (match_test "GET_MODE_CLASS (mode) == MODE_INT - && xtensa_simm12b (INTVAL (op))")) + (match_test "(GET_MODE_CLASS (mode) == MODE_INT + && xtensa_simm12b (INTVAL (op))) + || can_create_pseudo_p ()")) (and (match_code "const_int,const_double,const,symbol_ref,label_ref") (match_test "(TARGET_CONST16 || TARGET_AUTO_LITPOOLS) && CONSTANT_P (op) diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index d6f08b11648..c5d00acdf2c 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -1182,7 +1182,8 @@ xtensa_emit_move_sequence (rtx *operands, machine_mode mode) return 1; } - if (! TARGET_AUTO_LITPOOLS && ! TARGET_CONST16) + if (! TARGET_AUTO_LITPOOLS && ! TARGET_CONST16 + && ! (CONST_INT_P (src) && can_create_pseudo_p ())) { src = force_const_mem (SImode, src); operands[1] = src;