[PATCH] D79246: [mlir][vector] set alignment when lowering transfer_read and transfer_write.
Wen-Heng (Jack) Chung via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 17:14:47 PDT 2020
whchung created this revision.
whchung added projects: LLVM, MLIR.
Herald added subscribers: llvm-commits, Kayjukh, frgossen, grosul1, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, jpienaar, rriddle, mehdi_amini.
Herald added a reviewer: aartbik.
Herald added a reviewer: ftynse.
whchung added a comment.
@ftynse This patch is somewhat related to our discussion in D79019 <https://reviews.llvm.org/D79019>. It now becomes evident it's better to specify target triple and data layout in llvm dialect.
When emitting masked load / store, set alignment from data layout.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79246
Files:
mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
Index: mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
===================================================================
--- mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
+++ mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
@@ -803,7 +803,7 @@
// CHECK: %[[PASS_THROUGH:.*]] = llvm.mlir.constant(dense<7.000000e+00> :
// CHECK-SAME: vector<17xf32>) : !llvm<"<17 x float>">
// CHECK: %[[loaded:.*]] = llvm.intr.masked.load %[[vecPtr]], %[[mask]],
-// CHECK-SAME: %[[PASS_THROUGH]] {alignment = 1 : i32} :
+// CHECK-SAME: %[[PASS_THROUGH]] {alignment = 128 : i32} :
// CHECK-SAME: (!llvm<"<17 x float>*">, !llvm<"<17 x i1>">, !llvm<"<17 x float>">) -> !llvm<"<17 x float>">
//
@@ -835,7 +835,7 @@
//
// 5. Rewrite as a masked write.
// CHECK: llvm.intr.masked.store %[[loaded]], %[[vecPtr_b]], %[[mask_b]]
-// CHECK-SAME: {alignment = 1 : i32} :
+// CHECK-SAME: {alignment = 128 : i32} :
// CHECK-SAME: !llvm<"<17 x float>">, !llvm<"<17 x i1>"> into !llvm<"<17 x float>*">
func @transfer_read_2d_to_1d(%A : memref<?x?xf32>, %base0: index, %base1: index) -> vector<17xf32> {
Index: mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
===================================================================
--- mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -752,6 +752,15 @@
Operation *op, ArrayRef<Value> operands, Value dataPtr,
Value mask);
+static std::pair<LLVM::LLVMType, unsigned>
+getLLVMTypeAndAlignment(LLVMTypeConverter &typeConverter, Type type) {
+ auto toLLVMTy = [&](Type t) { return typeConverter.convertType(t); };
+ auto llvmType = toLLVMTy(type).template cast<LLVM::LLVMType>();
+ auto dataLayout = typeConverter.getDialect()->getLLVMModule().getDataLayout();
+ auto align = dataLayout.getPrefTypeAlignment(llvmType.getUnderlyingType());
+ return std::make_pair(llvmType, align);
+}
+
template <>
void replaceTransferOp<TransferReadOp>(ConversionPatternRewriter &rewriter,
LLVMTypeConverter &typeConverter,
@@ -764,10 +773,13 @@
Value fill = rewriter.create<SplatOp>(loc, fillType, xferOp.padding());
fill = rewriter.create<LLVM::DialectCastOp>(loc, toLLVMTy(fillType), fill);
- auto vecTy = toLLVMTy(xferOp.getVectorType()).template cast<LLVM::LLVMType>();
+ LLVM::LLVMType vecTy;
+ unsigned align;
+ std::tie(vecTy, align) =
+ getLLVMTypeAndAlignment(typeConverter, xferOp.getVectorType());
rewriter.replaceOpWithNewOp<LLVM::MaskedLoadOp>(
op, vecTy, dataPtr, mask, ValueRange{fill},
- rewriter.getI32IntegerAttr(1));
+ rewriter.getI32IntegerAttr(align));
}
template <>
@@ -777,8 +789,14 @@
ArrayRef<Value> operands, Value dataPtr,
Value mask) {
auto adaptor = TransferWriteOpOperandAdaptor(operands);
+
+ auto xferOp = cast<TransferWriteOp>(op);
+ LLVM::LLVMType vecTy;
+ unsigned align;
+ std::tie(vecTy, align) =
+ getLLVMTypeAndAlignment(typeConverter, xferOp.getVectorType());
rewriter.replaceOpWithNewOp<LLVM::MaskedStoreOp>(
- op, adaptor.vector(), dataPtr, mask, rewriter.getI32IntegerAttr(1));
+ op, adaptor.vector(), dataPtr, mask, rewriter.getI32IntegerAttr(align));
}
static TransferReadOpOperandAdaptor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79246.261482.patch
Type: text/x-patch
Size: 3420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200502/3a610ad1/attachment.bin>
More information about the llvm-commits
mailing list