From patchwork Fri Jul 15 10:50:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 24 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a98:d5ce:0:b0:178:cc93:bf7d with SMTP id g14csp641734eik; Fri, 15 Jul 2022 16:18:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vZAUlXXjzUwT0/zGMUcV8p5B6d94iJt/4icaYaM2G1nIULhet1dja4Sym1/YboK95871Rg X-Received: by 2002:a05:6402:278e:b0:43a:9cf5:6608 with SMTP id b14-20020a056402278e00b0043a9cf56608mr22222256ede.76.1657927106596; Fri, 15 Jul 2022 16:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657927106; cv=none; d=google.com; s=arc-20160816; b=EJwAayWqKMyjwbRft5DQfWurqXSddtvTjHBgMn+y6uVLXk7E8GouxzZVS32HcqrCYS YTghXLSZmbuwExF9Lsr0E+5YnTrEanGDxdy1cT81yXfMyeKmWZJXwBH8xu2HKpAwrmEz nhnYcPVuiJCjxvSMob6TqXcIIiy8pIJAFNy7DT0/pTJfi+yToGkWMyekTlT6/Rl3rkp2 U9KhCv039IpFiG0ml7K8B4KzLATJy814mfriWXnyHAwVrtwO0d7BH2bXGEjuairMq/ux RcL1IdV7z6t/zJy+xo7uxGgcPkx9MTsbxCxTjzdt1UTaaeLWZhvQHL7/I0JIgi9oERSQ zlEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:subject:to:content-language:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=9LKtQv/wuKaVA+1wrAXDjE/nznZz4sLnlXDQ6d1h5ew=; b=AeehOZUOLe9aR0e5lW2xTnlg0cshDQaWGAk0r36gSRPQC/RIrK+9JZ060ocOfnuOoS S348dTE56nIm1dKH5pZYtjaZdGC+d3jS8LvbjbmqgL6q34Q3RBuExkESIvV8eLPtNUa9 ZzDS1Qgd8jZ+m771tADwETJLyHCIhy4CNj0xzyfaNObdA8Ngi7U/FoAG4mgl6vkxefHH m+AdJ9VZ9TmqTPFRH2Bz4i3syHhglbJN9nG4+4b150DdNzIDMi1cSWzIamL6o9UFI83z kHrwu9yR+YIzRbw301DjuBa8DU4qhdkahgFWhbZKRC1z3kt1TtlPSMlPmtEek/GNN6MR SehQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hzr4GKxW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m9-20020a056402430900b00435705f2c71si8714940edc.439.2022.07.15.16.18.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 16:18:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hzr4GKxW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8E053857831 for ; Fri, 15 Jul 2022 23:18:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8E053857831 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657927093; bh=9LKtQv/wuKaVA+1wrAXDjE/nznZz4sLnlXDQ6d1h5ew=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hzr4GKxWqqGivP4AoNFguMV2WVL+r3E56pyN03fR5Gz9ntySdaB/QdgNf+w8HeaKi iVekYiUOX5rU05IDJaHRyKQgO4wv+pe+eRxR/jzhUhzih80FQZziKYwxqmxwA2slyK zNQUkXij50zHy901YjoWBvm2aIIcupN77/1pyQYU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh504-vm2.bullet.mail.kks.yahoo.co.jp (nh504-vm2.bullet.mail.kks.yahoo.co.jp [183.79.57.88]) by sourceware.org (Postfix) with SMTP id 7F2E3385828E for ; Fri, 15 Jul 2022 23:17:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7F2E3385828E Received: from [183.79.100.139] by nh504.bullet.mail.kks.yahoo.co.jp with NNFMP; 15 Jul 2022 23:17:24 -0000 Received: from [183.79.101.123] by t502.bullet.mail.kks.yahoo.co.jp with NNFMP; 15 Jul 2022 23:17:24 -0000 Received: from [127.0.0.1] by omp510.mail.kks.yahoo.co.jp with NNFMP; 15 Jul 2022 23:17:24 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 526804.11545.bm@omp510.mail.kks.yahoo.co.jp Received: (qmail 71180 invoked by alias); 15 Jul 2022 23:17:24 -0000 Received: from unknown (HELO ?192.168.2.4?) (175.177.45.176 with ) by smtp5002.mail.kks.ynwp.yahoo.co.jp with SMTP; 15 Jul 2022 23:17:24 -0000 X-YMail-JAS: UkhJMQMVM1nBecLqoXm6gVYcVNs8uC.cCr9S8xT5q.AwNXnlQhx.hfKcobEVM3ZQr0ZwueycNHboBQWrix9XvhlIGreGTGUg2.mFC0tg3SHWCpnz62wu.n26eEpWPqqKP8C8_DRvSQ-- X-Apparently-From: X-YMail-OSG: 2cKc0XwVM1kfGecVsfoSHw5OXV1fTU0c0WJBAQ4r_Z12fmo EAXrmB4SwBaaL5stfGjpVQN7LtszZOjZN1g1hni4r2p15ZqqrPkyIfDKyaWS O3Qw8gRl6NSPEaOwNZYw8SHx.12RJLvAc180jNvpgD3x4eke1YQx.D.XqhLH S6YytGGLwhbw7sB7f0DQMvVEheV4e7YwSVMJvbomcbbQqEMSSyq0hFyTXQOD WLNYwKvJ_gl85H4Zy5FMeaNhT4eIXw6wT3tg4uhlCxV_bPTMHceDw_Jj6ULj Bxs7dEVUwm9HhAC1VxR6mdI8.Ndj8FSPlC1mHH6JAcrwzsqIrbtIsR2lN78Q 2BdUO.V6Lo7vJ6tx74ta6DuU2JUPfoL8VfI4Hv1ICuD6MDkbX_Ass5Qr3boL h92PP1n0OnXbJJN.x9l1CiU7fSo9Ky33s2PYTNh3eBp5oH8tVHn5dMMRepUR I6Z.l6TJEbZtSo4kDMBvuSRVD0jO9IGe8fIImfvhtYYVeOUb_FvLhYwpBjLM WjTE6waJF2x4n.bRP3l4bOeWMRmEyBKRaNm8Js6yJ_V1AOmcXyGn1nISxBXb SUSdaXmu2.1j93zkkEJGV22tCo1joVaAU9OT..nzLESnbdGrN6BkvpnfMN.4 OpFjZ2kwmx4UzjH7Rv_c_H9xJKN00mG.soX7lQtv0gZBx0CROaCmyNpRSMN7 qnNQGWiDzs.mWz08uHgJDcSELRtdexhZR5PH6wWqdN0lYx8AVCvl7ukLh.7r 0kA0uoLNLvPVGOVSJG5NWDpZXDGkoS6R40Qui8sobh.chRRWZCQTfmhLlWP5 0UBTLY5PLRLb0mmCGQXvuoq98alMdlJp4gyaL_vIGS6jg0dHVuJVwi8oXoVW G0AJEjx3Bk_P1LuQg0gs56xYz0VqUwPGbsM70hHKV2h5gBK5MMidfdBa6_Gm wl8bdDy86Onhnqi6_Yw-- Message-ID: Date: Fri, 15 Jul 2022 19:50:52 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.0.2 Content-Language: en-US To: GCC Patches Subject: [PATCH 1/2] xtensa: constantsynth: Make try to find shorter instruction X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DATE_IN_PAST_12_24, 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 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: "Li, Pan2 via Gcc-patches" Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1738462574048736031?= X-GMAIL-MSGID: =?utf-8?q?1738462574048736031?= This patch allows the constant synthesis to choose shorter instruction if possible. /* example */ int test(void) { return 128 << 8; } ;; before test: movi a2, 0x100 addmi a2, a2, 0x7f00 ret.n ;; after test: movi.n a2, 1 slli a2, a2, 15 ret.n When the Code Density Option is configured, the latter is one byte smaller than the former. gcc/ChangeLog: * config/xtensa/xtensa.cc (xtensa_emit_constantsynth): Remove. (xtensa_constantsynth_2insn): Change to try all three synthetic methods and to use the one that fits the immediate value of the seed into a Narrow Move Immediate instruction "MOVI.N" when the Code Density Option is configured. --- gcc/config/xtensa/xtensa.cc | 58 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index 13f2b2b832c..94337452ba8 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -1035,35 +1035,35 @@ xtensa_split_operand_pair (rtx operands[4], machine_mode mode) load-immediate / arithmetic ones, instead of a L32R instruction (plus a constant in litpool). */ -static void -xtensa_emit_constantsynth (rtx dst, enum rtx_code code, - HOST_WIDE_INT imm0, HOST_WIDE_INT imm1, - rtx (*gen_op)(rtx, HOST_WIDE_INT), - HOST_WIDE_INT imm2) -{ - gcc_assert (REG_P (dst)); - emit_move_insn (dst, GEN_INT (imm0)); - emit_move_insn (dst, gen_rtx_fmt_ee (code, SImode, - dst, GEN_INT (imm1))); - if (gen_op) - emit_move_insn (dst, gen_op (dst, imm2)); -} - static int xtensa_constantsynth_2insn (rtx dst, HOST_WIDE_INT srcval, rtx (*gen_op)(rtx, HOST_WIDE_INT), HOST_WIDE_INT op_imm) { - int shift = exact_log2 (srcval + 1); + HOST_WIDE_INT imm = INT_MAX; + rtx x = NULL_RTX; + int shift; + gcc_assert (REG_P (dst)); + + shift = exact_log2 (srcval + 1); if (IN_RANGE (shift, 1, 31)) { - xtensa_emit_constantsynth (dst, LSHIFTRT, -1, 32 - shift, - gen_op, op_imm); - return 1; + imm = -1; + x = gen_lshrsi3 (dst, dst, GEN_INT (32 - shift)); } - if (IN_RANGE (srcval, (-2048 - 32768), (2047 + 32512))) + + shift = ctz_hwi (srcval); + if ((!x || (TARGET_DENSITY && ! IN_RANGE (imm, -32, 95))) + && xtensa_simm12b (srcval >> shift)) + { + imm = srcval >> shift; + x = gen_ashlsi3 (dst, dst, GEN_INT (shift)); + } + + if ((!x || (TARGET_DENSITY && ! IN_RANGE (imm, -32, 95))) + && IN_RANGE (srcval, (-2048 - 32768), (2047 + 32512))) { HOST_WIDE_INT imm0, imm1; @@ -1076,19 +1076,19 @@ xtensa_constantsynth_2insn (rtx dst, HOST_WIDE_INT srcval, imm0 = srcval - imm1; if (TARGET_DENSITY && imm1 < 32512 && IN_RANGE (imm0, 224, 255)) imm0 -= 256, imm1 += 256; - xtensa_emit_constantsynth (dst, PLUS, imm0, imm1, gen_op, op_imm); - return 1; + imm = imm0; + x = gen_addsi3 (dst, dst, GEN_INT (imm1)); } - shift = ctz_hwi (srcval); - if (xtensa_simm12b (srcval >> shift)) - { - xtensa_emit_constantsynth (dst, ASHIFT, srcval >> shift, shift, - gen_op, op_imm); - return 1; - } + if (!x) + return 0; - return 0; + emit_move_insn (dst, GEN_INT (imm)); + emit_insn (x); + if (gen_op) + emit_move_insn (dst, gen_op (dst, op_imm)); + + return 1; } static rtx From patchwork Fri Jul 15 10:51:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 25 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a98:d5ce:0:b0:178:cc93:bf7d with SMTP id g14csp641735eik; Fri, 15 Jul 2022 16:18:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vhlAH6qH+qxKrfvypSMgH84EYhASTvZJGKaP5G6K6wK8rqciXGKddxL0DZfgkTPhcCqSsN X-Received: by 2002:a17:906:5d04:b0:722:f46c:b891 with SMTP id g4-20020a1709065d0400b00722f46cb891mr16080591ejt.4.1657927106831; Fri, 15 Jul 2022 16:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657927106; cv=none; d=google.com; s=arc-20160816; b=H4OAuNy2d60fWTxmZePrYn+fUPOd7sGczHLonOifvipwnCIy418qsmHx2/YCFalDdT viJdSsoiSwJlZCgj6NMPlUS9S//XSRhIpXNiRyTq1zs84o/uoMNBPvyLysBGohrBhXmw auQXqGTz9JmLiSxDUsxxqUnUjcD+6ZgaP5fZVZ3NLdZ1pLSG3WVqUO+uxA1rnmmWw6cR 7ShsnR+k8YljOYJLme0DZ7uvjreGO5YBYPSoDST/wsHgdB6NW2W5gRZ5jRWSWtw4U0V+ uV5I5uqcKJGs7AYvGxUKmfJJxxnOkTEgJPm4EW9gJSYm1SzhvR4I2Yh1O2xkdsVFr8OF RV9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:subject:to:content-language:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=lg5qYANUUb6PFHQehmEwj31U03hgyyb8X8V8P7l07Pg=; b=kcsUUw2OfZB0SwqVIp+DMDbSugXmC4b3q8SIGByWIuhJ7AegwGxzY+3nuPhKAonNGG V8VT0JCQ2lObGQSCkpSdaDyesc3NWz7BPf31wxkJz431YiZxmniGo/LUUrKihVXGDK0t SHkV+e2Nb37FaCTsRXM3EFnx5Qe+nDv983xtiOwK6pkWZo/WxKNSmHLMO97PfkjpEq0P /SDVJ0dzP28/4xfwDMjLZXO318hsm/SvMv/DlEfgvhCjUuWn8iI0lNQpW3TiaN1MOES8 G+pcflszLNStB7D4IWu0EGtAGTCr416e9Wdv85n08412CgiC+t99uLhHklTQPIfdOncx NgbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ies1m7Mb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g13-20020aa7c84d000000b0043a9ba73187si5947396edt.289.2022.07.15.16.18.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 16:18:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ies1m7Mb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9C05385626C for ; Fri, 15 Jul 2022 23:18:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9C05385626C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657927094; bh=lg5qYANUUb6PFHQehmEwj31U03hgyyb8X8V8P7l07Pg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ies1m7Mbj1AVFqw2gl97mbQEsoGtmMeGi1rUVWmEVdnT6ReHEri7Zl8IoIqLorr5J 23L0vOi+ES91GCg+mYjKILhtzTrcbvfIYsmq3TvyZzfPFC0aysPPyXKAsh1JFUa5y+ L8ingq/DYsB87c8fVq9gwIcln46ict1eGaHDc3yQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh502-vm3.bullet.mail.kks.yahoo.co.jp (nh502-vm3.bullet.mail.kks.yahoo.co.jp [183.79.56.148]) by sourceware.org (Postfix) with SMTP id 0AE0E38582B9 for ; Fri, 15 Jul 2022 23:17:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0AE0E38582B9 Received: from [183.79.100.141] by nh502.bullet.mail.kks.yahoo.co.jp with NNFMP; 15 Jul 2022 23:17:25 -0000 Received: from [183.79.100.133] by t504.bullet.mail.kks.yahoo.co.jp with NNFMP; 15 Jul 2022 23:17:25 -0000 Received: from [127.0.0.1] by omp502.mail.kks.yahoo.co.jp with NNFMP; 15 Jul 2022 23:17:25 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 691971.10102.bm@omp502.mail.kks.yahoo.co.jp Received: (qmail 71185 invoked by alias); 15 Jul 2022 23:17:25 -0000 Received: from unknown (HELO ?192.168.2.4?) (175.177.45.176 with ) by smtp5002.mail.kks.ynwp.yahoo.co.jp with SMTP; 15 Jul 2022 23:17:25 -0000 X-YMail-JAS: 7S.n7mQVM1n1gK6K9KoocZEjJa_K6esif9ZpbyWlDmW8juTXX9k4JgY3wZjY_JM5XJM4SigD82YXFcwaNDd5bXYVaIavv9QrfO9ynusuoFEpYs1_i4ufa1UG1ysmg3H0nKAd1fwlUA-- X-Apparently-From: X-YMail-OSG: bA51jPwVM1lFyzB0LUg5CxRW2HxYQQmlRjHuKPNg3msuU55 _HHb61hFex5JB2uX5kqElmqi2rMPV6UenZxZpdDKzI1sVqUY9IiQ9GdUPmIC .a8sr3FCEMml5K4yCvH5c0.TsOQbhLgcdh8xs0VCto_vxHph1BWv.AtInZI5 8sv03vRWnzpbNBM2OHZHDBTBhZPwZeKUhcdeW5kS9lwM.ch99G7.0vu614ha YV9lP6dhxsNjmKM2BXGBXmHw_ybShuKk0regxvJ5Qr9lE28HZV1LLrpOO3tr dU_DxNzN.BXWp6DEhfmw7sfDpcz6C2bAalrdVj9e_Od8JfmOM9cE3OiaelYw VpkyWXz4XMTXcAwGraMEqk120Pbtv8GUo137Fc.fHAuys2rN5zXfB8M9rXRG NWp_SQQNVljyQtnuttjTrU.AQets2v0G._GGUfMrdGUvLigwPn3d.RG05zI3 1r1dnGRFh7s01Qahsb1bN2_te925gFNadk_hxQ5zMUzQeTvyYW2eZBZ1NuMz gcIPZBQMHoQwT_yr87AX_E0XQEkHsLdf_lQIOLuZvo2ofc.slJFpK_ICfXX6 UcIVQn8zbvEoouD4_9PuwZdANy2cjIxh24JHk800zebMZ878a0KTPrGSWKdN lwtjpp4BB0r9GxUKqMSln8pkDz23dHhUQj2wxQAPKYFMYiw58aO4yYpbvo8O h83L8vlfP1oj8gs5LPaG3AWcjs1YJrlmpgJkbb9NbG3Ti6ljvalK_Hzx16dN sx4BZjgun5vuaWmly7vgpYGujpJf5gnrQx5lQk5hBa0xrxKeQ6qVuDR7REZV DsBv_nl2v1VSZJZ6Bi_lt_WtND6CkFgxzIMkMKUwJYCVicp8cHKMIo02RU0x fcpkdf_8naqvdeYsQeZv1oTNR17AjxGnpNsWcKyXPjXs644yhA_6WxVkzCH_ t3IiEbS6dCKgFuV95Dg-- Message-ID: <0e1e513e-414f-20a6-3332-48ab90bbd371@yahoo.co.jp> Date: Fri, 15 Jul 2022 19:51:40 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.0.2 Content-Language: en-US To: GCC Patches Subject: [PATCH 2/2] xtensa: Optimize "bitwise AND with imm1" followed by "branch if (not) equal to imm2" X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DATE_IN_PAST_12_24, 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 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: "Li, Pan2 via Gcc-patches" Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1738462573916929620?= X-GMAIL-MSGID: =?utf-8?q?1738462573916929620?= This patch enhances the effectiveness of the previously posted one: "xtensa: Optimize bitwise AND operation with some specific forms of constants". /* example */ extern void foo(int); void test(int a) { if ((a & (-1U << 8)) == (128 << 8)) /* 0 or one of "b4const" */ foo(a); } ;; before .global test test: movi a3, -0x100 movi.n a4, 1 and a3, a2, a3 slli a4, a4, 15 bne a3, a4, .L3 j.l foo, a9 .L1: ret.n ;; after .global test test: srli a3, a2, 8 bnei a3, 128, .L1 j.l foo, a9 .L1: ret.n gcc/ChangeLog: * config/xtensa/xtensa.md (*masktrue_const_pow2_minus_one, *masktrue_const_negative_pow2, *masktrue_const_shifted_mask): If the immediate for bitwise AND is represented as '-(1 << N)', decrease the lower bound of N from 12 to 1. And the other immediate for conditional branch is now no longer limited to zero, but also one of some positive integers. Finally, remove the checks of some conditions, because the comparison expressions that don't satisfy such checks are determined as compile-time constants and thus will be optimized away before RTL expansion. --- gcc/config/xtensa/xtensa.md | 73 ++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index 6a58d3e2776..c02f1a56641 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -1716,63 +1716,78 @@ (define_insn_and_split "*masktrue_const_pow2_minus_one" [(set (pc) - (if_then_else (match_operator 3 "boolean_operator" + (if_then_else (match_operator 4 "boolean_operator" [(and:SI (match_operand:SI 0 "register_operand" "r") (match_operand:SI 1 "const_int_operand" "i")) - (const_int 0)]) - (label_ref (match_operand 2 "" "")) + (match_operand:SI 2 "const_int_operand" "i")]) + (label_ref (match_operand 3 "" "")) (pc)))] - "IN_RANGE (exact_log2 (INTVAL (operands[1]) + 1), 17, 31)" + "IN_RANGE (exact_log2 (INTVAL (operands[1]) + 1), 17, 31) + /* && (~INTVAL (operands[1]) & INTVAL (operands[2])) == 0 // can be omitted */ + && xtensa_b4const_or_zero (INTVAL (operands[2]) << (32 - floor_log2 (INTVAL (operands[1]) + 1)))" "#" "&& can_create_pseudo_p ()" - [(set (match_dup 4) + [(set (match_dup 5) (ashift:SI (match_dup 0) (match_dup 1))) (set (pc) - (if_then_else (match_op_dup 3 - [(match_dup 4) - (const_int 0)]) - (label_ref (match_dup 2)) + (if_then_else (match_op_dup 4 + [(match_dup 5) + (match_dup 2)]) + (label_ref (match_dup 3)) (pc)))] { - operands[1] = GEN_INT (32 - floor_log2 (INTVAL (operands[1]) + 1)); - operands[4] = gen_reg_rtx (SImode); + int shift = 32 - floor_log2 (INTVAL (operands[1]) + 1); + operands[1] = GEN_INT (shift); + operands[2] = GEN_INT (INTVAL (operands[2]) << shift); + operands[5] = gen_reg_rtx (SImode); } [(set_attr "type" "jump") (set_attr "mode" "none") (set (attr "length") - (if_then_else (match_test "TARGET_DENSITY - && INTVAL (operands[1]) == 0x7FFFFFFF") - (const_int 5) - (const_int 6)))]) + (if_then_else (match_test "(TARGET_DENSITY && INTVAL (operands[1]) == 0x7FFFFFFF) + && INTVAL (operands[2]) == 0") + (const_int 4) + (if_then_else (match_test "TARGET_DENSITY + && (INTVAL (operands[1]) == 0x7FFFFFFF + || INTVAL (operands[2]) == 0)") + (const_int 5) + (const_int 6))))]) (define_insn_and_split "*masktrue_const_negative_pow2" [(set (pc) - (if_then_else (match_operator 3 "boolean_operator" + (if_then_else (match_operator 4 "boolean_operator" [(and:SI (match_operand:SI 0 "register_operand" "r") (match_operand:SI 1 "const_int_operand" "i")) - (const_int 0)]) - (label_ref (match_operand 2 "" "")) + (match_operand:SI 2 "const_int_operand" "i")]) + (label_ref (match_operand 3 "" "")) (pc)))] - "IN_RANGE (exact_log2 (-INTVAL (operands[1])), 12, 30)" + "IN_RANGE (exact_log2 (-INTVAL (operands[1])), 1, 30) + /* && (~INTVAL (operands[1]) & INTVAL (operands[2])) == 0 // can be omitted */ + && xtensa_b4const_or_zero (INTVAL (operands[2]) >> floor_log2 (-INTVAL (operands[1])))" "#" "&& can_create_pseudo_p ()" - [(set (match_dup 4) + [(set (match_dup 5) (lshiftrt:SI (match_dup 0) (match_dup 1))) (set (pc) - (if_then_else (match_op_dup 3 - [(match_dup 4) - (const_int 0)]) - (label_ref (match_dup 2)) + (if_then_else (match_op_dup 4 + [(match_dup 5) + (match_dup 2)]) + (label_ref (match_dup 3)) (pc)))] { - operands[1] = GEN_INT (floor_log2 (-INTVAL (operands[1]))); - operands[4] = gen_reg_rtx (SImode); + int shift = floor_log2 (-INTVAL (operands[1])); + operands[1] = GEN_INT (shift); + operands[2] = GEN_INT (INTVAL (operands[2]) >> shift); + operands[5] = gen_reg_rtx (SImode); } [(set_attr "type" "jump") (set_attr "mode" "none") - (set_attr "length" "6")]) + (set (attr "length") + (if_then_else (match_test "TARGET_DENSITY && INTVAL (operands[2]) == 0") + (const_int 5) + (const_int 6)))]) (define_insn_and_split "*masktrue_const_shifted_mask" [(set (pc) @@ -1782,8 +1797,8 @@ (match_operand:SI 2 "const_int_operand" "i")]) (label_ref (match_operand 3 "" "")) (pc)))] - "(INTVAL (operands[2]) & ((1 << ctz_hwi (INTVAL (operands[1]))) - 1)) == 0 - && xtensa_b4const_or_zero ((uint32_t)INTVAL (operands[2]) >> ctz_hwi (INTVAL (operands[1])))" + "/* (INTVAL (operands[2]) & ((1 << ctz_hwi (INTVAL (operands[1]))) - 1)) == 0 // can be omitted + && */ xtensa_b4const_or_zero ((uint32_t)INTVAL (operands[2]) >> ctz_hwi (INTVAL (operands[1])))" "#" "&& can_create_pseudo_p ()" [(set (match_dup 6)