[Mlir-commits] [mlir] b6164ec - [MLIR] Add missing check for unsupported affine dependence analysis
Uday Bondhugula
llvmlistbot at llvm.org
Wed Aug 10 17:33:38 PDT 2022
Author: Uday Bondhugula
Date: 2022-08-11T06:02:39+05:30
New Revision: b6164ec9c2fb7f6448fb3821f06e30ada32a3cd9
URL: https://github.com/llvm/llvm-project/commit/b6164ec9c2fb7f6448fb3821f06e30ada32a3cd9
DIFF: https://github.com/llvm/llvm-project/commit/b6164ec9c2fb7f6448fb3821f06e30ada32a3cd9.diff
LOG: [MLIR] Add missing check for unsupported affine dependence analysis
Add missing check in affine dependence analysis when dependence analysis
isn't possible due to the ops being in different affine scopes. The
lack of such a check could lead to a crash or incorrect behavior in
several dependent utilities.
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D131556
Added:
Modified:
mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp
mlir/test/Dialect/Affine/scalrep.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp b/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp
index f861abe6b331a..8d78320b5b8eb 100644
--- a/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp
@@ -609,6 +609,10 @@ DependenceResult mlir::checkMemrefAccessDependence(
!isa<AffineWriteOpInterface>(dstAccess.opInst))
return DependenceResult::NoDependence;
+ // We can't analyze further if the ops lie in
diff erent affine scopes.
+ if (getAffineScope(srcAccess.opInst) != getAffineScope(dstAccess.opInst))
+ return DependenceResult::Failure;
+
// Create access relation from each MemRefAccess.
FlatAffineRelation srcRel, dstRel;
if (failed(srcAccess.getAccessRelation(srcRel)))
diff --git a/mlir/test/Dialect/Affine/scalrep.mlir b/mlir/test/Dialect/Affine/scalrep.mlir
index 062a8d55327dc..3bb8d1075d32e 100644
--- a/mlir/test/Dialect/Affine/scalrep.mlir
+++ b/mlir/test/Dialect/Affine/scalrep.mlir
@@ -744,3 +744,24 @@ func.func @affine_store_load_in_scope(%memref: memref<1x4094x510x1xf32>, %memref
}
return
}
+
+// No scalrep will be performed here but we ensure dependence correctly fails.
+
+// CHECK-LABEL: func @affine_load_store_in_
diff erent_scopes
+func.func @affine_load_store_in_
diff erent_scopes() -> memref<1xf32> {
+ %A = memref.alloc() : memref<1xf32>
+ %cf0 = arith.constant 0.0 : f32
+ %cf5 = arith.constant 5.0 : f32
+
+ affine.store %cf0, %A[0] : memref<1xf32>
+ test.affine_scope {
+ affine.store %cf5, %A[0] : memref<1xf32>
+ "test.terminate"() : () -> ()
+ }
+ %v = affine.load %A[0] : memref<1xf32>
+ // CHECK: affine.store
+ // CHECK-NEXT: test.affine_scope
+ // CHECK: affine.store
+ // CHECK: affine.load
+ return %A : memref<1xf32>
+}
More information about the Mlir-commits
mailing list