diff options
author | Artemiy Volkov <Artemiy.Volkov@synopsys.com> | 2024-10-08 18:06:23 -0600 |
---|---|---|
committer | Jeff Law <jlaw@ventanamicro.com> | 2024-10-08 18:06:23 -0600 |
commit | 52fdf1e7eb89a148a9cdd1daade524f4540ab5fa (patch) | |
tree | ecbcb758a8c46455162befd88b2b1ad6227249a9 /libtool-ldflags | |
parent | e5f5cffb8c8243896a9d3bd0e2b8f14c70f8df1e (diff) | |
download | gcc-52fdf1e7eb89a148a9cdd1daade524f4540ab5fa.zip gcc-52fdf1e7eb89a148a9cdd1daade524f4540ab5fa.tar.gz gcc-52fdf1e7eb89a148a9cdd1daade524f4540ab5fa.tar.bz2 |
tree-optimization/116024 - simplify some cases of X +- C1 cmp C2
Whenever C1 and C2 are integer constants, X is of a wrapping type, and
cmp is a relational operator, the expression X +- C1 cmp C2 can be
simplified in the following cases:
(a) If cmp is <= and C2 -+ C1 == +INF(1), we can transform the initial
comparison in the following way:
X +- C1 <= C2
-INF <= X +- C1 <= C2 (add left hand side which holds for any X, C1)
-INF -+ C1 <= X <= C2 -+ C1 (add -+C1 to all 3 expressions)
-INF -+ C1 <= X <= +INF (due to (1))
-INF -+ C1 <= X (eliminate the right hand side since it holds for any X)
(b) By analogy, if cmp if >= and C2 -+ C1 == -INF(1), use the following
sequence of transformations:
X +- C1 >= C2
+INF >= X +- C1 >= C2 (add left hand side which holds for any X, C1)
+INF -+ C1 >= X >= C2 -+ C1 (add -+C1 to all 3 expressions)
+INF -+ C1 >= X >= -INF (due to (1))
+INF -+ C1 >= X (eliminate the right hand side since it holds for any X)
(c) The > and < cases are negations of (a) and (b), respectively.
This transformation allows to occasionally save add / sub instructions,
for instance the expression
3 + (uint32_t)f() < 2
compiles to
cmn w0, #4
cset w0, ls
instead of
add w0, w0, 3
cmp w0, 2
cset w0, ls
on aarch64.
Testcases that go together with this patch have been split into two
separate files, one containing testcases for unsigned variables and the
other for wrapping signed ones (and thus compiled with -fwrapv).
Additionally, one aarch64 test has been adjusted since the patch has
caused the generated code to change from
cmn w0, #2
csinc w0, w1, wzr, cc (x < -2)
to
cmn w0, #3
csinc w0, w1, wzr, cs (x <= -3)
This patch has been bootstrapped and regtested on aarch64, x86_64, and
i386, and additionally regtested on riscv32.
gcc/ChangeLog:
PR tree-optimization/116024
* match.pd: New transformation around integer comparison.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr116024-2.c: New test.
* gcc.dg/tree-ssa/pr116024-2-fwrapv.c: Ditto.
* gcc.target/aarch64/gtu_to_ltu_cmp_1.c: Adjust.
Diffstat (limited to 'libtool-ldflags')
0 files changed, 0 insertions, 0 deletions