On Sat, Jun 3, 2023 at 3:52 PM Takayuki 'January June' Suwa
<jjsuwa_sys3...@yahoo.co.jp> wrote:
>
> This patch optimizes both the boolean evaluation of and the branching of
> EQ/NE against INT_MIN (-2147483648), by taking advantage of the specifi-
> cation the ABS machine instruction on Xtensa returns INT_MIN iff INT_MIN,
> otherwise non-negative value.
>
>     /* example */
>     int test0(int x) {
>       return (x == -2147483648);
>     }
>     int test1(int x) {
>       return (x != -2147483648);
>     }
>     extern void foo(void);
>     void test2(int x) {
>       if(x == -2147483648)
>         foo();
>     }
>     void test3(int x) {
>       if(x != -2147483648)
>         foo();
>     }
>
>     ;; before
>     test0:
>         movi.n  a9, -1
>         slli    a9, a9, 31
>         add.n   a2, a2, a9
>         nsau    a2, a2
>         srli    a2, a2, 5
>         ret.n
>     test1:
>         movi.n  a9, -1
>         slli    a9, a9, 31
>         add.n   a9, a2, a9
>         movi.n  a2, 1
>         moveqz  a2, a9, a9
>         ret.n
>     test2:
>         movi.n  a9, -1
>         slli    a9, a9, 31
>         bne     a2, a9, .L3
>         j.l     foo, a9
>     .L3:
>         ret.n
>     test3:
>         movi.n  a9, -1
>         slli    a9, a9, 31
>         beq     a2, a9, .L5
>         j.l     foo, a9
>     .L5:
>         ret.n
>
>     ;; after
>     test0:
>         abs     a2, a2
>         extui   a2, a2, 31, 1
>         ret.n
>     test1:
>         abs     a2, a2
>         srai    a2, a2, 31
>         addi.n  a2, a2, 1
>         ret.n
>     test2:
>         abs     a2, a2
>         bbci    a2, 31, .L3
>         j.l     foo, a9
>     .L3:
>         ret.n
>     test3:
>         abs     a2, a2
>         bbsi    a2, 31, .L5
>         j.l     foo, a9
>     .L5:
>         ret.n
>
> gcc/ChangeLog:
>
>         * config/xtensa/xtensa.md (*btrue_INT_MIN, *eqne_INT_MIN):
>         New insn_and_split patterns.
> ---
>  gcc/config/xtensa/xtensa.md | 64 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 64 insertions(+)

Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.

-- 
Thanks.
-- Max

Reply via email to