diff --git a/mlir/lib/Analysis/Utils.cpp b/mlir/lib/Analysis/Utils.cpp --- a/mlir/lib/Analysis/Utils.cpp +++ b/mlir/lib/Analysis/Utils.cpp @@ -208,13 +208,17 @@ LLVM_DEBUG(llvm::dbgs() << "MemRefRegion::compute: " << *op << "depth: " << loopDepth << "\n";); + // 0-d memrefs. if (rank == 0) { SmallVector ivs; getLoopIVs(*op, &ivs); - SmallVector regionSymbols; + assert(loopDepth <= ivs.size() && "invalid 'loopDepth'"); + // The first 'loopDepth' IVs are symbols for this region. + ivs.resize(loopDepth); + SmallVector regionSymbols; extractForInductionVars(ivs, ®ionSymbols); - // A rank 0 memref has a 0-d region. - cst.reset(rank, loopDepth, 0, regionSymbols); + // A 0-d memref has a 0-d region. + cst.reset(rank, loopDepth, /*numLocals=*/0, regionSymbols); return success(); } diff --git a/mlir/test/Transforms/memref-bound-check.mlir b/mlir/test/Transforms/memref-bound-check.mlir --- a/mlir/test/Transforms/memref-bound-check.mlir +++ b/mlir/test/Transforms/memref-bound-check.mlir @@ -284,3 +284,12 @@ } return } + +// CHECK-LABEL: func @zero_d_memref +func @zero_d_memref() { + %Z = alloc() : memref + affine.for %i = 0 to 100 { + affine.load %Z[] : memref + } + return +}