Skip to content

Commit d2f5741

Browse files
author
Lily Orth-Smith
committed
Add test for use-vector-alignment flag
1 parent efa44d5 commit d2f5741

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// RUN: mlir-opt -set-llvm-module-datalayout='data-layout=f32:32' %s --convert-vector-to-llvm='use-vector-alignment=1' | FileCheck %s --check-prefix=VEC-ALIGN
2+
// RUN: mlir-opt -set-llvm-module-datalayout='data-layout=v256:256' %s --convert-vector-to-llvm='use-vector-alignment=0' | FileCheck %s --check-prefix=MEMREF-ALIGN
3+
4+
5+
//===----------------------------------------------------------------------===//
6+
// vector.load
7+
//===----------------------------------------------------------------------===//
8+
9+
func.func @load(%memref : memref<200x100xf32>, %i : index, %j : index) -> vector<8xf32> {
10+
%0 = vector.load %memref[%i, %j] : memref<200x100xf32>, vector<8xf32>
11+
return %0 : vector<8xf32>
12+
}
13+
14+
// VEC-ALIGN-LABEL: func @load
15+
// VEC-ALIGN: %[[C100:.*]] = llvm.mlir.constant(100 : index) : i64
16+
// VEC-ALIGN: %[[MUL:.*]] = llvm.mul %{{.*}}, %[[C100]] : i64
17+
// VEC-ALIGN: %[[ADD:.*]] = llvm.add %[[MUL]], %{{.*}} : i64
18+
// VEC-ALIGN: %[[GEP:.*]] = llvm.getelementptr %{{.*}}[%[[ADD]]] : (!llvm.ptr, i64) -> !llvm.ptr, f32
19+
// VEC-ALIGN: llvm.load %[[GEP]] {alignment = 32 : i64} : !llvm.ptr -> vector<8xf32>
20+
21+
// MEMREF-ALIGN-LABEL: func @load
22+
// MEMREF-ALIGN: %[[C100:.*]] = llvm.mlir.constant(100 : index) : i64
23+
// MEMREF-ALIGN: %[[MUL:.*]] = llvm.mul %{{.*}}, %[[C100]] : i64
24+
// MEMREF-ALIGN: %[[ADD:.*]] = llvm.add %[[MUL]], %{{.*}} : i64
25+
// MEMREF-ALIGN: %[[GEP:.*]] = llvm.getelementptr %{{.*}}[%[[ADD]]] : (!llvm.ptr, i64) -> !llvm.ptr, f32
26+
// MEMREF-ALIGN: llvm.load %[[GEP]] {alignment = 4 : i64} : !llvm.ptr -> vector<8xf32>
27+
28+
// -----
29+
30+
//===----------------------------------------------------------------------===//
31+
// vector.store
32+
//===----------------------------------------------------------------------===//
33+
34+
func.func @store(%memref : memref<200x100xf32>, %i : index, %j : index) {
35+
%val = arith.constant dense<11.0> : vector<4xf32>
36+
vector.store %val, %memref[%i, %j] : memref<200x100xf32>, vector<4xf32>
37+
return
38+
}
39+
40+
// VEC-ALIGN-LABEL: func @store
41+
// VEC-ALIGN: %[[C100:.*]] = llvm.mlir.constant(100 : index) : i64
42+
// VEC-ALIGN: %[[MUL:.*]] = llvm.mul %{{.*}}, %[[C100]] : i64
43+
// VEC-ALIGN: %[[ADD:.*]] = llvm.add %[[MUL]], %{{.*}} : i64
44+
// VEC-ALIGN: %[[GEP:.*]] = llvm.getelementptr %{{.*}}[%[[ADD]]] : (!llvm.ptr, i64) -> !llvm.ptr, f32
45+
// VEC-ALIGN: llvm.store %{{.*}}, %[[GEP]] {alignment = 32 : i64} : vector<4xf32>, !llvm.ptr
46+
47+
// MEMREF-ALIGN-LABEL: func @store
48+
// MEMREF-ALIGN: %[[C100:.*]] = llvm.mlir.constant(100 : index) : i64
49+
// MEMREF-ALIGN: %[[MUL:.*]] = llvm.mul %{{.*}}, %[[C100]] : i64
50+
// MEMREF-ALIGN: %[[ADD:.*]] = llvm.add %[[MUL]], %{{.*}} : i64
51+
// MEMREF-ALIGN: %[[GEP:.*]] = llvm.getelementptr %{{.*}}[%[[ADD]]] : (!llvm.ptr, i64) -> !llvm.ptr, f32
52+
// MEMREF-ALIGN: llvm.store %{{.*}}, %[[GEP]] {alignment = 4 : i64} : vector<4xf32>, !llvm.ptr
53+
54+
// -----
55+
56+
//===----------------------------------------------------------------------===//
57+
// vector.maskedload
58+
//===----------------------------------------------------------------------===//
59+
60+
func.func @masked_load(%arg0: memref<?xf32>, %arg1: vector<16xi1>, %arg2: vector<16xf32>) -> vector<16xf32> {
61+
%c0 = arith.constant 0: index
62+
%0 = vector.maskedload %arg0[%c0], %arg1, %arg2 : memref<?xf32>, vector<16xi1>, vector<16xf32> into vector<16xf32>
63+
return %0 : vector<16xf32>
64+
}
65+
66+
// VEC-ALIGN-LABEL: func @masked_load
67+
// VEC-ALIGN: %[[CO:.*]] = arith.constant 0 : index
68+
// VEC-ALIGN: %[[C:.*]] = builtin.unrealized_conversion_cast %[[CO]] : index to i64
69+
// VEC-ALIGN: %[[P:.*]] = llvm.getelementptr %{{.*}}[%[[C]]] : (!llvm.ptr, i64) -> !llvm.ptr, f32
70+
// VEC-ALIGN: %[[L:.*]] = llvm.intr.masked.load %[[P]], %{{.*}}, %{{.*}} {alignment = 32 : i32} : (!llvm.ptr, vector<16xi1>, vector<16xf32>) -> vector<16xf32>
71+
// VEC-ALIGN: return %[[L]] : vector<16xf32>
72+
73+
// MEMREF-ALIGN-LABEL: func @masked_load
74+
// MEMREF-ALIGN: %[[CO:.*]] = arith.constant 0 : index
75+
// MEMREF-ALIGN: %[[C:.*]] = builtin.unrealized_conversion_cast %[[CO]] : index to i64
76+
// MEMREF-ALIGN: %[[P:.*]] = llvm.getelementptr %{{.*}}[%[[C]]] : (!llvm.ptr, i64) -> !llvm.ptr, f32
77+
// MEMREF-ALIGN: %[[L:.*]] = llvm.intr.masked.load %[[P]], %{{.*}}, %{{.*}} {alignment = 4 : i32} : (!llvm.ptr, vector<16xi1>, vector<16xf32>) -> vector<16xf32>
78+
// MEMREF-ALIGN: return %[[L]] : vector<16xf32>
79+
80+
// -----
81+
82+
//===----------------------------------------------------------------------===//
83+
// vector.maskedstore
84+
//===----------------------------------------------------------------------===//
85+
86+
func.func @masked_store(%arg0: memref<?xf32>, %arg1: vector<16xi1>, %arg2: vector<16xf32>) {
87+
%c0 = arith.constant 0: index
88+
vector.maskedstore %arg0[%c0], %arg1, %arg2 : memref<?xf32>, vector<16xi1>, vector<16xf32>
89+
return
90+
}
91+
92+
// VEC-ALIGN-LABEL: func @masked_store
93+
// VEC-ALIGN: %[[CO:.*]] = arith.constant 0 : index
94+
// VEC-ALIGN: %[[C:.*]] = builtin.unrealized_conversion_cast %[[CO]] : index to i64
95+
// VEC-ALIGN: %[[P:.*]] = llvm.getelementptr %{{.*}}[%[[C]]] : (!llvm.ptr, i64) -> !llvm.ptr, f32
96+
// VEC-ALIGN: llvm.intr.masked.store %{{.*}}, %[[P]], %{{.*}} {alignment = 32 : i32} : vector<16xf32>, vector<16xi1> into !llvm.ptr
97+
98+
// MEMREF-ALIGN-LABEL: func @masked_store
99+
// MEMREF-ALIGN: %[[CO:.*]] = arith.constant 0 : index
100+
// MEMREF-ALIGN: %[[C:.*]] = builtin.unrealized_conversion_cast %[[CO]] : index to i64
101+
// MEMREF-ALIGN: %[[P:.*]] = llvm.getelementptr %{{.*}}[%[[C]]] : (!llvm.ptr, i64) -> !llvm.ptr, f32
102+
// MEMREF-ALIGN: llvm.intr.masked.store %{{.*}}, %[[P]], %{{.*}} {alignment = 32 : i32} : vector<16xf32>, vector<16xi1> into !llvm.ptr
103+
104+
// -----
105+
106+
//===----------------------------------------------------------------------===//
107+
// vector.scatter
108+
//===----------------------------------------------------------------------===//
109+
110+
func.func @scatter(%arg0: memref<?xf32>, %arg1: vector<3xi32>, %arg2: vector<3xi1>, %arg3: vector<3xf32>) {
111+
%0 = arith.constant 0: index
112+
vector.scatter %arg0[%0][%arg1], %arg2, %arg3 : memref<?xf32>, vector<3xi32>, vector<3xi1>, vector<3xf32>
113+
return
114+
}
115+
116+
// VEC-ALIGN-LABEL: func @scatter
117+
// VEC-ALIGN: %[[P:.*]] = llvm.getelementptr %{{.*}}[%{{.*}}] : (!llvm.ptr, vector<3xi32>) -> vector<3x!llvm.ptr>, f32
118+
// VEC-ALIGN: llvm.intr.masked.scatter %{{.*}}, %[[P]], %{{.*}} {alignment = 32 : i32} : vector<3xf32>, vector<3xi1> into vector<3x!llvm.ptr>
119+
120+
// MEMREF-ALIGN-LABEL: func @scatter
121+
// MEMREF-ALIGN: %[[P:.*]] = llvm.getelementptr %{{.*}}[%{{.*}}] : (!llvm.ptr, vector<3xi32>) -> vector<3x!llvm.ptr>, f32
122+
// MEMREF-ALIGN: llvm.intr.masked.scatter %{{.*}}, %[[P]], %{{.*}} {alignment = 4 : i32} : vector<3xf32>, vector<3xi1> into vector<3x!llvm.ptr>
123+
124+
// -----
125+
126+
//===----------------------------------------------------------------------===//
127+
// vector.gather
128+
//===----------------------------------------------------------------------===//
129+
130+
func.func @gather(%arg0: memref<?xf32>, %arg1: vector<3xi32>, %arg2: vector<3xi1>, %arg3: vector<3xf32>) -> vector<3xf32> {
131+
%0 = arith.constant 0: index
132+
%1 = vector.gather %arg0[%0][%arg1], %arg2, %arg3 : memref<?xf32>, vector<3xi32>, vector<3xi1>, vector<3xf32> into vector<3xf32>
133+
return %1 : vector<3xf32>
134+
}
135+
136+
// VEC-ALIGN-LABEL: func @gather
137+
// VEC-ALIGN: %[[P:.*]] = llvm.getelementptr %{{.*}}[%{{.*}}] : (!llvm.ptr, vector<3xi32>) -> vector<3x!llvm.ptr>, f32
138+
// VEC-ALIGN: %[[G:.*]] = llvm.intr.masked.gather %[[P]], %{{.*}}, %{{.*}} {alignment = 32 : i32} : (vector<3x!llvm.ptr>, vector<3xi1>, vector<3xf32>) -> vector<3xf32>
139+
// VEC-ALIGN: return %[[G]] : vector<3xf32>
140+
141+
// MEMREF-ALIGN-LABEL: func @gather
142+
// MEMREF-ALIGN: %[[P:.*]] = llvm.getelementptr %{{.*}}[%{{.*}}] : (!llvm.ptr, vector<3xi32>) -> vector<3x!llvm.ptr>, f32
143+
// MEMREF-ALIGN: %[[G:.*]] = llvm.intr.masked.gather %[[P]], %{{.*}}, %{{.*}} {alignment = 4 : i32} : (vector<3x!llvm.ptr>, vector<3xi1>, vector<3xf32>) -> vector<3xf32>
144+
// MEMREF-ALIGN: return %[[G]] : vector<3xf32>

0 commit comments

Comments
 (0)