[Mlir-commits] [mlir] 08c681f - Perform memory accesses in the same addrspace as the corresponding memref.
Aart Bik
llvmlistbot at llvm.org
Thu Feb 18 12:36:33 PST 2021
Author: Andrew Pritchard
Date: 2021-02-18T12:36:16-08:00
New Revision: 08c681f645c529b24989f7a87c6919c981d1d1d2
URL: https://github.com/llvm/llvm-project/commit/08c681f645c529b24989f7a87c6919c981d1d1d2
DIFF: https://github.com/llvm/llvm-project/commit/08c681f645c529b24989f7a87c6919c981d1d1d2.diff
LOG: Perform memory accesses in the same addrspace as the corresponding memref.
It's not necessarily the case on all architectures that all memory is
addressable in addrspace 0, so casting the pointer to addrspace 0 is
liable to cause problems.
Reviewed By: aartbik, ftynse, nicolasvasilache
Differential Revision: https://reviews.llvm.org/D96380
Added:
Modified:
mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
index b6106560024c..168665e23111 100644
--- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -209,15 +209,12 @@ static LogicalResult getIndexedPtrs(ConversionPatternRewriter &rewriter,
return success();
}
-// Casts a strided element pointer to a vector pointer. The vector pointer
-// would always be on address space 0, therefore addrspacecast shall be
-// used when source/dst memrefs are not on address space 0.
+// Casts a strided element pointer to a vector pointer. The vector pointer
+// will be in the same address space as the incoming memref type.
static Value castDataPtr(ConversionPatternRewriter &rewriter, Location loc,
Value ptr, MemRefType memRefType, Type vt) {
- auto pType = LLVM::LLVMPointerType::get(vt);
- if (memRefType.getMemorySpace() == 0)
- return rewriter.create<LLVM::BitcastOp>(loc, pType, ptr);
- return rewriter.create<LLVM::AddrSpaceCastOp>(loc, pType, ptr);
+ auto pType = LLVM::LLVMPointerType::get(vt, memRefType.getMemorySpace());
+ return rewriter.create<LLVM::BitcastOp>(loc, pType, ptr);
}
static LogicalResult
diff --git a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
index 3d1294318a6e..e5c1adcee0ed 100644
--- a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
+++ b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
@@ -1147,18 +1147,18 @@ func @transfer_read_1d_non_zero_addrspace(%A : memref<?xf32, 3>, %base: index) -
// 1. Check address space for GEP is correct.
// CHECK: %[[gep:.*]] = llvm.getelementptr {{.*}} :
// CHECK-SAME: (!llvm.ptr<f32, 3>, i64) -> !llvm.ptr<f32, 3>
-// CHECK: %[[vecPtr:.*]] = llvm.addrspacecast %[[gep]] :
-// CHECK-SAME: !llvm.ptr<f32, 3> to !llvm.ptr<vector<17xf32>>
+// CHECK: %[[vecPtr:.*]] = llvm.bitcast %[[gep]] :
+// CHECK-SAME: !llvm.ptr<f32, 3> to !llvm.ptr<vector<17xf32>, 3>
//
// 2. Check address space of the memref is correct.
// CHECK: %[[c0:.*]] = constant 0 : index
// CHECK: %[[DIM:.*]] = dim %{{.*}}, %[[c0]] : memref<?xf32, 3>
//
-// 3. Check address apce for GEP is correct.
+// 3. Check address space for GEP is correct.
// CHECK: %[[gep_b:.*]] = llvm.getelementptr {{.*}} :
// CHECK-SAME: (!llvm.ptr<f32, 3>, i64) -> !llvm.ptr<f32, 3>
-// CHECK: %[[vecPtr_b:.*]] = llvm.addrspacecast %[[gep_b]] :
-// CHECK-SAME: !llvm.ptr<f32, 3> to !llvm.ptr<vector<17xf32>>
+// CHECK: %[[vecPtr_b:.*]] = llvm.bitcast %[[gep_b]] :
+// CHECK-SAME: !llvm.ptr<f32, 3> to !llvm.ptr<vector<17xf32>, 3>
// -----
More information about the Mlir-commits
mailing list