Details
- Reviewers
nikic goldstein.w.n - Commits
- rG2b1678cd06e6: [KnownBits] Simplify shl. NFCI.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
@nikic this was a result of me trying to understand your implementation. I tried to:
- remove special cases (but perhaps some of these were deliberate early-outs to speed up to the common cases?)
- work in unsigned instead of APInt as much as possible
- take advantage of APInt::*shl_ov
Yes, these are intentional fast paths. In fact, the ones we currently have are insufficient, and we'll need another one for the case where the shift amount is unknown, because the current implementation is too slow. (This path is mostly not exposed right now due to special code in ValueTracking, but it if does get exposed it causes substantial compile-time regressions.)
It's possible that dropping the special handling for constants would be fine, but we need to at least keep the code for handling unknown LHS.
- work in unsigned instead of APInt as much as possible
- take advantage of APInt::*shl_ov
These changes look good to me and should make the implementation faster.
For reference, that extra fast path is going to look something like this: https://github.com/llvm/llvm-project/commit/6c242bc3d81f87b819e6d705d73a43fb4bf1c5d0 (Which does fix the compile-time regressions.) But I'll return to this once you're done with your changes.
LGTM
llvm/lib/Support/KnownBits.cpp | ||
---|---|---|
210–214 | Seems like pulling this out of the isUnknown() branch would be cleaner, as it is not specific to unknown values. |
llvm/lib/Support/KnownBits.cpp | ||
---|---|---|
210–214 | Yeah, maybe. This was a result of me trying to work out why this code is required, and it's only required in the LHS.isUnknown() case, otherwise it will naturally fall out in the wash. And since it will almost never happen in practice, I chose to keep it out of the main code path. | |
210–214 | It is also only required in order to guarantee that we return zero for poison results. I've just put D151456 to check that property so we don't regress it. |
Seems like pulling this out of the isUnknown() branch would be cleaner, as it is not specific to unknown values.