-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add rfactor patterns for index-first argmax/argmin #8932
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
base: main
Are you sure you want to change the base?
Conversation
| debug(5) << "Found associative ops for " << e << " -> " << op << ":\n" | ||
| << [&] { | ||
| std::stringstream ss; | ||
| for (const auto &[var, val] : result) { | ||
| ss << " " << var << " -> " << val << "\n"; | ||
| } | ||
| return ss.str(); | ||
| }(); |
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.
"Fun" fact: without this patch, we get a segfault when HL_DEBUG_CODEGEN is set to print this message. When the associative op is in the second tuple component, only y1 is in the result, yet the lookup itself will add an entry to for y0, with an undefined Expr for the value. Later, the expr_uses_vars check will try to visit the undefined Expr and a null pointer gets dereferenced.
Add patterns to the associative ops table to allow writing argmin/argmax as (index, value) pairs. Previously, rfactor supported only (value, index) because it would fail to prove associativity.
Doing this required reworking the code that converted a matched expression back into a pattern over the new variable names. It did this completely backwards for some reason: trying to match large fragments of IR and replacing them with the placeholder names. But we just matched the pattern in the table! So I'm proceeding by renaming the table patterns directly. I don't see why this shouldn't work, but I've only run
correctness_rfactorand_test_internallocally, so we'll see what the bots say.Added tests for the inline reduction helpers, too.
ATTN @stevenraphael