[MLIR] Fix memref region compute for 0-d memref accesses

Fix memref region compute for 0-d memref accesses in certain cases (when
there are loops surrounding such 0-d accesses).

Differential Revision: https://reviews.llvm.org/D81792
This commit is contained in:
Uday Bondhugula 2020-06-14 00:50:26 +05:30
parent e00dcf61a2
commit 7965dd79a3
2 changed files with 16 additions and 3 deletions

View File

@ -208,13 +208,17 @@ LogicalResult MemRefRegion::compute(Operation *op, unsigned loopDepth,
LLVM_DEBUG(llvm::dbgs() << "MemRefRegion::compute: " << *op
<< "depth: " << loopDepth << "\n";);
// 0-d memrefs.
if (rank == 0) {
SmallVector<AffineForOp, 4> ivs;
getLoopIVs(*op, &ivs);
SmallVector<Value, 8> regionSymbols;
assert(loopDepth <= ivs.size() && "invalid 'loopDepth'");
// The first 'loopDepth' IVs are symbols for this region.
ivs.resize(loopDepth);
SmallVector<Value, 4> regionSymbols;
extractForInductionVars(ivs, &regionSymbols);
// 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();
}

View File

@ -284,3 +284,12 @@ func @non_composed_bound_operand(%arg0: memref<1024xf32>) {
}
return
}
// CHECK-LABEL: func @zero_d_memref
func @zero_d_memref() {
%Z = alloc() : memref<f32>
affine.for %i = 0 to 100 {
affine.load %Z[] : memref<f32>
}
return
}