Hi all, In this PR I'm trying to increase the use of the aarch64 instruction TST that performs a bitwise AND with a bitmask and compares the result with zero. GCC has many ways of representing these operations in RTL. Depending on the mask, the target and the context it might be an AND-immediate, a ZERO_EXTRACT or a ZERO_EXTEND of a subreg. aarch64.md already contains a pattern for the compare with and-immediate case, which is the most general form of this, but it doesn't match in many common cases The documentation on canonicalization in md.texi says: "Equality comparisons of a group of bits (usually a single bit) with zero will be written using @code{zero_extract} rather than the equivalent @code{and} or @code{sign_extract} operations. " This means that we should define a compare with a zero-extract pattern in aarch64, which is what this patch does. It's fairly simple: it constructs the TST mask from the operands of the zero_extract and updates the SELECT_CC_MODE implementation to assign the correct CC_NZ mode to such comparisons. Note that this is valid only for equality comparisons against zero. So for the testcase: int f1 (int x) { if (x & 1) return 1; return x; } we now generate: f1: tst x0, 1 csinc w0, w0, wzr, eq ret instead of the previous: f1: and w1, w0, 1 cmp w1, wzr csinc w0, w0, wzr, eq ret and for the testcase: int f2 (long x) { return ((short) x >= 0) ? x : 0; } we now generate: f2: tst x0, 32768 csel x0, x0, xzr, eq ret instead of: f2: sxth w1, w0 cmp w1, wzr csel x0, x0, xzr, ge ret i.e. we test the sign bit rather than perform the full comparison with zero. Bootstrapped and tested on aarch64-none-linux-gnu. Ok for trunk? Thanks, Kyrill 2015-12-17 Kyrylo Tkachov PR rtl-optimization/68796 * config/aarch64/aarch64.md (*and3nr_compare0_zextract): New pattern. * config/aarch64/aarch64.c (aarch64_select_cc_mode): Handle ZERO_EXTRACT comparison with zero. (aarch64_mask_from_zextract_ops): New function. * config/aarch64/aarch64-protos.h (aarch64_mask_from_zextract_ops): New prototype. 2015-12-17 Kyrylo Tkachov PR rtl-optimization/68796 * gcc.target/aarch64/tst_3.c: New test. * gcc.target/aarch64/tst_4.c: Likewise.