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
(I've filed this as x86-specific because the selects in LLVM-IR might be better for optimizations to use, as more obvious than the subtraction. The specific pattern that Clang emits for <=> is most important, but it would be nice if it also recognized -- or canonicalized in IR -- the bunch of equivalent select chains.)
The text was updated successfully, but these errors were encountered:
(A s>> (BW - 1)) + (zext (A s> 0)) --> (A s>> (BW - 1)) | (zext (A != 0))
https://alive2.llvm.org/ce/z/V-nM8N
This is not the form that we currently match as m_Signum(),
but I'm not sure if one is better than the other, so there's
a follow-up patch needed either way.
For this patch, it should be better for analysis to use a
not-null test and bitwise logic rather than >0 with add.
Codegen doesn't seem significantly different on any targets
that I looked at.
Also note that none of these variants is shown in issue #60012 -
those generally include at least one 'select', so that's likely
where these patterns will end up.
Today, this code https://cpp.godbolt.org/z/e8q15zzK1
gives this select chain
which compiles to some pretty verbose assembly:
There are other ways of doing this that are definitely better for size, and plausibly better for speed too https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign
For example, it could be
(I've filed this as x86-specific because the
select
s in LLVM-IR might be better for optimizations to use, as more obvious than the subtraction. The specific pattern that Clang emits for<=>
is most important, but it would be nice if it also recognized -- or canonicalized in IR -- the bunch of equivalent select chains.)The text was updated successfully, but these errors were encountered: