-
Notifications
You must be signed in to change notification settings - Fork 10.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
missing instcombine: select (icmp ugt A, N), (shr A, M), 0 -> shr A, M, when N < 2^M #54089
Comments
We probably want an even more general match using knownbits (ValueTracking) when the compare (select condition) is a disguised bit-test (see llvm::decomposeBitTestICmp()). For example, we also miss the optimization with an 'and' instruction instead of a shift:
|
I'd probably approach this in terms of |
I've prepared a patch, planning to send it for review ~soon. |
This diff extends foldSelectInstWithICmp to handle the case icmp(X) ? f(X) : C when f(X) is guaranteed to be equal to C for all X in the exact range of the inverse predicate. This addresses the issue #54089. Differential revision: https://reviews.llvm.org/D123159 Test plan: make check-all
This diff extends foldSelectInstWithICmp to handle the case icmp(X) ? f(X) : C when f(X) is guaranteed to be equal to C for all X in the exact range of the inverse predicate. This addresses the issue llvm/llvm-project#54089. Differential revision: https://reviews.llvm.org/D123159 Test plan: make check-all
Example, seen in the wild in libcap-ng:
produces:
This could be optimized further to:
The general pattern here is:
select (icmp ugt A, N), (shr A, M), 0
->shr A, M
whenever
N
< 2M
.The text was updated successfully, but these errors were encountered: