-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failure to recognize andn-like pattern #45100
Comments
assigned to @rotateright |
Current Codegen: https://gcc.godbolt.org/z/JUaYXZ gcc doesn't manage this for vectors |
If we view this as a missed IR canonicalization: define i8 @src(i8 %x) { define i8 @tgt(i8 %x) { |
Alive2 seems to be down at the moment, but this doesn't appear to need to be a unary transform: int g(int x, int y) works as well: (gcc): g: vs (clang): g: |
int g(int x, int y) --> int g2(int x, int y) So the general case seem to be legit: https://alive2.llvm.org/ce/z/cxZDSp It comes down to whether we want to do this in InstCombine or wait to SelectionDAG where we know if there's a ANDN instruction or not. |
InstCombine should do. We prefer 'add' over 'sub' for analysis. Codegen looks equal or better for the 'add' variant on the targets that I checked. x86: (with andn): AArch64: ARM-v7a: PowerPC: |
I'll look at the instcombine patch. Most of the work will be in writing tests to cover variations. |
Thanks Sanjay |
Extended Description
int f(int x)
{
return ~(x | -x);
}
With -O3, GCC outputs this :
f(int):
lea eax, [rdi-1]
andn eax, edi, eax
ret
LLVM outputs this :
f(int): # @f(int)
mov eax, edi
neg eax
or eax, edi
not eax
ret
The text was updated successfully, but these errors were encountered: