File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -2075,7 +2075,8 @@ struct SimplifyDimOfAllocOp : public OpRewritePattern<memref::DimOp> {
20752075 return failure ();
20762076
20772077 auto memrefType = llvm::dyn_cast<MemRefType>(dimOp.getSource ().getType ());
2078- if (!memrefType || !memrefType.isDynamicDim (index.value ()))
2078+ if (!memrefType || index.value () >= memrefType.getRank () ||
2079+ !memrefType.isDynamicDim (index.value ()))
20792080 return failure ();
20802081
20812082 auto alloc = dimOp.getSource ().getDefiningOp <AllocOp>();
Original file line number Diff line number Diff line change @@ -152,6 +152,17 @@ func.func @gpu_dim_of_alloc(%size: index) -> index {
152152
153153// -----
154154
155+ // CHECK-LABEL: func @out_of_bound_memref.dim
156+ // CHECK: %[[MEMREF:.[a-z0-9A-Z_]+]] = memref.dim
157+ // CHECK: return %[[MEMREF]] : index
158+ func.func @out_of_bound_memref.dim (%arg : memref <?xi8 >, %size: index ) -> index {
159+ %c2 = arith.constant 2 : index
160+ %1 = memref.dim %arg , %c2 : memref <?xi8 >
161+ return %1 : index
162+ }
163+
164+ // -----
165+
155166// CHECK-LABEL: func @simplify_gpu_launch
156167func.func @simplify_gpu_launch () attributes {llvm.emit_c_interface } {
157168 %cst = arith.constant 0.000000e+00 : f32
You can’t perform that action at this time.
0 commit comments