From e609f63d49227ce385316896dde6a476f5f27db7 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
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 <jozef.l@mittosystems.com>
* 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 <jozef.l@mittosystems.com>
* 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
@@ -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])
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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