]> git.ipfire.org Git - thirdparty/gcc.git/commit
middle-end: simplify complex if expressions where comparisons are inverse of one...
authorTamar Christina <tamar.christina@arm.com>
Mon, 12 Dec 2022 15:21:39 +0000 (15:21 +0000)
committerTamar Christina <tamar.christina@arm.com>
Mon, 12 Dec 2022 15:21:39 +0000 (15:21 +0000)
commit4d9db4bdd458a4b526f59e4bc5bbd549d3861cea
treee358bee89eb086f37e9d44026954d0eaaff5ef58
parent594264e9bcb592b8edc4b50b5d9be5eb34c1d6d7
middle-end: simplify complex if expressions where comparisons are inverse of one another.

This optimizes the following sequence

  ((a < b) & c) | ((a >= b) & d)

into

  (a < b ? c : d) & 1

for scalar and on vector we can omit the & 1.

Also recognizes

  (-(a < b) & c) | (-(a >= b) & d)

into

  a < b ? c : d

This changes the code generation from

zoo2:
cmp     w0, w1
cset    w0, lt
cset    w1, ge
and     w0, w0, w2
and     w1, w1, w3
orr     w0, w0, w1
ret

into

cmp w0, w1
csel w0, w2, w3, lt
and w0, w0, 1
ret

and significantly reduces the number of selects we have to do in the vector
code.

gcc/ChangeLog:

* match.pd: Add new rule.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/if-compare_1.c: New test.
* gcc.target/aarch64/if-compare_2.c: New test.
gcc/match.pd
gcc/testsuite/gcc.target/aarch64/if-compare_1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/if-compare_2.c [new file with mode: 0644]