Backport from trunk r239919.
2016-09-01 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* config/aarch64/aarch64.md (*ands<mode>_compare0): New pattern.
* config/aarch64/aarch64.c (aarch64_select_cc_mode): Return CC_NZmode
for comparisons of integer ZERO_EXTEND against zero.
gcc/testsuite/
Backport from trunk r239919.
2016-09-01 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* gcc.target/aarch64/ands_3.c: New test.
Change-Id: I1eb5eee3b585ebfac952786043dbd6aed6c3f953
&& (GET_MODE (x) == HImode || GET_MODE (x) == QImode))
return CC_NZmode;
+ /* Similarly, comparisons of zero_extends from shorter modes can
+ be performed using an ANDS with an immediate mask. */
+ if (y == const0_rtx && GET_CODE (x) == ZERO_EXTEND
+ && (GET_MODE (x) == SImode || GET_MODE (x) == DImode)
+ && (GET_MODE (XEXP (x, 0)) == HImode || GET_MODE (XEXP (x, 0)) == QImode)
+ && (code == EQ || code == NE))
+ return CC_NZmode;
+
if ((GET_MODE (x) == SImode || GET_MODE (x) == DImode)
&& y == const0_rtx
&& (code == EQ || code == NE || code == LT || code == GE)
[(set_attr "type" "alus_imm")]
)
+(define_insn "*ands<mode>_compare0"
+ [(set (reg:CC_NZ CC_REGNUM)
+ (compare:CC_NZ
+ (zero_extend:GPI (match_operand:SHORT 1 "register_operand" "r"))
+ (const_int 0)))
+ (set (match_operand:GPI 0 "register_operand" "=r")
+ (zero_extend:GPI (match_dup 1)))]
+ ""
+ "ands\\t%<GPI:w>0, %<GPI:w>1, <short_mask>"
+ [(set_attr "type" "alus_imm")]
+)
+
(define_insn "*and<mode>3nr_compare0"
[(set (reg:CC_NZ CC_REGNUM)
(compare:CC_NZ
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int
+f9 (unsigned char x, int y)
+{
+ if (y > 1 && x == 0)
+ return 10;
+ return x;
+}
+
+/* { dg-final { scan-assembler "ands\t(x|w)\[0-9\]+,\[ \t\]*(x|w)\[0-9\]+,\[ \t\]*255" } } */