The new function has been added to SCEV that allows
to raise the number 2 to the desired power.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Please write a more reasonable patch name
llvm/include/llvm/Analysis/ScalarEvolution.h | ||
---|---|---|
659 |
| |
660 | This is incorrect for anything greater than 31. (1 << 32) is just zero, no matter the type. | |
llvm/unittests/Analysis/ScalarEvolutionTest.cpp | ||
1764 | Just check that they are constants you expect to see. |
llvm/include/llvm/Analysis/ScalarEvolution.h | ||
---|---|---|
659 | Change return types here to const SCEVConstant *? Can be an NFC follow-up. |
llvm/include/llvm/Analysis/ScalarEvolution.h | ||
---|---|---|
660 | Even if you make it 1LL << 32, it is still wrong. You should use APInt to construct the constant, |
This helper method is planned to be used to improve the SCEV module. In particular, to improve existing optimizations and to write new ones.
llvm/include/llvm/Analysis/ScalarEvolution.h | ||
---|---|---|
659 | I'll do it in the next NFC patch. |
llvm/include/llvm/Analysis/ScalarEvolution.h | ||
---|---|---|
661 | APInt::getOneBitSet(). |
I talked to Dmitry offline, and the motivating example is in downstream code. However, I think this utility function is still a good thing to have in general, maybe someone else will use it.
@dbakunevich I propose commit message
[SCEV][NFC] Introduce utility function to get power of 2
I talked to Dmitry offline, and the motivating example is in downstream code. However, I think this utility function is still a good thing to have in general, maybe someone else will use it.
There are two uses of APInt::getOneBitSet() that could make use of this API -- but they specify the bitwidth as an integer, not as a type.
Though TBH I can't say the value of getPowerOfTwo(BitWidth, TZ) over getConstant(APInt::getOneBitSet(BitWidth, TZ)) is particularly large.
/// Return a SCEV for the constant \p Power of two.