Skip to content

Add rfactor patterns for index-first argmax/argmin#8932

Open
alexreinking wants to merge 11 commits intomainfrom
fix-argmax
Open

Add rfactor patterns for index-first argmax/argmin#8932
alexreinking wants to merge 11 commits intomainfrom
fix-argmax

Conversation

@alexreinking
Copy link
Member

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_rfactor and _test_internal locally, so we'll see what the bots say.

Added tests for the inline reduction helpers, too.

ATTN @stevenraphael

Comment on lines +106 to +113
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();
}();
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant