[Mlir-commits] [mlir] [mlir][docs] Add more examples for the "canonical form" (PR #173667)

Matthias Springer llvmlistbot at llvm.org
Sun Dec 28 09:51:47 PST 2025


================
@@ -63,30 +63,37 @@ Some important things to think about w.r.t. canonicalization patterns:
 *   Canonicalize shouldn't lose the semantic of original operation: the original
     information should always be recoverable from the transformed IR.
 
-For example, a pattern that transform
-
-```
-  %transpose = linalg.transpose
-      ins(%input : tensor<1x2x3xf32>)
-      outs(%init1 : tensor<2x1x3xf32>)
-      dimensions = [1, 0, 2]
-  %out = linalg.transpose
-      ins(%transpose: tensor<2x1x3xf32>)
-      outs(%init2 : tensor<3x1x2xf32>)
-      permutation = [2, 1, 0]
-```
-
-to
-
-```
-  %out= linalg.transpose
-      ins(%input : tensor<1x2x3xf32>)
-      outs(%init2: tensor<3x1x2xf32>)
-      permutation = [2, 0, 1]
-```
-
-is a good canonicalization pattern because it removes a redundant operation,
-making other analysis optimizations and more efficient.
+## What is the Canonical Form?
+
+There is no single formally defined canonical form in MLIR. Some dialects
+define multiple forms, depending on the transformation ([example](https://mlir.llvm.org/docs/Rationale/RationaleLinalgDialect/#interchangeability-of-formsa-nameformsa)).
+The de-facto canonical form keeps evolving, as canonicalization patterns and
+folders are getting added / removed / modified by the community.
+
+The canonicalizer pass is integral to many downstream projects but offers no
----------------
matthias-springer wrote:

I will rephrase. This was just meant to set expectations: Most folks likely don't care too much when you're changing a part of LLVM that they don't use, so you may not get much feedback on your PRs. But almost everybody is using the canonicalizer pass (and every change is affecting them directly), so you can expect to get a lot of feedback.


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


More information about the Mlir-commits mailing list