Skip to content

Rewrite broadcast->layout - #5141

Open
pfultz2 wants to merge 5 commits into
developfrom
layout-broadcast
Open

Rewrite broadcast->layout#5141
pfultz2 wants to merge 5 commits into
developfrom
layout-broadcast

Conversation

@pfultz2

@pfultz2 pfultz2 commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Technical Details

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

Follow the LLVM AI Tool Use Policy for contributions using AI.

Copilot AI lite review requested due to automatic review settings August 16, 2026 20:22
@pfultz2
pfultz2 requested a review from causten as a code owner August 16, 2026 20:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the simplify_reshapes optimization pipeline to rewrite layout(broadcast(x)) / layout(multibroadcast(x)) into broadcast(layout(x)) / multibroadcast(layout(x)). This reduces unnecessary materialization by applying the layout transformation only to the unique (non-broadcasted) data, keeping broadcasted dimensions as broadcasted for downstream optimization and codegen.

Changes:

  • Add a simplify_reshapes matcher (find_layout_broadcast) that pushes layout through broadcast/multibroadcast for static shapes.
  • Compute an “inner” layout permutation that preserves the relative memory-ordering of the original input-aligned axes.
  • Add unit tests covering multibroadcast and broadcast cases (including different broadcast axes) to validate the rewrite.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/simplify_reshapes.cpp Adds a new simplify_reshapes rewrite to push layout before broadcast/multibroadcast to avoid full materialization of broadcasted outputs.
test/simplify_reshapes_test.cpp Adds regression tests ensuring the new layoutbroadcast rewrite produces the expected transformed module.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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