From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 60810 invoked by alias); 4 Jun 2019 13:11:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 60801 invoked by uid 89); 4 Jun 2019 13:11:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-wm1-f47.google.com Received: from mail-wm1-f47.google.com (HELO mail-wm1-f47.google.com) (209.85.128.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Jun 2019 13:11:42 +0000 Received: by mail-wm1-f47.google.com with SMTP id g135so11633289wme.4 for ; Tue, 04 Jun 2019 06:11:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mittosystems.com; s=google; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version; bh=s8cQLMnjOBho+WZWI8ebY5dN6A9QZw2gjvbyYV01dRM=; b=JifwipKRKlcKGSfTyzJ1r5sfPZCGFIsd/CYS3dR+WUkIoxnIy3ffIcHG3K0f3T7PIF KYzgKWHjS4SQDy7bxYffnagCFByIXVSK8Ow6rYfeUK2IDJT6Z/u7DHtiaoLyFXkuLRA6 OHGbTVrKjufFocIf+AL7j0RsU/XHLJryHa4Lm2dpXuTJ6yZAHZQu+dIrqLg4Ttx5AsBC IQ7V2jVOrgOlnkJDHi/eqQ/rjh6Y6DZS/iQLksEsgCeH61i96Bq4sr/VFGcNs7loWesQ NGZ1zL16w97Bfw25K4aLhQaiCqsOvd3b+hY4N8CMIFSxHlkxiNdYFSTdiMmDPowXWMwh mNpQ== Return-Path: Received: from jozef-kubuntu ([2a01:4b00:87fd:900:5c4d:209e:5b9a:8189]) by smtp.gmail.com with ESMTPSA id e17sm4553071wrt.95.2019.06.04.06.11.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 06:11:40 -0700 (PDT) Date: Tue, 04 Jun 2019 13:11:00 -0000 From: Jozef Lawrynowicz To: gcc-patches@gcc.gnu.org Cc: "nickc@redhat.com" Subject: [PATCH][MSP430][2/4] Emulate 16-bit shifts with rotate insn when src operand is originally in memory Message-ID: <20190604141138.061f7e8f@jozef-kubuntu> In-Reply-To: <20190604140329.5c4e1629@jozef-kubuntu> References: <20190604140329.5c4e1629@jozef-kubuntu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/OBWIX494N6r73jlRFCxi9wd" X-IsSubscribed: yes X-SW-Source: 2019-06/txt/msg00165.txt.bz2 --MP_/OBWIX494N6r73jlRFCxi9wd Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 609 This patch reduces code size by enabling the emulation of some 16-bit shift instructions with the native rotate instructions, when the source operand is in memory. This is achieved by forcing the source operand into a register. For the following program, the below code size reduction is observed: int a; int main (void) { a = a << 4; return 0; } With shift patch 1: text data bss dec hex filename 484 12 20 516 204 a.out With new patch: text data bss dec hex filename 452 12 20 484 1e4 a.out Ok for trunk? --MP_/OBWIX494N6r73jlRFCxi9wd Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0002-MSP430-Force-the-src-operand-of-a-HImode-shift-into-.patch Content-length: 4310 >From e609f63d49227ce385316896dde6a476f5f27db7 Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Mon, 13 May 2019 17:48:00 +0100 Subject: [PATCH 2/4] MSP430: Force the src operand of a HImode shift into a register if it is in memory gcc/ChangeLog 2019-06-04 Jozef Lawrynowicz * config/msp430/msp430.md (ashlhi3): Force shift src operand into a register if it is in memory, so the shift can be emulated with a rotate instruction. (ashrhi3): Likewise. (lshrhi3): Likewise. gcc/testsuite/ChangeLog 2019-06-04 Jozef Lawrynowicz * gcc.target/msp430/emulate-slli.c: New test. * gcc.target/msp430/emulate-srai.c: New test. * gcc.target/msp430/emulate-srli.c: New test. --- gcc/config/msp430/msp430.md | 15 +++++++++------ gcc/testsuite/gcc.target/msp430/emulate-slli.c | 15 +++++++++++++++ gcc/testsuite/gcc.target/msp430/emulate-srai.c | 15 +++++++++++++++ gcc/testsuite/gcc.target/msp430/emulate-srli.c | 15 +++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.target/msp430/emulate-slli.c create mode 100644 gcc/testsuite/gcc.target/msp430/emulate-srai.c create mode 100644 gcc/testsuite/gcc.target/msp430/emulate-srli.c diff --git a/gcc/config/msp430/msp430.md b/gcc/config/msp430/msp430.md index 344d21d9378..58c1f4edc9c 100644 --- a/gcc/config/msp430/msp430.md +++ b/gcc/config/msp430/msp430.md @@ -756,8 +756,9 @@ (match_operand:HI 2 "general_operand")))] "" { - if (GET_CODE (operands[1]) == SUBREG - && REG_P (XEXP (operands[1], 0))) + if ((GET_CODE (operands[1]) == SUBREG + && REG_P (XEXP (operands[1], 0))) + || MEM_P (operands[1])) operands[1] = force_reg (HImode, operands[1]); if (msp430x && REG_P (operands[0]) @@ -828,8 +829,9 @@ (match_operand:HI 2 "general_operand")))] "" { - if (GET_CODE (operands[1]) == SUBREG - && REG_P (XEXP (operands[1], 0))) + if ((GET_CODE (operands[1]) == SUBREG + && REG_P (XEXP (operands[1], 0))) + || MEM_P (operands[1])) operands[1] = force_reg (HImode, operands[1]); if (msp430x && REG_P (operands[0]) @@ -916,8 +918,9 @@ (match_operand:HI 2 "general_operand")))] "" { - if (GET_CODE (operands[1]) == SUBREG - && REG_P (XEXP (operands[1], 0))) + if ((GET_CODE (operands[1]) == SUBREG + && REG_P (XEXP (operands[1], 0))) + || MEM_P (operands[1])) operands[1] = force_reg (HImode, operands[1]); if (msp430x && REG_P (operands[0]) diff --git a/gcc/testsuite/gcc.target/msp430/emulate-slli.c b/gcc/testsuite/gcc.target/msp430/emulate-slli.c new file mode 100644 index 00000000000..0ed09d55d8c --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/emulate-slli.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-Os" } */ +/* { dg-final { scan-assembler-not "mspabi_slli" } } */ +/* { dg-final { scan-assembler "rlax" } } */ + +/* Ensure that HImode shifts with source operand in memory are emulated with a + rotate instructions. */ + +int a; + +void +foo (void) +{ + a = a << 4; +} diff --git a/gcc/testsuite/gcc.target/msp430/emulate-srai.c b/gcc/testsuite/gcc.target/msp430/emulate-srai.c new file mode 100644 index 00000000000..66291717a02 --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/emulate-srai.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-Os" } */ +/* { dg-final { scan-assembler-not "mspabi_srai" } } */ +/* { dg-final { scan-assembler "rrax" } } */ + +/* Ensure that HImode shifts with source operand in memory are emulated with a + rotate instructions. */ + +int a; + +void +foo (void) +{ + a = a >> 4; +} diff --git a/gcc/testsuite/gcc.target/msp430/emulate-srli.c b/gcc/testsuite/gcc.target/msp430/emulate-srli.c new file mode 100644 index 00000000000..c10f30b2779 --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/emulate-srli.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-Os" } */ +/* { dg-final { scan-assembler-not "mspabi_srli" } } */ +/* { dg-final { scan-assembler "rrum" } } */ + +/* Ensure that HImode shifts with source operand in memory are emulated with a + rotate instructions. */ + +unsigned int a; + +void +foo (void) +{ + a = a >> 4; +} -- 2.17.1 --MP_/OBWIX494N6r73jlRFCxi9wd--