Use the obvious formula for the maximum backedge-taken count.
Details
Diff Detail
Event Timeline
lib/Analysis/ScalarEvolution.cpp | ||
---|---|---|
7217 | This looks correct to me, but I think it could use a comment. Do we only need to match against Distance + 1 because this is what we typically get from rotating the loop? Otherwise I think this could be generalized to Distance + constant, but we would need to do some work to find the value of the constant. |
lib/Analysis/ScalarEvolution.cpp | ||
---|---|---|
7217 | The transform is correct because we prove "Distance + 1" doesn't overflow. I'll add a comment explaining that. You could generalize this to "Distance + Constant", but it's not clear what sort of pattern we would be looking for. (Also, at that point, it would probably be better to just write a context-sensitive version of getUnsignedRange().) |
I'm happy with the direction, but I think this is changing the code in two ways at once. I'd rather have the two changes clearly spelt out as different checkins.
lib/Analysis/ScalarEvolution.cpp | ||
---|---|---|
7210 | I think we should really split this change up into two.
| |
7216 | s/getAddExpr(Distance, getOne(Distance->getType()))/getAddExpr(Distance, One)/ ? | |
7219 | Why are you checking (Distance + 1) != 0 instead of Distance != -1? I'd find the latter more straightforward. |
lib/Analysis/ScalarEvolution.cpp | ||
---|---|---|
7219 | In case I gave the wrong impression, I don't specifically care about checking (Distance + 1) != 0 vs. Distance != -1. If you find the former more straightforward, then I'm okay too. |
Split so this change just contains the cleanup. (This is enough to fix ne_max_trip_count_1.)
lgtm
lib/Analysis/ScalarEvolution.cpp | ||
---|---|---|
7209–7229 | I'd add a one-liner here: // Solve {Distance,+,-1} == 0. |
I think we should really split this change up into two.