@@ -330,6 +330,7 @@ int aarch64_uxt_size (int, HOST_WIDE_INT);
int aarch64_vec_fpconst_pow_of_2 (rtx);
rtx aarch64_final_eh_return_addr (void);
rtx aarch64_legitimize_reload_address (rtx *, machine_mode, int, int, int);
+rtx aarch64_mask_from_zextract_ops (rtx, rtx);
const char *aarch64_output_move_struct (rtx *operands);
rtx aarch64_return_addr (int, rtx);
rtx aarch64_simd_gen_const_vector_dup (machine_mode, int);
@@ -4147,7 +4147,9 @@ aarch64_select_cc_mode (RTX_CODE code, rtx x, rtx y)
&& y == const0_rtx
&& (code == EQ || code == NE || code == LT || code == GE)
&& (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS || GET_CODE (x) == AND
- || GET_CODE (x) == NEG))
+ || GET_CODE (x) == NEG
+ || (GET_CODE (x) == ZERO_EXTRACT && CONST_INT_P (XEXP (x, 1))
+ && CONST_INT_P (XEXP (x, 2)))))
return CC_NZmode;
/* A compare with a shifted operand. Because of canonicalization,
@@ -10759,6 +10761,21 @@ aarch64_simd_imm_zero_p (rtx x, machine_mode mode)
return x == CONST0_RTX (mode);
}
+
+/* Return the bitmask CONST_INT to select the bits required by a zero extract
+ operation of width WIDTH at bit position POS. */
+
+rtx
+aarch64_mask_from_zextract_ops (rtx width, rtx pos)
+{
+ gcc_assert (CONST_INT_P (width));
+ gcc_assert (CONST_INT_P (pos));
+
+ unsigned HOST_WIDE_INT mask
+ = ((unsigned HOST_WIDE_INT) 1 << UINTVAL (width)) - 1;
+ return GEN_INT (mask << UINTVAL (pos));
+}
+
bool
aarch64_simd_imm_scalar_p (rtx x, machine_mode mode ATTRIBUTE_UNUSED)
{
@@ -3698,6 +3698,28 @@ (define_insn "*and<mode>3nr_compare0"
[(set_attr "type" "logics_reg,logics_imm")]
)
+(define_insn "*and<mode>3nr_compare0_zextract"
+ [(set (reg:CC_NZ CC_REGNUM)
+ (compare:CC_NZ
+ (zero_extract:GPI (match_operand:GPI 0 "register_operand" "r")
+ (match_operand:GPI 1 "const_int_operand" "n")
+ (match_operand:GPI 2 "const_int_operand" "n"))
+ (const_int 0)))]
+ "INTVAL (operands[1]) > 0
+ && ((INTVAL (operands[1]) + INTVAL (operands[2]))
+ <= GET_MODE_BITSIZE (<MODE>mode))
+ && aarch64_bitmask_imm (
+ UINTVAL (aarch64_mask_from_zextract_ops (operands[1],
+ operands[2])),
+ <MODE>mode)"
+ {
+ operands[1]
+ = aarch64_mask_from_zextract_ops (operands[1], operands[2]);
+ return "tst\\t%<w>0, %1";
+ }
+ [(set_attr "type" "logics_shift_imm")]
+)
+
(define_insn "*and_<SHIFT:optab><mode>3nr_compare0"
[(set (reg:CC_NZ CC_REGNUM)
(compare:CC_NZ
new file mode 100644
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int
+f1 (int x)
+{
+ if (x & 1)
+ return 1;
+ return x;
+}
+
+/* { dg-final { scan-assembler "tst\t(x|w)\[0-9\]*.*1" } } */
new file mode 100644
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int
+f1 (long x)
+{
+ return ((short) x >= 0) ? x : 0;
+}
+
+/* { dg-final { scan-assembler "tst\t(x|w)\[0-9\]*.*32768\n" } } */