https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95424
Zhao Wei Liew <zhaoweiliew at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #52091|0 |1
is obsolete| |
--- Comment #2 from Zhao Wei Liew <zhaoweiliew at gmail dot com> ---
Created attachment 52097
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52097&action=edit
Optimization for both unsigned and signed integer X
I've attached a new patch which does the optimization for both the unsigned and
the signed case.
With this patch, x86-64 gcc -std=c++20 -O3 produces the following assembly:
f(int):
lea eax, [rdi + 1]
cmp eax, 2
mov eax, 0
cmovbe eax, edi
ret
f(unsigned int):
xor eax, eax
cmp edi, 1
sete al
ret
which is virtually identical to the following assembly produced by clang++
-std=c++20 -O3:
f(int):
lea ecx, [rdi + 1]
xor eax, eax
cmp ecx, 3
cmovb eax, edi
ret
f(unsigned int):
xor eax, eax
cmp edi, 1
sete al
ret