[AArch64] Split X-reg UBFIZ into W-reg LSL when possible
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Fri, 16 Dec 2016 16:26:08 +0000 (16:26 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Fri, 16 Dec 2016 16:26:08 +0000 (16:26 +0000)
* config/aarch64/aarch64.md: New define_split above bswap<mode>2.

* gcc.target/aarch64/ubfiz_lsl_1.c: New test.

From-SVN: r243756

gcc/ChangeLog
gcc/config/aarch64/aarch64.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/ubfiz_lsl_1.c [new file with mode: 0644]

index d7f39fcb05e6e4fffeb334ecd99673ff62f5f658..9aecfdc9d9409c2791329caef6692cbadae4a1b0 100644 (file)
@@ -1,3 +1,7 @@
+2016-12-16  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * config/aarch64/aarch64.md: New define_split above bswap<mode>2.
+
 2016-12-16  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        * config/aarch64/aarch64.md: New define_split above insv<mode>.
index 078bd8e69a0ebf6dbc94dab33d9eb494ec9154eb..6d89e31fdebb8588fc789e264b31e3dde25f558b 100644 (file)
   [(set_attr "type" "bfx")]
 )
 
+;; When the bit position and width of the equivalent extraction add up to 32
+;; we can use a W-reg LSL instruction taking advantage of the implicit
+;; zero-extension of the X-reg.
+(define_split
+  [(set (match_operand:DI 0 "register_operand")
+       (and:DI (ashift:DI (match_operand:DI 1 "register_operand")
+                            (match_operand 2 "const_int_operand"))
+                (match_operand 3 "const_int_operand")))]
+ "aarch64_mask_and_shift_for_ubfiz_p (DImode, operands[3], operands[2])
+  && (INTVAL (operands[2]) + popcount_hwi (INTVAL (operands[3])))
+      == GET_MODE_BITSIZE (SImode)"
+  [(set (match_dup 0)
+       (zero_extend:DI (ashift:SI (match_dup 4) (match_dup 2))))]
+  {
+    operands[4] = gen_lowpart (SImode, operands[1]);
+  }
+)
+
 (define_insn "bswap<mode>2"
   [(set (match_operand:GPI 0 "register_operand" "=r")
         (bswap:GPI (match_operand:GPI 1 "register_operand" "r")))]
index fc73346906ce72c8d6785743dd21af6eda4b6ed5..30f89311da84ab9edaabdf3919d1183bd180dc6a 100644 (file)
@@ -1,3 +1,7 @@
+2016-12-16  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * gcc.target/aarch64/ubfiz_lsl_1.c: New test.
+
 2016-12-16  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        * gcc.target/aarch64/ubfx_lsr_1.c: New test.
diff --git a/gcc/testsuite/gcc.target/aarch64/ubfiz_lsl_1.c b/gcc/testsuite/gcc.target/aarch64/ubfiz_lsl_1.c
new file mode 100644 (file)
index 0000000..d3fd3f2
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+/* Check that an X-reg UBFIZ can be simplified into a W-reg LSL.  */
+
+long long
+f2 (long long x)
+{
+  return (x << 5) & 0xffffffff;
+}
+
+/* { dg-final { scan-assembler "lsl\tw" } } */
+/* { dg-final { scan-assembler-not "ubfiz\tx" } } */