forked from OSchip/llvm-project
[mlir][MemRef] Fix MemRefCastOpLowering for 32 bit index type.
The lowering creates llvm.insertvalue with the rank value, so it needs to use index type instead of 64 bit integer type. Otherwise, we get an error: llvm.insertvalue' op Type mismatch: cannot insert 'i64' into '!llvm.struct<(i32, ptr<i8>)>' Differential Revision: https://reviews.llvm.org/D119534
This commit is contained in:
parent
855cd847f7
commit
5b02a48085
|
@ -794,8 +794,7 @@ struct MemRefCastOpLowering : public ConvertOpToLLVMPattern<memref::CastOp> {
|
||||||
.getResult();
|
.getResult();
|
||||||
// rank = ConstantOp srcRank
|
// rank = ConstantOp srcRank
|
||||||
auto rankVal = rewriter.create<LLVM::ConstantOp>(
|
auto rankVal = rewriter.create<LLVM::ConstantOp>(
|
||||||
loc, typeConverter->convertType(rewriter.getIntegerType(64)),
|
loc, getIndexType(), rewriter.getIndexAttr(rank));
|
||||||
rewriter.getI64IntegerAttr(rank));
|
|
||||||
// undef = UndefOp
|
// undef = UndefOp
|
||||||
UnrankedMemRefDescriptor memRefDesc =
|
UnrankedMemRefDescriptor memRefDesc =
|
||||||
UnrankedMemRefDescriptor::undef(rewriter, loc, targetStructType);
|
UnrankedMemRefDescriptor::undef(rewriter, loc, targetStructType);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// RUN: mlir-opt -split-input-file -convert-memref-to-llvm %s | FileCheck %s
|
// RUN: mlir-opt -split-input-file -convert-memref-to-llvm %s | FileCheck %s
|
||||||
// RUN: mlir-opt -split-input-file -convert-memref-to-llvm='use-aligned-alloc=1' %s | FileCheck %s --check-prefix=ALIGNED-ALLOC
|
// RUN: mlir-opt -split-input-file -convert-memref-to-llvm='use-aligned-alloc=1' %s | FileCheck %s --check-prefix=ALIGNED-ALLOC
|
||||||
|
// RUN: mlir-opt -split-input-file -convert-memref-to-llvm='index-bitwidth=32' %s | FileCheck --check-prefix=CHECK32 %s
|
||||||
|
|
||||||
// CHECK-LABEL: func @mixed_alloc(
|
// CHECK-LABEL: func @mixed_alloc(
|
||||||
// CHECK: %[[Marg:.*]]: index, %[[Narg:.*]]: index)
|
// CHECK: %[[Marg:.*]]: index, %[[Narg:.*]]: index)
|
||||||
|
@ -326,15 +327,24 @@ func @memref_cast_mixed_to_mixed(%mixed : memref<42x?xf32>) {
|
||||||
// -----
|
// -----
|
||||||
|
|
||||||
// CHECK-LABEL: func @memref_cast_ranked_to_unranked
|
// CHECK-LABEL: func @memref_cast_ranked_to_unranked
|
||||||
|
// CHECK32-LABEL: func @memref_cast_ranked_to_unranked
|
||||||
func @memref_cast_ranked_to_unranked(%arg : memref<42x2x?xf32>) {
|
func @memref_cast_ranked_to_unranked(%arg : memref<42x2x?xf32>) {
|
||||||
// CHECK-DAG: %[[c:.*]] = llvm.mlir.constant(1 : index) : i64
|
// CHECK-DAG: %[[c:.*]] = llvm.mlir.constant(1 : index) : i64
|
||||||
// CHECK-DAG: %[[p:.*]] = llvm.alloca %[[c]] x !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<3 x i64>, array<3 x i64>)> : (i64) -> !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i64, array<3 x i64>, array<3 x i64>)>>
|
// CHECK-DAG: %[[p:.*]] = llvm.alloca %[[c]] x !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<3 x i64>, array<3 x i64>)> : (i64) -> !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i64, array<3 x i64>, array<3 x i64>)>>
|
||||||
// CHECK-DAG: llvm.store %{{.*}}, %[[p]] : !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i64, array<3 x i64>, array<3 x i64>)>>
|
// CHECK-DAG: llvm.store %{{.*}}, %[[p]] : !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i64, array<3 x i64>, array<3 x i64>)>>
|
||||||
// CHECK-DAG: %[[p2:.*]] = llvm.bitcast %[[p]] : !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i64, array<3 x i64>, array<3 x i64>)>> to !llvm.ptr<i8>
|
// CHECK-DAG: %[[p2:.*]] = llvm.bitcast %[[p]] : !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i64, array<3 x i64>, array<3 x i64>)>> to !llvm.ptr<i8>
|
||||||
// CHECK-DAG: %[[r:.*]] = llvm.mlir.constant(3 : i64) : i64
|
// CHECK-DAG: %[[r:.*]] = llvm.mlir.constant(3 : index) : i64
|
||||||
// CHECK : llvm.mlir.undef : !llvm.struct<(i64, ptr<i8>)>
|
// CHECK : llvm.mlir.undef : !llvm.struct<(i64, ptr<i8>)>
|
||||||
// CHECK-DAG: llvm.insertvalue %[[r]], %{{.*}}[0] : !llvm.struct<(i64, ptr<i8>)>
|
// CHECK-DAG: llvm.insertvalue %[[r]], %{{.*}}[0] : !llvm.struct<(i64, ptr<i8>)>
|
||||||
// CHECK-DAG: llvm.insertvalue %[[p2]], %{{.*}}[1] : !llvm.struct<(i64, ptr<i8>)>
|
// CHECK-DAG: llvm.insertvalue %[[p2]], %{{.*}}[1] : !llvm.struct<(i64, ptr<i8>)>
|
||||||
|
// CHECK32-DAG: %[[c:.*]] = llvm.mlir.constant(1 : index) : i64
|
||||||
|
// CHECK32-DAG: %[[p:.*]] = llvm.alloca %[[c]] x !llvm.struct<(ptr<f32>, ptr<f32>, i32, array<3 x i32>, array<3 x i32>)> : (i64) -> !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i32, array<3 x i32>, array<3 x i32>)>>
|
||||||
|
// CHECK32-DAG: llvm.store %{{.*}}, %[[p]] : !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i32, array<3 x i32>, array<3 x i32>)>>
|
||||||
|
// CHECK32-DAG: %[[p2:.*]] = llvm.bitcast %[[p]] : !llvm.ptr<struct<(ptr<f32>, ptr<f32>, i32, array<3 x i32>, array<3 x i32>)>> to !llvm.ptr<i8>
|
||||||
|
// CHECK32-DAG: %[[r:.*]] = llvm.mlir.constant(3 : index) : i32
|
||||||
|
// CHECK32 : llvm.mlir.undef : !llvm.struct<(i32, ptr<i8>)>
|
||||||
|
// CHECK32-DAG: llvm.insertvalue %[[r]], %{{.*}}[0] : !llvm.struct<(i32, ptr<i8>)>
|
||||||
|
// CHECK32-DAG: llvm.insertvalue %[[p2]], %{{.*}}[1] : !llvm.struct<(i32, ptr<i8>)>
|
||||||
%0 = memref.cast %arg : memref<42x2x?xf32> to memref<*xf32>
|
%0 = memref.cast %arg : memref<42x2x?xf32> to memref<*xf32>
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ func @return_var_memref(%arg0: memref<4x3xf32>) -> memref<*xf32> attributes { ll
|
||||||
// Match the construction of the unranked descriptor.
|
// Match the construction of the unranked descriptor.
|
||||||
// CHECK: %[[ALLOCA:.*]] = llvm.alloca
|
// CHECK: %[[ALLOCA:.*]] = llvm.alloca
|
||||||
// CHECK: %[[MEMORY:.*]] = llvm.bitcast %[[ALLOCA]]
|
// CHECK: %[[MEMORY:.*]] = llvm.bitcast %[[ALLOCA]]
|
||||||
// CHECK: %[[RANK:.*]] = llvm.mlir.constant(2 : i64)
|
// CHECK: %[[RANK:.*]] = llvm.mlir.constant(2 : index)
|
||||||
// CHECK: %[[DESC_0:.*]] = llvm.mlir.undef : !llvm.struct<(i64, ptr<i8>)>
|
// CHECK: %[[DESC_0:.*]] = llvm.mlir.undef : !llvm.struct<(i64, ptr<i8>)>
|
||||||
// CHECK: %[[DESC_1:.*]] = llvm.insertvalue %[[RANK]], %[[DESC_0]][0]
|
// CHECK: %[[DESC_1:.*]] = llvm.insertvalue %[[RANK]], %[[DESC_0]][0]
|
||||||
// CHECK: %[[DESC_2:.*]] = llvm.insertvalue %[[MEMORY]], %[[DESC_1]][1]
|
// CHECK: %[[DESC_2:.*]] = llvm.insertvalue %[[MEMORY]], %[[DESC_1]][1]
|
||||||
|
|
Loading…
Reference in New Issue