[Mlir-commits] [mlir] [mlir][scf] Add simple LICM pattern for `scf.while` (PR #76370)

Renato Golin llvmlistbot at llvm.org
Sat Jan 6 04:22:49 PST 2024


rengolin wrote:

> My interpretation (admittedly not based on docs but inferred from use cases) was that canonicalization were a set of always good simplifications that allowed the rest of the compiler to make it simpler for other transformations to decide which form of IR to expect.

Not _just_ "always good", necessary. Without canonicalization, passes down the pipeline cannot assume anything and the complexity of pattern matching expressions can go combinatorial.

> My concern is that this could significantly reduce user control over what transformations are applied as canonicalization has to be applied as all or nothing and those patterns are usually not exposed otherwise, preventing any alternative solution for users.

I think people are mixing two different things:
* Canonicalization between "independent stages" of the pipeline, where one or more passes work in unison. For example one-shot bufferization and follow up cleanups, tile-and-fuse, lowering dialects, etc. Canonicalization between these stages is necessary to make sure that the stages have wiggle room to improve without breaking following stages.
* Canonicalization between individual passes on the same "stage". For example, running ownership based deallocation right after bufferization. Canonicalization patterns can destroy the interim form of IR operations and make it harder for the second pass to find knowledge (without additional analysis passes).

Questions about the validity of keeping interim information that is prone to cleanups as a dependency between transformation passes on the side, there are always some information being left by analysis passes to following transformation passes that need to be kept. So it's not a clear-cut answer here.

Other artefacts (like annotation, properties, metadata) could be created and managed for different purposes, but having IR ops in a "known but not canonical" shape between two specific passes isn't unheard of and may be beneficial in some cases.

Now, back to this PR, I agree with @joker-eph here: LICM, even a simplified version, isn't canonicalization, it's a transformation.

@Hardcode84 if you add this pattern to the LICM pass and run it before your conversion, would that solve your problem?

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


More information about the Mlir-commits mailing list