xtensa: Optimize "bitwise AND with imm1" followed by "branch if (not) equal to imm2"
This patch enhances the effectiveness of the previously posted one:
"xtensa: Optimize bitwise AND operation with some specific forms of constants".
/* example */
extern void foo(int);
void test(int a) {
if ((a & (-1U << 8)) == (128 << 8)) /* 0 or one of "b4const" */
foo(a);
}
;; before
.global test
test:
movi a3, -0x100
movi.n a4, 1
and a3, a2, a3
slli a4, a4, 15
bne a3, a4, .L3
j.l foo, a9
.L1:
ret.n
;; after
.global test
test:
srli a3, a2, 8
bnei a3, 128, .L1
j.l foo, a9
.L1:
ret.n
gcc/ChangeLog:
* config/xtensa/xtensa.md
(*masktrue_const_pow2_minus_one, *masktrue_const_negative_pow2,
*masktrue_const_shifted_mask): If the immediate for bitwise AND is
represented as '-(1 << N)', decrease the lower bound of N from 12
to 1. And the other immediate for conditional branch is now no
longer limited to zero, but also one of some positive integers.
Finally, remove the checks of some conditions, because the comparison
expressions that don't satisfy such checks are determined as
compile-time constants and thus will be optimized away before
RTL expansion.