Eliminate concat after reshapes - #5137
Conversation
Regressions detected 🔴 * No develop baseline was found for this PR's branch point; compared against the latest available develop run instead. |
|
There was a problem hiding this comment.
Pull request overview
This PR extends the eliminate_concat optimization to elide more concats when inputs are produced through invertible view chains (e.g., transpose/reshape), enabling producers to write directly into slices/views of a super-buffer. It also adjusts GPU precompile_op shape reporting to propagate the actual output-buffer layout (strides) so downstream shape/layout expectations match what kernels write.
Changes:
- Teach
eliminate_concatto walk/invert view chains and replace a producer’s output allocation with an inverse-view into the concat super-buffer when safe. - Update GPU
precompile_op::compute_shapeto return the provided output-buffer layout when it matches element type + lens but differs in layout. - Refresh and add tests covering concat elimination through view chains, including new
test/verifycases for alias vs copy fallback.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/eliminate_concat.cpp |
Adds view-chain discovery/inversion and copy-elision planning for concat elimination. |
src/targets/gpu/compile_ops.cpp |
Makes precompile_op report the output buffer’s layout when aliasing into larger buffers. |
test/eliminate_concat_test.cpp |
Updates existing expected-module tests and adds new unit tests for reshape-chain and slice-input behavior. |
test/verify/test_concat_view_chain_alias.cpp |
New verify test validating aliasing through transpose+reshape view chains. |
test/verify/test_concat_view_chain_copy.cpp |
New verify test validating copy fallback when inverse view cannot alias safely. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| auto [producer, chain] = get_view_chain(input); | ||
| if(not can_write_inplace(producer)) | ||
| return std::nullopt; | ||
| if(not slice_shape.packed() and not opt->supports_non_packed_output(producer, axis)) | ||
| return std::nullopt; | ||
| // other users just read the strided view; the caller checks that | ||
| // they support non-packed inputs | ||
| if(chain.empty()) | ||
| return plan{producer}; | ||
| if(producer->outputs().size() != 1) | ||
| return std::nullopt; | ||
| auto inverse = invert_view_chain(chain, producer->get_shape(), slice_shape); | ||
| if(not inverse.has_value()) | ||
| return std::nullopt; | ||
| return plan{producer, *inverse}; | ||
| } |
Motivation
Technical Details
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot ApplicableFollow the LLVM AI Tool Use Policy for contributions using AI.