-
Notifications
You must be signed in to change notification settings - Fork 277
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
[FIRRTL][InferWidths] Fix back-prop, fix ref equality, fix upper bound. #5403
[FIRRTL][InferWidths] Fix back-prop, fix ref equality, fix upper bound. #5403
Conversation
// This should only happen if somehow the constraint is | ||
// solved before visiting this expression, so that our upperBound | ||
// was not added to the worklist such that it was handled first. | ||
if (expr->upperBound && solvedExprs.contains(expr->upperBound)) |
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.
I'm not sure we don't need to handle this re:seenVars and checkCycles/etc.?
Or if constraint expressions can be re-used such that we could have solution for the constraint w/o having put the upper bound on the worklist first?
@@ -1819,7 +1821,7 @@ void InferenceMapping::constrainTypes(Value larger, Value smaller) { | |||
} else if (type.isGround()) { | |||
// Leaf element, look up their expressions, and create the constraint. | |||
constrainTypes(getExpr(FieldRef(larger, fieldID)), | |||
getExpr(FieldRef(smaller, fieldID))); | |||
getExpr(FieldRef(smaller, fieldID)), false, equal); |
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.
Don't love this re:bools and ergonomics but wanted to get this reviewed for functionality first, but once that seems good suggestions on improvements welcome (please!). FWIW-- imposeUpperBounds adds LEQ in compatible way to GEQ (if x >= y is requested, it'll add y <= x if x isn't free variable), where-as "equal" causes LEQ (x >= y && x <= y) to be added. Anyway.
Note that the discussion on whether |
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.
This looks good to me! Since this is mostly touching the upperBound
, which isn't used for most of the widths, this shouldn't have any impact on existing width inference.
I wish there was a saner way to do width inference overall than building this shadow expression graph and then running this custom solver. Problem for another day 😉
FWIW this explicitly fixes a bug where we inferred wrong widths, not involving upper bound, mostly because the operation-visiting code put constraints in both directions so we propagated the wrong way (perhaps because didn't have a way to express what it wanted re:new |
tyvm for review and discussion/explanation! |
Fix upperBoundSolution being set from bool indicating if cycle, instead of the value solved for (.first instead of .second).
Tweak how/when upper bound constraint is solved.
Fixes #5002.
Fixes #5391.