]> git.ipfire.org Git - thirdparty/gcc.git/commit
xtensa: Optimize "bitwise AND with imm1" followed by "branch if (not) equal to imm2"
authorTakayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
Fri, 15 Jul 2022 10:51:40 +0000 (19:51 +0900)
committerMax Filippov <jcmvbkbc@gmail.com>
Sat, 16 Jul 2022 07:27:42 +0000 (00:27 -0700)
commitd6d8e6a7e1379f9dfdf2f39efcc82d9185cca6d0
tree9ce1ad9bc1badeceb2bb4f809dc658d9749a5e46
parent1884f8978237b15013576a720bcb32e7c5647574
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.
gcc/config/xtensa/xtensa.md