diff options
author | Artemiy Volkov <Artemiy.Volkov@synopsys.com> | 2024-10-08 17:51:08 -0600 |
---|---|---|
committer | Jeff Law <jlaw@ventanamicro.com> | 2024-10-08 17:51:59 -0600 |
commit | 0883c88664d48463dfc79335dccaf15a69230952 (patch) | |
tree | 102b1a358745302e1e8aa5b1717e2e3acd030b90 /libcpp/include/cpplib.h | |
parent | 2990f5802a727cbd717587c3a345fa940193049f (diff) | |
download | gcc-0883c88664d48463dfc79335dccaf15a69230952.zip gcc-0883c88664d48463dfc79335dccaf15a69230952.tar.gz gcc-0883c88664d48463dfc79335dccaf15a69230952.tar.bz2 |
tree-optimization/116024 - simplify C1-X cmp C2 for UB-on-overflow types
Implement a match.pd pattern for C1 - X cmp C2, where C1 and C2 are
integer constants and X is of a UB-on-overflow type. The pattern is
simplified to X rcmp C1 - C2 by moving X and C2 to the other side of the
comparison (with opposite signs). If C1 - C2 happens to overflow,
replace the whole expression with either a constant 0 or a constant 1
node, depending on the comparison operator and the sign of the overflow.
This transformation allows to occasionally save load-immediate /
subtraction instructions, e.g. the following statement:
10 - (int) x <= 9;
now compiles to
sgt a0,a0,zero
instead of
li a5,10
sub a0,a5,a0
slti a0,a0,10
on 32-bit RISC-V.
Additional examples can be found in the newly added test file. This
patch has been bootstrapped and regtested on aarch64, x86_64, and
i386, and additionally regtested on riscv32. Existing tests were
adjusted where necessary.
gcc/ChangeLog:
PR tree-optimization/116024
* match.pd: New transformation around integer comparison.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr116024.c: New test.
* gcc.dg/pr67089-6.c: Adjust.
Diffstat (limited to 'libcpp/include/cpplib.h')
0 files changed, 0 insertions, 0 deletions