[Mlir-commits] [mlir] 7965dd7 - [MLIR] Fix memref region compute for 0-d memref accesses

Uday Bondhugula llvmlistbot at llvm.org
Tue Jun 16 01:31:04 PDT 2020


Author: Uday Bondhugula
Date: 2020-06-16T13:59:53+05:30
New Revision: 7965dd79a3da76f68a65e942f2ad4d78270491e6

URL: https://github.com/llvm/llvm-project/commit/7965dd79a3da76f68a65e942f2ad4d78270491e6
DIFF: https://github.com/llvm/llvm-project/commit/7965dd79a3da76f68a65e942f2ad4d78270491e6.diff

LOG: [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

Added: 
    

Modified: 
    mlir/lib/Analysis/Utils.cpp
    mlir/test/Transforms/memref-bound-check.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Analysis/Utils.cpp b/mlir/lib/Analysis/Utils.cpp
index b43d0bedec56..40a45cece287 100644
--- a/mlir/lib/Analysis/Utils.cpp
+++ b/mlir/lib/Analysis/Utils.cpp
@@ -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();
   }
 

diff  --git a/mlir/test/Transforms/memref-bound-check.mlir b/mlir/test/Transforms/memref-bound-check.mlir
index 76ed78a76240..a8d83cc65a2c 100644
--- a/mlir/test/Transforms/memref-bound-check.mlir
+++ b/mlir/test/Transforms/memref-bound-check.mlir
@@ -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
+}


        


More information about the Mlir-commits mailing list