Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,8 @@ struct SimplifyDimOfAllocOp : public OpRewritePattern<memref::DimOp> {
return failure();

auto memrefType = llvm::dyn_cast<MemRefType>(dimOp.getSource().getType());
if (!memrefType || !memrefType.isDynamicDim(index.value()))
if (!memrefType || index.value() >= memrefType.getRank() ||
!memrefType.isDynamicDim(index.value()))
return failure();

auto alloc = dimOp.getSource().getDefiningOp<AllocOp>();
Expand Down
11 changes: 11 additions & 0 deletions mlir/test/Dialect/GPU/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ func.func @gpu_dim_of_alloc(%size: index) -> index {

// -----

// CHECK-LABEL: func @out_of_bound_memref.dim
// CHECK: %[[MEMREF:.[a-z0-9A-Z_]+]] = memref.dim
// CHECK: return %[[MEMREF]] : index
func.func @out_of_bound_memref.dim(%arg : memref<?xi8>, %size: index) -> index {
%c2 = arith.constant 2 : index
%1 = memref.dim %arg, %c2 : memref<?xi8>
return %1 : index
}

// -----

// CHECK-LABEL: func @simplify_gpu_launch
func.func @simplify_gpu_launch() attributes {llvm.emit_c_interface} {
%cst = arith.constant 0.000000e+00 : f32
Expand Down
Loading