Skip to content

Hoist the shared dense load as a let in stage_strided_loads#8964

Open
abadams wants to merge 2 commits intomainfrom
abadams/stage_strided_loads_let
Open

Hoist the shared dense load as a let in stage_strided_loads#8964
abadams wants to merge 2 commits intomainfrom
abadams/stage_strided_loads_let

Conversation

@abadams
Copy link
Member

@abadams abadams commented Feb 25, 2026

Previously each strided load did the same dense load redundantly, and we relied on LLVM to dedup. Pulling it out as a let makes it possible in #8925 future to transpose it as one thing.

This will make it possible in future to transpose it as one thing.
Copy link
Member

@alexreinking alexreinking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with a couple clarifying questions and one comment-wording nit.

Func f;
Var x;
f(x) = buf(16 * x) + buf(16 * x + 15);
f(x) = buf(17 * x) + buf(17 * x + 15);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it so that hoisting a dense load now occurs in the case where the stride equals the vector length, so that square transposes will be handled in the next PR.

replacer.replacements.emplace(std::make_pair(alloc, l), shuf);

// We can't lift the shared load further out than the scope over
// which the loads definition occur. If k.scope is null, the loads
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar here is awkward. "over which the load's definition occurs"? "the load is valid everywhere"?

return result;
}

bool can_hoist_shared_load(const IRNode *n, const std::string &buf, const Expr &idx) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any risk of hoisting past an extern stage with a side-effect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be. I'll try to construct a failure

Comment on lines 249 to 250
// within this stmt, and there are no stores to the given buffer in the
// stmt.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test that covers the "don't hoist past a store" mistake?

@alexreinking
Copy link
Member

Failure is #8928

Also address other review comments
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.

2 participants