-
Notifications
You must be signed in to change notification settings - Fork 883
ConstraintAnalysis: Fix a hang with a tee in an increment #9058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -568,14 +568,6 @@ struct ConstraintAnalysis | |||
| return; | ||||
| } | ||||
|
|
||||
| // See above on binary action counting limits. | ||||
| if (auto* binary = set->value->dynCast<Binary>()) { | ||||
| if (binaryActionCounts[binary]++ >= MaxBinaryActions) { | ||||
| constraints.setProvesNothing(set->index); | ||||
| return; | ||||
| } | ||||
| } | ||||
|
|
||||
| // Look at the fallthrough. It is valid to do so, because our constraints | ||||
| // only track two things, constants and locals. For a constant, it does | ||||
| // not change while falling through. For a local, the only way for the | ||||
|
|
@@ -600,8 +592,37 @@ struct ConstraintAnalysis | |||
| // opportunity to write any other value while falling through. (And, any | ||||
| // local.tee appearing here would have been reached earlier in the | ||||
| // traversal, and handled.) | ||||
| auto* value = | ||||
| Properties::getFallthrough(set->value, getPassOptions(), *getModule()); | ||||
| auto* value = set->value; | ||||
| while (1) { | ||||
| if (value->is<LocalSet>()) { | ||||
| // We stop at the first tee: we don't need to look any further, and | ||||
| // will just apply that local's values to ourselves, saving repeated | ||||
| // work. | ||||
| break; | ||||
| } | ||||
| auto* next = Properties::getImmediateFallthrough( | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't there an optional parameter to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is, but it also skips BrIfs: Line 271 in 39be64e
We could perhaps make that flag more refined, but I'm not sure it's worth it. |
||||
| value, getPassOptions(), *getModule()); | ||||
| if (value == next) { | ||||
| break; | ||||
| } else { | ||||
| value = next; | ||||
| } | ||||
| } | ||||
|
|
||||
| // Now that we know the value, check binary action counting limits (see | ||||
| // above). | ||||
| if (auto* binary = value->dynCast<Binary>()) { | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason to continue restricting this to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to keep this "precise" to the things it needs to handle. There is nothing else where we have this issue other than a Binary, atm (and I'm not sure we ever will?)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I guess all infinite analysis loops would involve a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me it makes sense as a Binary is where With that said, maybe it is nicer to count basic block operations? Worth thinking about. |
||||
| // The count may exceed the limit sometimes, but add a hard assert on | ||||
| // never going up so high it is likely doing an unbounded computation. | ||||
| auto& count = binaryActionCounts[binary]; | ||||
| assert(count < MaxBinaryActions * 10); | ||||
| count++; | ||||
| if (count >= MaxBinaryActions) { | ||||
| constraints.setProvesNothing(set->index); | ||||
| return; | ||||
| } | ||||
| } | ||||
|
|
||||
| constraints.set(set->index, value); | ||||
| } | ||||
| } | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wasn't this catch-all widening sufficient to prevent the problem? Because the expression we have here isn't a
Binary? Could we fix it by just handling any kind of expression here instead of justBinary?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue was that we didn't handle this wrt a fallthrough. That is, we computed the fallthrough after, perhaps producing a Binary then - after this check.
That was silly and also inefficient...