@@ -121,6 +121,25 @@ LogicalResult getVectorToLLVMAlignment(const LLVMTypeConverter &typeConverter,
121
121
return success ();
122
122
}
123
123
124
+ // Helper to resolve the alignment for vector load/store, gather and scatter
125
+ // ops. First, this method will try to obtain the preferred alignment from the
126
+ // load or store operation itself. If the store or load operation does not
127
+ // contain any preferred alignment, then it will get alignment attribute through
128
+ // the type or the backend.
129
+ template <class LoadOrStoreOp >
130
+ LogicalResult getVectorToLLVMAlignment (LoadOrStoreOp loadOrStoreOp,
131
+ const LLVMTypeConverter &typeConverter,
132
+ VectorType vectorType,
133
+ MemRefType memrefType, unsigned &align,
134
+ bool useVectorAlignment) {
135
+ if (auto alignment = loadOrStoreOp.getAlignment ()) {
136
+ align = alignment.value_or (0 );
137
+ return success ();
138
+ }
139
+ return getVectorToLLVMAlignment (typeConverter, vectorType, memrefType,
140
+ align, useVectorAlignment);
141
+ }
142
+
124
143
// Check if the last stride is non-unit and has a valid memory space.
125
144
static LogicalResult isMemRefTypeSupported (MemRefType memRefType,
126
145
const LLVMTypeConverter &converter) {
@@ -247,8 +266,9 @@ class VectorLoadStoreConversion : public ConvertOpToLLVMPattern<LoadOrStoreOp> {
247
266
MemRefType memRefTy = loadOrStoreOp.getMemRefType ();
248
267
249
268
// Resolve alignment.
250
- unsigned align = loadOrStoreOp.getAlignment ().value_or (0 );
251
- if (!align && failed (getVectorToLLVMAlignment (*this ->getTypeConverter (), vectorTy,
269
+ unsigned align;
270
+ if (failed (getVectorToLLVMAlignment (loadOrStoreOp,
271
+ *this ->getTypeConverter (), vectorTy,
252
272
memRefTy, align, useVectorAlignment)))
253
273
return rewriter.notifyMatchFailure (loadOrStoreOp,
254
274
" could not resolve alignment" );
0 commit comments