Skip to content
Snippets Groups Projects
Commit 830d36b3 authored by Takayuki 'January June' Suwa's avatar Takayuki 'January June' Suwa Committed by Max Filippov
Browse files

xtensa: Optimize boolean evaluation or branching when EQ/NE to INT_MIN

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.
parent a96ba6b9
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment