diff options
author | Uros Bizjak <ubizjak@gmail.com> | 2024-06-08 12:17:11 +0200 |
---|---|---|
committer | Uros Bizjak <ubizjak@gmail.com> | 2024-06-08 12:19:37 +0200 |
commit | de05e44b2ad9638d04173393b1eae3c38b2c3864 (patch) | |
tree | 9616bc696794ce3e177762d9161d3d449341cf68 /gcc/cp/parser.cc | |
parent | ab50ac8180beae9001c97cc036ce0df055e25b41 (diff) | |
download | gcc-de05e44b2ad9638d04173393b1eae3c38b2c3864.zip gcc-de05e44b2ad9638d04173393b1eae3c38b2c3864.tar.gz gcc-de05e44b2ad9638d04173393b1eae3c38b2c3864.tar.bz2 |
i386: Implement .SAT_ADD for unsigned scalar integers [PR112600]
The following testcase:
unsigned
add_sat(unsigned x, unsigned y)
{
unsigned z;
return __builtin_add_overflow(x, y, &z) ? -1u : z;
}
currently compiles (-O2) to:
add_sat:
addl %esi, %edi
jc .L3
movl %edi, %eax
ret
.L3:
orl $-1, %eax
ret
We can expand through usadd{m}3 optab to use carry flag from the addition
and generate branchless code using SBB instruction implementing:
unsigned res = x + y;
res |= -(res < x);
add_sat:
addl %esi, %edi
sbbl %eax, %eax
orl %edi, %eax
ret
PR target/112600
gcc/ChangeLog:
* config/i386/i386.md (usadd<mode>3): New expander.
(x86_mov<mode>cc_0_m1_neg): Use SWI mode iterator.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr112600-a.c: New test.
Diffstat (limited to 'gcc/cp/parser.cc')
0 files changed, 0 insertions, 0 deletions