-
Notifications
You must be signed in to change notification settings - Fork 355
[Comb] Fix more recursive mux folders #8756
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
Conversation
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.
LGTM, thanks for fixing this 🙌
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 wondering if it really makes sense to play whack-a-mole with this kind of issues, or if we shouldn't just bail out of canonicalize
immediately when the op is trivially cyclic. Does anyone actually benefit from optimizations over cyclic comb expressions?
How about adding a more general helper function?
// Returns true if the op is in `comb` and if any of its operands
// is identical to any of its results.
static bool isTriviallyCyclicCombOp(Operation* op) {
if (!op || !isa<comb::CombDialect>(op->getDialect()))
return false;
for (auto res: op->getResults()) {
if (llvm::any_of(op->getOperands(), [res](auto operand){
return operand == res;
}))
return true;
}
return false;
}
(Not tested!)
I'd expect this to come in handy at various places.
I agree that I think in general bailing out of canonicalization if the op is trivially cyclic probably makes sense and that having such a helper would be useful, but worth noting that these cases don't always occur when the root operation is trivially cyclic - in this case it's another operation that gets caught up in the fold. I guess maybe the answer is to call this on any op involved in a comb fold, but that's probably a topic for a later discussion (I can't make the next one, but maybe an ODM?). In the meantime I'm going to merge this just so we have the bug covered |
Co-authored-by: Fabian Schuiki <fabian@schuiki.ch>
Co-authored-by: Fabian Schuiki <fabian@schuiki.ch>
This catches two more cases where muxes that have themselves as an input can cause a recursive folder in comb canonicalization, both triggered by the added integration test. Closes #8754