[Mlir-commits] [mlir] [mlir][docs] Update documentation for canonicalize. (PR #99753)
Mehdi Amini
llvmlistbot at llvm.org
Sat Jul 20 14:17:05 PDT 2024
================
@@ -51,6 +55,61 @@ Some important things to think about w.r.t. canonicalization patterns:
* It is always good to eliminate operations entirely when possible, e.g. by
folding known identities (like "x + 0 = x").
+* Canonicalization isn't a great place to put pattens with expensive running
+ time (i.e. have O(n) complexity) or complicated cost models.
+
+* 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
+
+```
+ %0 = tensor.insert_slice %slice into
+ %x[0, 0, 0, 0, 0][1, 1, 1, 16, 32][1, 1, 1, 1, 1] :
+ tensor<16x32xf32> into tensor<1x1x1x16x32xf32>
+```
+
+to
+
+```
+ %0 = tensor.expand_shape %slice[[0,1,2,3], [4]] :
+ tensor<16x32xf32> into tensor<1x1x1x16x32xf32>
+```
+
+is not a good canonicalize pattern because it lose the destination style
+semantic.
----------------
joker-eph wrote:
I don't know what "lose the destination style semantic" means, nor why it would be a bad canonicalization.
I think we should stick to very obvious examples here.
https://github.com/llvm/llvm-project/pull/99753
More information about the Mlir-commits
mailing list