[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
Tue May 5 15:08:43 PDT 2020
whchung updated this revision to Diff 262229.
whchung added a comment.
Address code review comments adding more checks.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79246/new/
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
@@ -818,7 +818,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>">
//
@@ -850,7 +850,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,19 @@
Operation *op, ArrayRef<Value> operands, Value dataPtr,
Value mask);
+LogicalResult getLLVMTypeAndAlignment(LLVMTypeConverter &typeConverter,
+ Type type, LLVM::LLVMType &llvmType,
+ unsigned &align) {
+ auto convertedType = typeConverter.convertType(type);
+ if (!convertedType)
+ return failure();
+
+ llvmType = convertedType.template cast<LLVM::LLVMType>();
+ auto dataLayout = typeConverter.getDialect()->getLLVMModule().getDataLayout();
+ align = dataLayout.getPrefTypeAlignment(llvmType.getUnderlyingType());
+ return success();
+}
+
template <>
void replaceTransferOp<TransferReadOp>(ConversionPatternRewriter &rewriter,
LLVMTypeConverter &typeConverter,
@@ -764,10 +777,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>();
- rewriter.replaceOpWithNewOp<LLVM::MaskedLoadOp>(
- op, vecTy, dataPtr, mask, ValueRange{fill},
- rewriter.getI32IntegerAttr(1));
+ LLVM::LLVMType vecTy;
+ unsigned align;
+ if (succeeded(getLLVMTypeAndAlignment(typeConverter, xferOp.getVectorType(),
+ vecTy, align)))
+ rewriter.replaceOpWithNewOp<LLVM::MaskedLoadOp>(
+ op, vecTy, dataPtr, mask, ValueRange{fill},
+ rewriter.getI32IntegerAttr(align));
}
template <>
@@ -777,8 +793,14 @@
ArrayRef<Value> operands, Value dataPtr,
Value mask) {
auto adaptor = TransferWriteOpOperandAdaptor(operands);
- rewriter.replaceOpWithNewOp<LLVM::MaskedStoreOp>(
- op, adaptor.vector(), dataPtr, mask, rewriter.getI32IntegerAttr(1));
+
+ auto xferOp = cast<TransferWriteOp>(op);
+ LLVM::LLVMType vecTy;
+ unsigned align;
+ if (succeeded(getLLVMTypeAndAlignment(typeConverter, xferOp.getVectorType(),
+ vecTy, align)))
+ rewriter.replaceOpWithNewOp<LLVM::MaskedStoreOp>(
+ op, adaptor.vector(), dataPtr, mask, rewriter.getI32IntegerAttr(align));
}
static TransferReadOpOperandAdaptor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79246.262229.patch
Type: text/x-patch
Size: 3752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200505/ed3a3173/attachment.bin>
More information about the llvm-commits
mailing list