[Mlir-commits] [mlir] [mlir] Add use-vector-alignment flag to ConvertVectorToLLVMPass (PR #137389)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Thu May 1 05:04:12 PDT 2025
================
@@ -0,0 +1,144 @@
+// RUN: mlir-opt %s --convert-vector-to-llvm='use-vector-alignment=0' --split-input-file | FileCheck %s --check-prefix=MEMREF-ALIGN
+// RUN: mlir-opt %s --convert-vector-to-llvm='use-vector-alignment=1' --split-input-file | FileCheck %s --check-prefix=VEC-ALIGN
+
+
+//===----------------------------------------------------------------------===//
+// vector.load
+//===----------------------------------------------------------------------===//
+
+func.func @load(%base : memref<200x100xf32>, %i : index, %j : index) -> vector<8xf32> {
+ %0 = vector.load %base[%i, %j] : memref<200x100xf32>, vector<8xf32>
+ return %0 : vector<8xf32>
+}
+
+// VEC-ALIGN-LABEL: func @load
+// VEC-ALIGN: %[[C100:.*]] = llvm.mlir.constant(100 : index) : i64
+// VEC-ALIGN: %[[MUL:.*]] = llvm.mul %{{.*}}, %[[C100]] : i64
+// VEC-ALIGN: %[[ADD:.*]] = llvm.add %[[MUL]], %{{.*}} : i64
+// VEC-ALIGN: %[[GEP:.*]] = llvm.getelementptr %{{.*}}[%[[ADD]]] : (!llvm.ptr, i64) -> !llvm.ptr, f32
+// VEC-ALIGN: llvm.load %[[GEP]] {alignment = 32 : i64} : !llvm.ptr -> vector<8xf32>
+
+// MEMREF-ALIGN-LABEL: func @load
+// MEMREF-ALIGN: %[[C100:.*]] = llvm.mlir.constant(100 : index) : i64
+// MEMREF-ALIGN: %[[MUL:.*]] = llvm.mul %{{.*}}, %[[C100]] : i64
+// MEMREF-ALIGN: %[[ADD:.*]] = llvm.add %[[MUL]], %{{.*}} : i64
+// MEMREF-ALIGN: %[[GEP:.*]] = llvm.getelementptr %{{.*}}[%[[ADD]]] : (!llvm.ptr, i64) -> !llvm.ptr, f32
+// MEMREF-ALIGN: llvm.load %[[GEP]] {alignment = 4 : i64} : !llvm.ptr -> vector<8xf32>
----------------
banach-space wrote:
Since we only care about the alignment here (and the rest of the conversion logic is already well tested elsewhere), I think it would be fine to reduce the CHECK lines to something like:
```
// ALL-LABEL: func @load
// VEC-ALIGN: llvm.load %[[GEP]] {alignment = 32 : i64} : !llvm.ptr -> vector<8xf32>
// MEMREF-ALIGN: llvm.load %[[GEP]] {alignment = 4 : i64} : !llvm.ptr -> vector<8xf32>
```
This is mostly in the spirit of "less is more", but it's also consistent with our [FileCheck best practices](https://mlir.llvm.org/getting_started/TestingGuide/#filecheck-best-practices):
* "Tests should be minimal, and only check what is absolutely necessary."
Also, note that you can use a dedicated prefix for lines shared between configurations. For example: https://github.com/llvm/llvm-project/blob/082598a64d1f3d583c7ae979681df90f9f9c0f63/mlir/test/Dialect/Vector/linearize.mlir#L5
https://github.com/llvm/llvm-project/pull/137389
More information about the Mlir-commits
mailing list