You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The three functions are equivalent. Specifically the threshold constant to be compared with is a power-of-two. If there is no shortage of temporary registers, then the right shift version (that is, func2) will likely make the smallest code.
My expected result is like this (assuming -Os optimization, not -O2)
shrl $20, %edi
sete %al
retq
Instead I got this (x86-64 clang 20.1.0 with -Os option, tested in Compiler Explorer):
cmpl $1048576, %edi
setb %al
retq
(Clang can recognize the three functions are equivalent. It just made suboptimal code among the possible choices.)
Note that in RISC-V targets of Clang, it does use the right shift to reduce code size