From: Uday Bondhugula Date: Thu, 23 Mar 2023 07:45:22 +0000 (+0530) Subject: [MLIR][Affine] Fix bug and MSAN issue in affine loop utils X-Git-Tag: upstream/17.0.6~13919 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e50f131ae6e22aefdaa502af09a3396f49726976;p=platform%2Fupstream%2Fllvm.git [MLIR][Affine] Fix bug and MSAN issue in affine loop utils Fix bug and MSAN issue in affine loop utils introduced by d25e022cd19b83c22a6022edb78c4b97a5fc1b49 (D146495). While on it, fix/clean up issues in immediately surrounding code. Differential Revision: https://reviews.llvm.org/D146698 --- diff --git a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp index 38d660d..1e567a6 100644 --- a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp @@ -2057,6 +2057,8 @@ static LogicalResult generateCopy( OpBuilder topBuilder(f.getBody()); Value zeroIndex = topBuilder.create(f.getLoc(), 0); + *sizeInBytes = 0; + if (begin == end) return success(); @@ -2105,7 +2107,6 @@ static LogicalResult generateCopy( if (*numElements == 0) { LLVM_DEBUG(llvm::dbgs() << "Nothing to copy\n"); - *sizeInBytes = 0; return success(); } @@ -2183,8 +2184,7 @@ static LogicalResult generateCopy( // fastMemRefType is a constant shaped memref. auto maySizeInBytes = getIntOrFloatMemRefSizeInBytes(fastMemRefType); // We don't account for things of unknown size. - if (!maySizeInBytes) - maySizeInBytes = 0; + *sizeInBytes = maySizeInBytes ? *maySizeInBytes : 0; LLVM_DEBUG(emitRemarkForBlock(*block) << "Creating fast buffer of type " << fastMemRefType @@ -2193,7 +2193,6 @@ static LogicalResult generateCopy( } else { // Reuse the one already created. fastMemRef = fastBufferMap[memref]; - *sizeInBytes = 0; } auto numElementsSSA = top.create(loc, *numElements); @@ -2554,13 +2553,13 @@ LogicalResult mlir::affineDataCopyGenerate(Block::iterator begin, if (llvm::DebugFlag && (forOp = dyn_cast(&*begin))) { LLVM_DEBUG(forOp.emitRemark() << llvm::divideCeil(totalCopyBuffersSizeInBytes, 1024) - << " KiB of copy buffers in fast memory space for this block\n"); + << " KiB of copy buffers in fast memory space for this block"); } if (totalCopyBuffersSizeInBytes > copyOptions.fastMemCapacityBytes) { - StringRef str = "Total size of all copy buffers' for this block " - "exceeds fast memory capacity\n"; - block->getParentOp()->emitWarning(str); + block->getParentOp()->emitWarning( + "total size of all copy buffers' for this block exceeds fast memory " + "capacity"); } return success();