[Mlir-commits] [mlir] [mlir][linalg] Add pattern to clean unused results after fusion (PR #158627)

Pavel Lipskiy llvmlistbot at llvm.org
Tue Sep 16 05:50:35 PDT 2025


pavlips wrote:

Hey @MaheshRavishankar , thanks for taking a look! 

>From my rough understanding `populateEraseUnusedOperandsAndResultsPatterns` erases outs[i] and its result only when the result is dead and the tied out’s block-arg is unused in the payload or only in `linalg.yield` with the correct index.

After fusion, there are cases where the **payload still reads that tied block-arg to build another live result**, but the corresponding result is unused. In that situation **the pattern doesn’t fire**; the op retains the outs[i]/result pair, which prevents further fusion and harms readability.

This patch reclassifies that outs[i] as an input and drops the corresponding result **(not erases them)**. **The `@drop_unused_results test` demonstrates the case where the existing pattern doesn't fire.** 

I hope this is more of a clear explanation; please let me know if something is confusing. 

https://github.com/llvm/llvm-project/pull/158627


More information about the Mlir-commits mailing list