If a PHI starts at a non-negative constant, monotonically increases (only adds of a constant are supported at the moment) and that add does not wrap, then the PHI is known never to be zero.
Diff Detail
- Repository
- rL LLVM
Event Timeline
A couple of meta comments:
- This is duplicating logic in SCEV. I think that's okay in this case, but we don't want to take that to the extreme.
- Adding the analogous case isKnownNonNegative (aka, using it to set the sign bit in computeKnownBits) would be a really good idea. An increasing induction variable starting at zero is pretty much the ideal canonical induction variable and we should exploit that.
lib/Analysis/ValueTracking.cpp | ||
---|---|---|
1911 | I find the Op1 vs Op0 naming confusing. Given this is inherently zero based indexing, mind either using that in the Op names or picking non-index based ones? | |
1916 | Might be time to introduce a isNonNegative on ConstantInt? Could be another patch. | |
1919 | Given you're starting from zero, I think you only need the NSW check. Given INT_MAX is always less than UINT_MAX, I believe the former implies the later in this case. (But we might not yet have proved it.) |
Hi Philip,
Thanks very much for the review!
I've addressed your comments, and spent some time to convert the test into one that can run through InstSimplify.
Cheers,
James
Adding the analogous case isKnownNonNegative (aka, using it to set the sign bit in computeKnownBits) would be a really good idea. An increasing induction variable starting at zero is pretty much the ideal canonical induction variable and we should exploit that.
It looks like this should already be handled in computeKnownBits (ValueTracking.cpp:1277).
I find the Op1 vs Op0 naming confusing. Given this is inherently zero based indexing, mind either using that in the Op names or picking non-index based ones?