This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Fix bug involving zero step and non-invariant RHS in trip count logic
ClosedPublic

Authored by reames on Jul 19 2021, 5:37 PM.

Details

Summary

Eli pointed out the issue when reviewing D104140. The max trip count logic makes an assumption that the value of IV changes. When the step is zero, the nowrap fact becomes trivial, and thus there's nothing preventing the loop from being nearly infinite. (The "nearly" part is because mustprogress may disallow an infinite loop while still allowing 999999999 iterations before RHS happens to allow an exit.)

This is very difficult to see in practice. You need a means to produce a loop varying RHS in a mustprogress loop which doesn't allow the loop to be infinite. In most cases, LICM or SCEV are smart enough to remove the loop varying expressions.

Diff Detail

Event Timeline

reames created this revision.Jul 19 2021, 5:37 PM
reames requested review of this revision.Jul 19 2021, 5:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2021, 5:37 PM
reames planned changes to this revision.Jul 19 2021, 5:52 PM

Er, ignore this for the moment. I appear to have screwed something up in extracting and testing this - it doesn't pass make check for me now. Time to return to this with fresh eyes tomorrow.

reames requested review of this revision.Jul 19 2021, 5:56 PM

Local test failure was a stray change which had snuck in, not this patch. But still, probably time to return to the project tomorrow.

Like I noted on the other review, I think you also need the isLoopInvariant(RHS, L) check if the stride is negative.

Like I noted on the other review, I think you also need the isLoopInvariant(RHS, L) check if the stride is negative.

Can we fix one bug at a time though? I'm happy to explore that one, but I'd prefer to do it on it's own with it's own discussion and tests.

efriedma accepted this revision.Jul 20 2021, 9:35 AM

LGTM

I guess we can deal with the negative case separately, sure.

This revision is now accepted and ready to land.Jul 20 2021, 9:35 AM

Eli, just FYI, I'm going to be away from build env for most of the next couple days. I might get this in tonight, but if not, it'll likely wait until the weekend. Feel free to commit on my behalf if doing so would help you make progress.

This revision was landed with ongoing or failed builds.Jul 23 2021, 3:19 PM
This revision was automatically updated to reflect the committed changes.