[Mlir-commits] [mlir] 34ff99a - Revert "[MLIR] Fix fold-memref-subview-ops for affine.load/store"

Tres Popp llvmlistbot at llvm.org
Thu Feb 10 01:47:06 PST 2022


Author: Tres Popp
Date: 2022-02-10T10:46:59+01:00
New Revision: 34ff99a0b7b18d8242cce7d1fe0e04e003718015

URL: https://github.com/llvm/llvm-project/commit/34ff99a0b7b18d8242cce7d1fe0e04e003718015
DIFF: https://github.com/llvm/llvm-project/commit/34ff99a0b7b18d8242cce7d1fe0e04e003718015.diff

LOG: Revert "[MLIR] Fix fold-memref-subview-ops for affine.load/store"

This reverts commit ac6cb41303450b4cf8b5c71b971b729990b93a36.

This code has a stack-use-after-scope error that can be seen with asan.

Added: 
    

Modified: 
    mlir/lib/Dialect/MemRef/Transforms/FoldSubViewOps.cpp
    mlir/test/Dialect/MemRef/fold-subview-ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/MemRef/Transforms/FoldSubViewOps.cpp b/mlir/lib/Dialect/MemRef/Transforms/FoldSubViewOps.cpp
index 5618ff8554a7b..5080a69688b9c 100644
--- a/mlir/lib/Dialect/MemRef/Transforms/FoldSubViewOps.cpp
+++ b/mlir/lib/Dialect/MemRef/Transforms/FoldSubViewOps.cpp
@@ -10,14 +10,13 @@
 // loading/storing from/to the original memref.
 //
 //===----------------------------------------------------------------------===//
-#include "mlir/Dialect/MemRef/Transforms/Passes.h"
 
 #include "mlir/Dialect/Affine/IR/AffineOps.h"
-#include "mlir/Dialect/Affine/Utils.h"
 #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/MemRef/Transforms/Passes.h"
 #include "mlir/Dialect/Vector/IR/VectorOps.h"
+#include "mlir/IR/BuiltinTypes.h"
 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
 #include "llvm/ADT/SmallBitVector.h"
 
@@ -213,20 +212,9 @@ LoadOpOfSubViewFolder<OpTy>::matchAndRewrite(OpTy loadOp,
   if (!subViewOp)
     return failure();
 
-  ValueRange indices = loadOp.indices();
-  // For affine ops, we need to apply the map to get the operands to get the
-  // "actual" indices.
-  if (auto affineLoadOp = dyn_cast<AffineLoadOp>(loadOp.getOperation())) {
-    auto expandedIndices =
-        expandAffineMap(rewriter, loadOp.getLoc(), affineLoadOp.getAffineMap(),
-                        affineLoadOp.indices());
-    if (!expandedIndices)
-      return failure();
-    indices = expandedIndices.getValue();
-  }
   SmallVector<Value, 4> sourceIndices;
-  if (failed(resolveSourceIndices(loadOp.getLoc(), rewriter, subViewOp, indices,
-                                  sourceIndices)))
+  if (failed(resolveSourceIndices(loadOp.getLoc(), rewriter, subViewOp,
+                                  loadOp.indices(), sourceIndices)))
     return failure();
 
   replaceOp(loadOp, subViewOp, sourceIndices, rewriter);
@@ -242,20 +230,9 @@ StoreOpOfSubViewFolder<OpTy>::matchAndRewrite(OpTy storeOp,
   if (!subViewOp)
     return failure();
 
-  ValueRange indices = storeOp.indices();
-  // For affine ops, we need to apply the map to get the operands to get the
-  // "actual" indices.
-  if (auto affineStoreOp = dyn_cast<AffineStoreOp>(storeOp.getOperation())) {
-    auto expandedIndices =
-        expandAffineMap(rewriter, storeOp.getLoc(),
-                        affineStoreOp.getAffineMap(), affineStoreOp.indices());
-    if (!expandedIndices)
-      return failure();
-    indices = expandedIndices.getValue();
-  }
   SmallVector<Value, 4> sourceIndices;
   if (failed(resolveSourceIndices(storeOp.getLoc(), rewriter, subViewOp,
-                                  indices, sourceIndices)))
+                                  storeOp.indices(), sourceIndices)))
     return failure();
 
   replaceOp(storeOp, subViewOp, sourceIndices, rewriter);

diff  --git a/mlir/test/Dialect/MemRef/fold-subview-ops.mlir b/mlir/test/Dialect/MemRef/fold-subview-ops.mlir
index 968ead54967d4..6f8e46fab4442 100644
--- a/mlir/test/Dialect/MemRef/fold-subview-ops.mlir
+++ b/mlir/test/Dialect/MemRef/fold-subview-ops.mlir
@@ -262,7 +262,6 @@ func @fold_vector_transfer_write_with_inner_rank_reduced_subview(
 func @fold_static_stride_subview_with_affine_load_store(%arg0 : memref<12x32xf32>, %arg1 : index, %arg2 : index, %arg3 : index, %arg4 : index) -> f32 {
   %0 = memref.subview %arg0[%arg1, %arg2][4, 4][2, 3] : memref<12x32xf32> to memref<4x4xf32, offset:?, strides: [64, 3]>
   %1 = affine.load %0[%arg3, %arg4] : memref<4x4xf32, offset:?, strides: [64, 3]>
-  // CHECK-NEXT: %[[C0:.*]] = arith.constant 0 : index
   // CHECK-NEXT: affine.apply
   // CHECK-NEXT: affine.apply
   // CHECK-NEXT: affine.load
@@ -270,11 +269,6 @@ func @fold_static_stride_subview_with_affine_load_store(%arg0 : memref<12x32xf32
   // CHECK-NEXT: affine.apply
   // CHECK-NEXT: affine.apply
   // CHECK-NEXT: affine.store
-  // Fewer operands than the memref rank.
-  // CHECK-NEXT: affine.apply
-  // CHECK-NEXT: affine.apply #{{.*}}(%[[C0]])[%{{.*}}]
-  // CHECK-NEXT: affine.store
-  affine.store %1, %0[%arg3, 0] : memref<4x4xf32, offset:?, strides: [64, 3]>
   // CHECK-NEXT: return
   return %1 : f32
 }


        


More information about the Mlir-commits mailing list