[Mlir-commits] [mlir] [mlir][linalg] Add folder for `linalg.index` (PR #136640)

Andrzej WarzyƄski llvmlistbot at llvm.org
Tue Apr 22 07:51:11 PDT 2025


================
@@ -305,6 +305,86 @@ func.func @self_copy(%arg0 : memref<2x3x?x4xf32>) {
 }
 
 // -----
+
+// CHECK: func @fold_linalg_index_tensor_static
+func.func @fold_linalg_index_tensor_static(%0: tensor<4x16xi32>, %1: tensor<1x16xi32>,
+                                           %2: tensor<4x1xi32>) -> tensor<4x1xi32> {
+// CHECK-NEXT: linalg.generic
+// CHECK:        %[[IDX_0:.+]] = linalg.index 0 : index
+// CHECK-NOT:    linalg.index 1
----------------
banach-space wrote:

> ```
> // CHECK-NOT: linalg.index 1
> // CHECK: %[[IDX_0:.+]] = linalg.index 0 : index
> ```
> Wouldn't that just ensure that `linalg.index 1` does not appear before `linalg.index 0`?

On re-reading the docs, I think that you are right.

> I see the CHECK-NOT as primarily there for readability indicating what folding occurred.

Sure, but it won't guarantee that `linalg.index 1` will be removed, right? It simply checks it does not appear in that particular place (between `linalg.index 0` and `linalg.index 2`). `CHECK-NEXT` would take care of that though.

This is really a side/non-blocking conversation. I am actually interested in finding a good/succinct pattern here. From what I can tell, even with `CHECK-NOT` we could be getting `linalg.index 1` (that could be dead anyway).

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


More information about the Mlir-commits mailing list