We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
int f(int a) { return ((2 << a) & 1) == 0; }
This can be optimized to return 1;. This transformation is done by GCC, but by LLVM.
return 1;
Godbolt comparison here: https://godbolt.org/z/dTfsbx alive2 check here: https://alive2.llvm.org/ce/z/U3DMgJ
The text was updated successfully, but these errors were encountered:
PS: This can also be optimized in cases where the low bits aren't necessarily unset, e.g.
int f(int a) { return ((2 << a) & 16) != 0; }
Can be optimized to return a == b; (done by GCC, not by LLVM).
return a == b;
Sorry, something went wrong.
PPS: I messed up and typed a == b where I meant a == 3 in the previous message.
a == b
a == 3
This is presumably caused by the early exit at
llvm-project/llvm/lib/Analysis/ValueTracking.cpp
Line 1010 in 75347ba
This would catch the example in the description (and similar): https://reviews.llvm.org/D95959
Should be fixed after: https://reviews.llvm.org/rG0be0a1237cb9
No branches or pull requests
Extended Description
int f(int a)
{
return ((2 << a) & 1) == 0;
}
This can be optimized to
return 1;
. This transformation is done by GCC, but by LLVM.Godbolt comparison here: https://godbolt.org/z/dTfsbx
alive2 check here: https://alive2.llvm.org/ce/z/U3DMgJ
The text was updated successfully, but these errors were encountered: