MSP430: Use minimal code size library shift functions when optimizing for size
authorJozef Lawrynowicz <jozef.l@mittosystems.com>
Thu, 6 Jun 2019 12:10:19 +0000 (12:10 +0000)
committerJozef Lawrynowicz <jozefl@gcc.gnu.org>
Thu, 6 Jun 2019 12:10:19 +0000 (12:10 +0000)
gcc/ChangeLog

2019-06-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

* config/msp430/msp430.md (ashlhi3): Use the const_variant of shift
library functions only when not optimizing for size.
(ashlsi3): Likewise.
(ashrhi3): Likewise.
(ashrsi3): Likewise.
(lshrhi3): Likewise.
(lshrsi3): Likewise.

gcc/testsuite/ChangeLog

2019-06-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

* gcc.target/msp430/size-optimized-shifts.c: New test.

From-SVN: r271997

gcc/ChangeLog
gcc/config/msp430/msp430.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/msp430/size-optimized-shifts.c [new file with mode: 0644]

index 012af38d631863087f1ea33c942fbfd723c8fcd6..41e0c17f33c25266311a405e8d44926119973750 100644 (file)
@@ -1,3 +1,13 @@
+2019-06-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
+
+       * config/msp430/msp430.md (ashlhi3): Use the const_variant of shift
+       library functions only when not optimizing for size.
+       (ashlsi3): Likewise.
+       (ashrhi3): Likewise.
+       (ashrsi3): Likewise.
+       (lshrhi3): Likewise.
+       (lshrsi3): Likewise.
+
 2019-06-06  Andreas Krebbel  <krebbel@linux.ibm.com>
 
        PR rtl-optimization/88751
index 58c1f4edc9cf149ab9bf31c464994d24bba63ad1..76296a2f317f31169723abae01017043569d9c0d 100644 (file)
             && INTVAL (operands[2]) == 1)
       emit_insn (gen_slli_1 (operands[0], operands[1]));
     else                
-      msp430_expand_helper (operands, \"__mspabi_slli\", true);
+      /* The const variants of mspabi shifts have larger code size than the
+        generic version, so use the generic version if optimizing for
+        size.  */
+      msp430_expand_helper (operands, \"__mspabi_slli\", !optimize_size);
     DONE;
   }
 )
        (ashift:SI (match_operand:SI 1 "general_operand")
                   (match_operand:SI 2 "general_operand")))]
   ""
-  "msp430_expand_helper (operands, \"__mspabi_slll\", true);
+  "msp430_expand_helper (operands, \"__mspabi_slll\", !optimize_size);
    DONE;"
 )
 
             && INTVAL (operands[2]) == 1)
       emit_insn (gen_srai_1 (operands[0], operands[1]));
     else                
-       msp430_expand_helper (operands, \"__mspabi_srai\", true);
+       msp430_expand_helper (operands, \"__mspabi_srai\", !optimize_size);
    DONE;
    }
 )
        (ashiftrt:SI (match_operand:SI 1 "general_operand")
                     (match_operand:SI 2 "general_operand")))]
   ""
-  "msp430_expand_helper (operands, \"__mspabi_sral\", true);
+  "msp430_expand_helper (operands, \"__mspabi_sral\", !optimize_size);
    DONE;"
 )
 
             && INTVAL (operands[2]) == 1)
       emit_insn (gen_srli_1 (operands[0], operands[1]));
     else                
-      msp430_expand_helper (operands, \"__mspabi_srli\", true);
+      msp430_expand_helper (operands, \"__mspabi_srli\", !optimize_size);
     DONE;
   }
 )
        (lshiftrt:SI (match_operand:SI 1 "general_operand")
                     (match_operand:SI 2 "general_operand")))]
   ""
-  "msp430_expand_helper (operands, \"__mspabi_srll\", true);
+  "msp430_expand_helper (operands, \"__mspabi_srll\", !optimize_size);
    DONE;"
 )
 
index c08d228b613cccd9a61b9b496a38dbb777138c2d..cf8592ae66dea17789f01c3594b2fa1f0e2ed549 100644 (file)
@@ -1,3 +1,7 @@
+2019-06-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
+
+       * gcc.target/msp430/size-optimized-shifts.c: New test.
+
 2019-06-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
        * gcc.target/msp430/emulate-slli.c: New test.
diff --git a/gcc/testsuite/gcc.target/msp430/size-optimized-shifts.c b/gcc/testsuite/gcc.target/msp430/size-optimized-shifts.c
new file mode 100644 (file)
index 0000000..be9509b
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-Os" } */
+/* { dg-final { scan-assembler-not "__mspabi_sral_4" } } */
+/* { dg-final { scan-assembler-not "__mspabi_srll_4" } } */
+/* { dg-final { scan-assembler-not "__mspabi_slll_4" } } */
+/* { dg-final { scan-assembler "__mspabi_sral" } } */
+/* { dg-final { scan-assembler "__mspabi_srll" } } */
+/* { dg-final { scan-assembler "__mspabi_slll" } } */
+
+/* Ensure that SImode shifts by a constant amount do not use the const_variant
+   of the shift library code when optimizing for size.  */
+
+long a;
+long b;
+long c;
+long d;
+unsigned long e;
+unsigned long f;
+
+void
+foo (void)
+{
+  a = b >> 4;
+  c = d << 4;
+  e = f >> 4;
+}