]> git.ipfire.org Git - thirdparty/gcc.git/commit
AArch64: Define the spaceship optab [PR117013]
authorSpencer Abson <spencer.abson@arm.com>
Thu, 23 Jan 2025 19:48:49 +0000 (19:48 +0000)
committerChristophe Lyon <christophe.lyon@arm.com>
Tue, 22 Apr 2025 15:07:39 +0000 (17:07 +0200)
commitfabbf99fc8ae26f0d87ff0c8619b4fc3bb4a5da2
tree1d561a9ea2d030dbb40f6909a132e25b96a7c430
parent5d5e8e87a42af8c0d962fa16dc9835fb71778250
AArch64: Define the spaceship optab [PR117013]

This expansion ensures that exactly one comparison is emitted for
spacesip-like sequences on floating-point operands, including when
the result of such sequences are compared against members of
std::<some_ordering>::<some_value>.

For both integer and floating-point types, we optimize for the case
in which the result of a spaceship-like operation is written to a GPR.
The PR highlights this issue for floating-point operands, but we also
make an improvement for integers, preferring:

cmp     w0, w1
cset w1, gt
csinv w0, w1, wzr, ge

over:

cmp w0, w1
mov     w0, 1
csinv   w0, w0, wzr, ge
csel    w0, w0, wzr, ne

to compute:

auto test(int a, int b) { return a <=> b;}

gcc/ChangeLog:
PR target/117013
* config/aarch64/aarch64-protos.h (aarch64_expand_fp_spaceship):
Declare optab expander function for floating-point types.
* config/aarch64/aarch64.cc (aarch64_expand_fp_spaceship):
Define optab expansion for floating-point types (new function).
* config/aarch64/aarch64.md (spaceship<mode>4):
Add define_expands for spaceship<mode>4 on integer and
floating-point types.

gcc/testsuite/ChangeLog:
PR target/117013
* g++.target/aarch64/spaceship_1.C: New test.
* g++.target/aarch64/spaceship_2.C: New test.
* g++.target/aarch64/spaceship_3.C: New test.
gcc/config/aarch64/aarch64-protos.h
gcc/config/aarch64/aarch64.cc
gcc/config/aarch64/aarch64.md
gcc/testsuite/g++.target/aarch64/spaceship_1.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/spaceship_2.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/spaceship_3.C [new file with mode: 0644]