-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Reducing switch range on powers of two #70756
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
Comments
You should emit a call to BTW, I guess |
I ran into another problem, which is that we need to convert the
The idea of transformations is to make the number of trailing zeros equal to 0 if the "condition" is not a power of two (since zero case is forbidden in this optimization), and otherwise not to change this number. My question is: isn't it too slow for such optimization, even if we only perform it on systems with built-in support for @llvm.cttz? And if so, do you have any ideas how to do it faster? Upd: I have come up with another solution that
But the question remains open. |
IMHO, I recommend using
|
I believe I need help with failed test: llvm-project/llvm/test/CodeGen/AArch64/switch-unreachable-default.ll Lines 77 to 80 in 801c78d
Proposed optimization doesn't check range for value not to fall through the jump table. It's just reduce switch range and only for switches with unreachable default case. Should I add range-check anyway? |
) Optimization reduces the range for switches whose cases are positive powers of two by replacing each case with count_trailing_zero(case). Resolves llvm#70756
) Optimization reduces the range for switches whose cases are positive powers of two by replacing each case with count_trailing_zero(case). Resolves llvm#70756
) Optimization reduces the range for switches whose cases are positive powers of two by replacing each case with count_trailing_zero(case). Resolves llvm#70756
I recently found
FIXME
:llvm-project/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Lines 6795 to 6797 in b0e00ca
I decided to implement it. My Idea was, as described in FIXME, to check if switch contains only powers of two, and if so, to replace each key with
countl_zero(key)
. When I'm almost done, I ran into a problem that I also need to change the switchcondition
tocountl_zero(condition)
. I tried to find some simple and fast algorithm to count leading zeros in runtime, but all algorithms are too slow or too complex. Should I try to implement something complicated at all, or is this optimization not worth it?My current approach looks like that:
The text was updated successfully, but these errors were encountered: