]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[AArch64] PR rtl-optimization/68796: Add patterns for QImode and HImode comparison...
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Mon, 11 Jan 2016 14:44:22 +0000 (14:44 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Mon, 11 Jan 2016 14:44:22 +0000 (14:44 +0000)
PR rtl-optimization/68796
* config/aarch64/aarch64.md (*and<mode>_compare0): New pattern.
* config/aarch64/aarch64.c (aarch64_select_cc_mode): Handle HImode
and QImode comparisons against zero with CC_NZmode.
* config/aarch64/iterators.md (short_mask): New mode_attr.

* gcc.target/aarch64/tst_5.c: New test.
* gcc.target/aarch64/tst_6.c: Likewise.

From-SVN: r232228

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

index ffe643e6084da50c45c1c75472c36803b09b6610..74875108f04771faa7f5db5268bea3e5eac228ca 100644 (file)
@@ -1,3 +1,11 @@
+2016-01-11  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       PR rtl-optimization/68796
+       * config/aarch64/aarch64.md (*and<mode>_compare0): New pattern.
+       * config/aarch64/aarch64.c (aarch64_select_cc_mode): Handle HImode
+       and QImode comparisons against zero with CC_NZmode.
+       * config/aarch64/iterators.md (short_mask): New mode_attr.
+
 2016-01-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        * config/i386/sse.md (<avx512>_load<mode>_mask): Remove
index 9142ac0885f717dfdd699f1d02ebbce5db1d382c..6853b0abebd22abae82e5770ca8f8bbb57af59b3 100644 (file)
@@ -4142,6 +4142,13 @@ aarch64_select_cc_mode (RTX_CODE code, rtx x, rtx y)
        }
     }
 
+  /* Equality comparisons of short modes against zero can be performed
+     using the TST instruction with the appropriate bitmask.  */
+  if (y == const0_rtx && REG_P (x)
+      && (code == EQ || code == NE)
+      && (GET_MODE (x) == HImode || GET_MODE (x) == QImode))
+    return CC_NZmode;
+
   if ((GET_MODE (x) == SImode || GET_MODE (x) == DImode)
       && y == const0_rtx
       && (code == EQ || code == NE || code == LT || code == GE)
index d40c02a7d51768aaa1c294c2eb66f40e7ccaef97..f6c8eb1d9fa41fd53322ea9be9dbb3f9c1ceaeb2 100644 (file)
   }
 )
 
+(define_insn "*and<mode>_compare0"
+  [(set (reg:CC_NZ CC_REGNUM)
+       (compare:CC_NZ
+        (match_operand:SHORT 0 "register_operand" "r")
+        (const_int 0)))]
+  ""
+  "tst\\t%<w>0, <short_mask>"
+  [(set_attr "type" "alus_imm")]
+)
+
 (define_insn "*and<mode>3nr_compare0"
   [(set (reg:CC_NZ CC_REGNUM)
        (compare:CC_NZ
index 549d47a7a5d88c142343cdc5c952972069af1c0c..49598a2cd9356d2ff9920544c16f48bbb30022fb 100644 (file)
 (define_mode_attr w1 [(SF "w") (DF "x")])
 (define_mode_attr w2 [(SF "x") (DF "w")])
 
+(define_mode_attr short_mask [(HI "65535") (QI "255")])
+
 ;; For constraints used in scalar immediate vector moves
 (define_mode_attr hq [(HI "h") (QI "q")])
 
index 8157e439c9638179446d627e69cdcf9b58f076eb..6366b495bceb6f1005aea2f57dc8fdc79b037e9c 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-11  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       PR rtl-optimization/68796
+       * gcc.target/aarch64/tst_5.c: New test.
+       * gcc.target/aarch64/tst_6.c: Likewise.
+
 2016-01-11  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR rtl-optimization/68841
diff --git a/gcc/testsuite/gcc.target/aarch64/tst_5.c b/gcc/testsuite/gcc.target/aarch64/tst_5.c
new file mode 100644 (file)
index 0000000..0de40a6
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int
+f255 (int x)
+{
+  if (x & 255)
+    return 1;
+  return x;
+}
+
+int
+f65535 (int x)
+{
+  if (x & 65535)
+    return 1;
+  return x;
+}
+
+/* { dg-final { scan-assembler "tst\t(x|w)\[0-9\]+,\[ \t\]*255" } } */
+/* { dg-final { scan-assembler "tst\t(x|w)\[0-9\]+,\[ \t\]*65535" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/tst_6.c b/gcc/testsuite/gcc.target/aarch64/tst_6.c
new file mode 100644 (file)
index 0000000..f15ec11
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int
+foo (long x)
+{
+   return ((short) x != 0) ? x : 1;
+}
+
+/* { dg-final { scan-assembler "tst\t(x|w)\[0-9\]+,\[ \t\]*65535" } } */