Implement precise nuw/nsw support in the KnownBits implementation, replacing the rather crude handling in ValueTracking.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Support/KnownBits.cpp | ||
---|---|---|
176 | nit style: Instead of nesting if statements, can you invert them and just return immediately? Think it makes code easier to read. | |
213 | Imo, this check should just be at the top. Then you can drop the RHS.getConstant().ult(BitWidth) check before ShiftByConst | |
232 | in the NSW/NUW we should be able to further bound MaxShiftAmount with LHS.countLeadingZeros no? (and poison if MinShiftAmunt > LHS.countLeadingZeros) | |
253–258 | can you assert no conflict? Its not super obvious just reading the code that the loop will be enough to clear the all zeros/ones initial state in Known. |
llvm/lib/Support/KnownBits.cpp | ||
---|---|---|
176 | I've done this for the first check here and also for the isUnknown checks in https://github.com/llvm/llvm-project/commit/2d48a771fc00681414c54ea3936bff91f3b253c4. | |
232 | Yes, but this is already implicitly handled by the loop below. It stops once it gets the first shift amount that results in poison due to nuw/nsw. | |
253–258 | You are right, it's necessary to check for conflicts here. I've added a general assertion for this in the exhaustive tests, so we don't have to remember checking it for every function: https://github.com/llvm/llvm-project/commit/d4bfc144eaa6e34eafaab1e8574421ebd2bb78ed |
nit style: Instead of nesting if statements, can you invert them and just return immediately? Think it makes code easier to read.