From patchwork Thu Mar 9 12:09:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 66823 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp251745wrd; Thu, 9 Mar 2023 04:10:46 -0800 (PST) X-Google-Smtp-Source: AK7set9NnDN6AJ0G122S2NnrACXDYTd0RzPKlxJF2oEKbB6jhXqTGlJL2CJimV7pNoID8Svug/OE X-Received: by 2002:a17:907:7fa7:b0:8d7:6699:3bae with SMTP id qk39-20020a1709077fa700b008d766993baemr25708045ejc.57.1678363846261; Thu, 09 Mar 2023 04:10:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678363846; cv=none; d=google.com; s=arc-20160816; b=pFXgnN5k2WtFo0pPhEsPfa6zx2pMG11lwjinOj9fbVDc23aVsmlmy8gpB0MkcHC+sK WO1moGvbWyJ2Zupwd/XPFJc0p+ywUTSTqI7x+WUJt6XSBAry16YDKtiIgEChXT4K7N4j 7RW+9f8k58n7kxfuWIrk4hQ73Co4gOxBNeOe0llZcNWFBzceMcErbU7U+h0pkAXaFBZc kUpmPY+tS4cku/bdjD7bELOUa5P3t4qF/DdhlI5sEkkN6rdranyZRA2k9kbydPT6M+67 vVzZtKKaBAjvH6eELSn4uYKxQZon69x0mZjjoaVAN2ub+0+87qTJ4DEaearVcelSTwen ZiyA== 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:mime-version :user-agent:message-id:in-reply-to:date:references:subject:cc :mail-followup-to:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=T+ycLooeOpXMPuqKfHIjGZoFyYghpMQIk+6ZKUZ6lTI=; b=jR1MHCw8kxRVJ/QRn0Yi14eKlt/J4tGqFFAtKsNVcQ32eYbK1sruRE7iEA1luBOS7K R1GjJqgRI/3Ds1sAnksbnVZouOJcfsbIKr+17pVFgf0aCjRNldB29d84hNThIc5/Gh4o cGOQYBXNcsbK3QoIB7Oid7CW3vHkF5Ua69EX2jfADsiL7ugonFbrcRiD//WjllVm4B2G mCsHD7Belr2MLF1REFsTWMdHz5eHoyh6dcLoh9RzZmpH7ueiuotSpQiiJQGCFYPvPozj cpaKPClb91scsAi36wtxDItPjdhrLXhxvh0TWx7Wxw44f49CuOoBTTD8mcyKKYe2ajQC V4xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ikuQSt8e; 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 a13-20020a1709065f8d00b008c03cbdabb3si1195720eju.477.2023.03.09.04.10.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 04:10:46 -0800 (PST) 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=ikuQSt8e; 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 52EA53858C74 for ; Thu, 9 Mar 2023 12:10:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 52EA53858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678363845; bh=T+ycLooeOpXMPuqKfHIjGZoFyYghpMQIk+6ZKUZ6lTI=; h=To:Cc:Subject:References:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ikuQSt8eVBqfMr38yuZRJWW+pgEuDG5oGiCN1QO73KXrLaxjJRetWxeen6GbQTBAt wkFPyTKeOJ5fuwrjDyaceP05hHDi7GR+9lphYGuPBH8oEn+qpVLyYgfVIv0j4TFHtV doPAbU/3T5sJ13JZWC3Ls+OOgRJsOnwy/Cql5c0g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id B98093858D33 for ; Thu, 9 Mar 2023 12:10:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B98093858D33 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C2FC44B3; Thu, 9 Mar 2023 04:10:44 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D06363F67D; Thu, 9 Mar 2023 04:10:00 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, segher@kernel.crashing.org, richard.sandiford@arm.com Cc: segher@kernel.crashing.org Subject: [PATCH v2 1/2] combine: Split code out of make_compound_operation_int References: Date: Thu, 09 Mar 2023 12:09:59 +0000 In-Reply-To: (Richard Sandiford's message of "Thu, 09 Mar 2023 12:08:33 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-33.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, 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: Richard Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford 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?1759892048525472054?= X-GMAIL-MSGID: =?utf-8?q?1759892048525472054?= This patch just splits some code out of make_compound_operation_int into a new function called make_compound_operation_and. It is a prerequisite for the fix for PR106594. It might (or might not) make sense to put more of the existing "and" handling into the new function, so that the subreg+lshiftrt case can be handled through recursion rather than duplication. But that's certainly not necessary to fix the bug, so is at best stage 1 material. No behavioural change intended. gcc/ * combine.cc (make_compound_operation_and): New function, split out from... (make_compound_operation_int): ...here. --- gcc/combine.cc | 84 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/gcc/combine.cc b/gcc/combine.cc index 053879500b7..7d446d02cb4 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -7952,6 +7952,56 @@ extract_left_shift (scalar_int_mode mode, rtx x, int count) return 0; } +/* A subroutine of make_compound_operation_int. Try to combine an outer + AND of X and MASK with a partnering inner operation to form a compound + operation. Return the new X on success, otherwise return null. + + MODE is the mode of X. IN_CODE is as for make_compound_operation. + NEXT_CODE is the value of IN_CODE that should be used for (recursive) + calls to make_compound_operation. */ + +static rtx +make_compound_operation_and (scalar_int_mode mode, rtx x, + unsigned HOST_WIDE_INT mask, + rtx_code in_code, rtx_code next_code) +{ + switch (GET_CODE (x)) + { + case SUBREG: + /* If the operand is a paradoxical subreg of a register or memory + and MASK (limited to the smaller mode) has only zero bits where + the sub expression has known zero bits, this can be expressed as + a zero_extend. */ + { + rtx sub = XEXP (x, 0); + machine_mode sub_mode = GET_MODE (sub); + int sub_width; + if ((REG_P (sub) || MEM_P (sub)) + && GET_MODE_PRECISION (sub_mode).is_constant (&sub_width) + && sub_width < GET_MODE_PRECISION (mode)) + { + unsigned HOST_WIDE_INT mode_mask = GET_MODE_MASK (sub_mode); + unsigned HOST_WIDE_INT submask; + + /* The shifted AND constant with all the known zero + bits set. */ + submask = mask | ~nonzero_bits (sub, sub_mode); + if ((submask & mode_mask) == mode_mask) + { + rtx new_rtx = make_compound_operation (sub, next_code); + return make_extraction (mode, new_rtx, 0, 0, sub_width, + 1, 0, in_code == COMPARE); + } + } + break; + } + + default: + break; + } + return NULL_RTX; +} + /* Subroutine of make_compound_operation. *X_PTR is the rtx at the current level of the expression and MODE is its mode. IN_CODE is as for make_compound_operation. *NEXT_CODE_PTR is the value of IN_CODE @@ -8184,36 +8234,10 @@ make_compound_operation_int (scalar_int_mode mode, rtx *x_ptr, make_compound_operation (XEXP (x, 0), next_code), i, NULL_RTX, 1, 1, 0, 1); - - /* If the one operand is a paradoxical subreg of a register or memory and - the constant (limited to the smaller mode) has only zero bits where - the sub expression has known zero bits, this can be expressed as - a zero_extend. */ - else if (GET_CODE (XEXP (x, 0)) == SUBREG) - { - rtx sub; - - sub = XEXP (XEXP (x, 0), 0); - machine_mode sub_mode = GET_MODE (sub); - int sub_width; - if ((REG_P (sub) || MEM_P (sub)) - && GET_MODE_PRECISION (sub_mode).is_constant (&sub_width) - && sub_width < mode_width) - { - unsigned HOST_WIDE_INT mode_mask = GET_MODE_MASK (sub_mode); - unsigned HOST_WIDE_INT mask; - - /* original AND constant with all the known zero bits set */ - mask = UINTVAL (XEXP (x, 1)) | (~nonzero_bits (sub, sub_mode)); - if ((mask & mode_mask) == mode_mask) - { - new_rtx = make_compound_operation (sub, next_code); - new_rtx = make_extraction (mode, new_rtx, 0, 0, sub_width, - 1, 0, in_code == COMPARE); - } - } - } - + else + new_rtx = make_compound_operation_and (mode, XEXP (x, 0), + UINTVAL (XEXP (x, 1)), + in_code, next_code); break; case LSHIFTRT: From patchwork Thu Mar 9 12:10:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 66824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp252124wrd; Thu, 9 Mar 2023 04:11:37 -0800 (PST) X-Google-Smtp-Source: AK7set+43XXTMhZQCoyd55iWWZtEhrGSAnruHkzyALUVItltbc71Q5yY5pHWy+xU5DxC4WQMq5Z/ X-Received: by 2002:a17:907:94c6:b0:8b1:2c37:ae97 with SMTP id dn6-20020a17090794c600b008b12c37ae97mr24511869ejc.43.1678363897165; Thu, 09 Mar 2023 04:11:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678363897; cv=none; d=google.com; s=arc-20160816; b=TIyMKNEPBcrEtoogGqoCy4P0CsNhc47BKuxZfh/N8or3mLcbjK46giTKkqtbBfb0YD NydGg/OzbTeJXAPPjh8TzF4vWKqMBPaO3FIBrgXG1jPr9Y/Y1rv1ndWAVUBxDht3RDOH +lwrEhUKAf0eXxQ4KurK4p/hnAuJCivesKOD8P4WzDBAUdn9RtKJtA54AvVL19u7F90w NycVz/wSrFJZU0p94IYW+W7v+sbIuSXgdsI4LBoDwF1X9tlplASVJ2uBgRJXBHTK1d68 4x8Uuahhm7/ipbHsKC2XgMtUPLho0F0x5Z3V/uJZV7m6DQvFgIPyXEIIlMqftorvhioj nUhQ== 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:mime-version :user-agent:message-id:in-reply-to:date:references:subject:cc :mail-followup-to:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=zR30jfDn7k9288H6eSCcnjTClomdntGEOhhbQPZBscM=; b=mv3qyZog0lDcCCllmTYuEY5ZHBb0mez/7ZUgQlEbBcnoJxJ9Us7BJt12blKnuupAq0 j1n/CDI1r9wIegMcEwnLRuExFXoyc66fqzjfjQDqLlTSfTs22e2Uz47Gb6gsIgFH4rpk r4luq89WyK+pDcWbDZx1fmIgkdpV5qzkR1ALnjuXhy6uoLmYAKorqmKg9KlmEQzMATOe aIvRRbwqMb9B77ViKWHmQHnimVsNx6VorXudHpYatJQXf9e5uHHUW8DpSttBC2jiJXlH wMlj72/8eLqTUzkzEeQNKMSqm/B3caH8VWIYJOkDwh8KixL/c/IBVY4ujXGk44EeR9Je eU/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="qU/lrz1B"; 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 my36-20020a1709065a6400b008d6ae2337c4si3511647ejc.128.2023.03.09.04.11.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 04:11:37 -0800 (PST) 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="qU/lrz1B"; 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 E47403858CDB for ; Thu, 9 Mar 2023 12:11:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E47403858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678363895; bh=zR30jfDn7k9288H6eSCcnjTClomdntGEOhhbQPZBscM=; h=To:Cc:Subject:References:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=qU/lrz1Bvg12yKo2jiA9+qLpP03n0TY+oZXJTUPKWQ8Jhb/0arfpy6X6/L0s9IlAL dJi0mr1dgZzRJC/kEbG5LRKUk6mAdYXHATVfCwuJY4n9UQFQz4UYUKuwyGiW7bsjF5 mhK7EAtiPlMSma/4pfYrFvfHFtYy6Kmr3iz5qUZI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id F3BB23858002 for ; Thu, 9 Mar 2023 12:10:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3BB23858002 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 352934B3; Thu, 9 Mar 2023 04:11:36 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4230C3F67D; Thu, 9 Mar 2023 04:10:52 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, segher@kernel.crashing.org, richard.sandiford@arm.com Cc: segher@kernel.crashing.org Subject: [PATCH v2 2/2] combine: Try harder to form zero_extends [PR106594] References: Date: Thu, 09 Mar 2023 12:10:51 +0000 In-Reply-To: (Richard Sandiford's message of "Thu, 09 Mar 2023 12:08:33 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-33.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, 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: Richard Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford 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?1759892102011118093?= X-GMAIL-MSGID: =?utf-8?q?1759892102011118093?= g:c23a9c87cc62bd177fd0d4db6ad34b34e1b9a31f uses nonzero_bits information to convert sign_extends into zero_extends. That change is semantically correct in itself, but for the testcase in the PR, it leads to a series of unfortunate events, as described below. We try to combine: Trying 24 -> 25: 24: r116:DI=sign_extend(r115:SI) REG_DEAD r115:SI 25: r117:SI=[r116:DI*0x4+r118:DI] REG_DEAD r116:DI REG_EQUAL [r116:DI*0x4+`constellation_64qam'] which previously succeeded, giving: (set (reg:SI 117 [ constellation_64qam[_5] ]) (mem/u:SI (plus:DI (mult:DI (sign_extend:DI (reg:SI 115)) (const_int 4 [0x4])) (reg/f:DI 118)) [1 constellation_64qam[_5]+0 S4 A32])) However, nonzero_bits can tell that only the low 6 bits of r115 can be nonzero. The commit above therefore converts the sign_extend to a zero_extend. Using the same nonzero_bits information, we then "expand" the zero_extend to: (and:DI (subreg:DI (reg:SI r115) 0) (const_int 63)) Substituting into the mult gives the unsimplified expression: (mult:DI (and:DI (subreg:DI (reg:SI r115) 0) (const_int 63)) (const_int 4)) The simplification rules for mult convert this to an ashift by 2. Then, this rule in simplify_shift_const_1: /* If we have (shift (logical)), move the logical to the outside to allow it to possibly combine with another logical and the shift to combine with another shift. This also canonicalizes to what a ZERO_EXTRACT looks like. Also, some machines have (and (shift)) insns. */ moves the shift inside the "and", so that the expression becomes: (and:DI (ashift:DI (subreg:DI (reg:SI r115) 0) (const_int 2)) (const_int 252)) We later recanonicalise to a mult (since this is an address): (and:DI (mult:DI (subreg:DI (reg:SI r115) 0) (const_int 4)) (const_int 252)) But we fail to transform this back to the natural substitution: (mult:DI (zero_extend:DI (reg:SI r115)) (const_int 4)) There are several other cases in which make_compound_operation needs to look more than one level down in order to complete a compound operation. For example: (a) the ashiftrt handling uses extract_left_shift to look through things like logic ops in order to find a partnering ashift operation (b) the "and" handling looks through subregs, xors and iors to find a partnerning lshiftrt This patch takes the same approach for mult. gcc/ PR rtl-optimization/106594 * combine.cc (make_compound_operation_and): Look through multiplications by a power of two. gcc/testsuite/ * gcc.target/aarch64/pr106594.c: New test. --- gcc/combine.cc | 17 +++++++++++++++++ gcc/testsuite/gcc.target/aarch64/pr106594.c | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/pr106594.c diff --git a/gcc/combine.cc b/gcc/combine.cc index 7d446d02cb4..36d04ad6703 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -7996,6 +7996,23 @@ make_compound_operation_and (scalar_int_mode mode, rtx x, break; } + case MULT: + /* Recurse through a power of 2 multiplication (as can be found + in an address), using the relationship: + + (and (mult X 2**N1) N2) == (mult (and X (lshifrt N2 N1)) 2**N1). */ + if (CONST_INT_P (XEXP (x, 1)) + && pow2p_hwi (INTVAL (XEXP (x, 1)))) + { + int shift = exact_log2 (INTVAL (XEXP (x, 1))); + rtx sub = make_compound_operation_and (mode, XEXP (x, 0), + mask >> shift, in_code, + next_code); + if (sub) + return gen_rtx_MULT (mode, sub, XEXP (x, 1)); + } + break; + default: break; } diff --git a/gcc/testsuite/gcc.target/aarch64/pr106594.c b/gcc/testsuite/gcc.target/aarch64/pr106594.c new file mode 100644 index 00000000000..beda8e050a5 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr106594.c @@ -0,0 +1,20 @@ +/* { dg-options "-O2" } */ + +extern const int constellation_64qam[64]; + +void foo(int nbits, + const char *p_src, + int *p_dst) { + + while (nbits > 0U) { + char first = *p_src++; + + char index1 = ((first & 0x3) << 4) | (first >> 4); + + *p_dst++ = constellation_64qam[index1]; + + nbits--; + } +} + +/* { dg-final { scan-assembler {ldr\tw[0-9]+, \[x[0-9]+, w[0-9]+, [su]xtw #?2\]} } } */