If the shifter operand is a constant, and all of the bits shifted out are known to be zero, then if X is known non-zero at least one non-zero bit must remain.
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/Analysis/ValueTracking.cpp | ||
---|---|---|
1837 | This really seems like two distinct cases and the code would be clearer if organized as such. case 1 - There's a known one bit somewhere in the portion not shifted out. case 2 - All bits shifted out are known-zero and X is known non-zero. I think what you have is correct, I just found the flow of the code confusing on first read. | |
unittests/Analysis/ValueTrackingTest.cpp | ||
203 ↗ | (On Diff #34543) | I'd probably just phrase this as a normal IR test for inst combine or inst simplify. What's here is correct, just needlessly complicated. |
lib/Analysis/ValueTracking.cpp | ||
---|---|---|
1832 | I don't think this check is necessary, and you can just use Shift->getLimitedValue(BitWidth-1) below, because it is undefined behavior for the number to be larger than that regardless. |
lib/Analysis/ValueTracking.cpp | ||
---|---|---|
1837 | You could also check for the exact flag here. | |
1837 | How about if (KnownZero.countTrailingZeros() >= Shift->getLimitedValue())? | |
1838 | I'd expect this first case to be handled by the fall through at the end. Do you have a case where it doesn't? | |
unittests/Analysis/ValueTrackingTest.cpp | ||
203 ↗ | (On Diff #34543) | +1 to Philip's comment. |
Hi Hal, Sanjoy, Philip,
Thanks very much for the reviews - sorry it took so long to address.
The newest version should address these comments.
Cheers,
James
lib/Analysis/ValueTracking.cpp | ||
---|---|---|
1841 | I don't think so, because bits in KnownZero are one if they are known to be zero. I agree it looks confusing though and I've made this mistake in the past. |
I don't think this check is necessary, and you can just use Shift->getLimitedValue(BitWidth-1) below, because it is undefined behavior for the number to be larger than that regardless.