[Mlir-commits] [mlir] 978ca8c - Canonicalize affine set + operands while adding affine.if op domain
Uday Bondhugula
llvmlistbot at llvm.org
Wed Jan 11 22:13:54 PST 2023
Author: Uday Bondhugula
Date: 2023-01-12T11:39:14+05:30
New Revision: 978ca8cae26e2a50d18cac7839c304c625a917e6
URL: https://github.com/llvm/llvm-project/commit/978ca8cae26e2a50d18cac7839c304c625a917e6
DIFF: https://github.com/llvm/llvm-project/commit/978ca8cae26e2a50d18cac7839c304c625a917e6.diff
LOG: Canonicalize affine set + operands while adding affine.if op domain
Canonicalize affine set + operands in addAffineIfOpDomain. This is to
ensure a unique set of operands for FlatAffineValueConstraints and in
general to provide a simplified set of constraints. For the latter
scenario, this just leads to efficiency improvements as opposed to
functionality. While on this, remove outdated/stale stuff from
AffineStructures.h.
Fixes: https://github.com/llvm/llvm-project/issues/59461
Differential Revision: https://reviews.llvm.org/D141250
Added:
Modified:
mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h
mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp
mlir/test/Transforms/memref-dependence-check.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h b/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h
index cd23e1234833d..e519cbc766cca 100644
--- a/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h
+++ b/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h
@@ -88,10 +88,7 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron {
explicit FlatAffineValueConstraints(ArrayRef<const AffineValueMap *> avmRef);
/// Creates an affine constraint system from an IntegerSet.
- explicit FlatAffineValueConstraints(IntegerSet set);
-
- FlatAffineValueConstraints(ArrayRef<const AffineValueMap *> avmRef,
- IntegerSet set);
+ explicit FlatAffineValueConstraints(IntegerSet set, ValueRange operands = {});
// Construct a hyperrectangular constraint set from ValueRanges that represent
// induction variables, lower and upper bounds. `ivs`, `lbs` and `ubs` are
@@ -139,7 +136,6 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron {
/// 'affine.for' operation are added as trailing variables (either
/// dimensional or symbolic depending on whether the operand is a valid
/// symbol).
- // TODO: add support for non-unit strides.
LogicalResult addAffineForOpDomain(AffineForOp forOp);
/// Add constraints (lower and upper bounds) for the specified
@@ -279,7 +275,7 @@ class FlatAffineValueConstraints : public presburger::IntegerPolyhedron {
/// Returns true if an variable with the specified Value exists, false
/// otherwise.
- bool containsVar(Value mayBeVar) const;
+ bool containsVar(Value val) const;
/// Swap the posA^th variable with the posB^th variable.
void swapVar(unsigned posA, unsigned posB) override;
diff --git a/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp b/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp
index 453f20c4b4106..8ed31c5c85b04 100644
--- a/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp
@@ -150,15 +150,20 @@ FlatAffineValueConstraints::clone() const {
}
// Construct from an IntegerSet.
-FlatAffineValueConstraints::FlatAffineValueConstraints(IntegerSet set)
+FlatAffineValueConstraints::FlatAffineValueConstraints(IntegerSet set,
+ ValueRange operands)
: IntegerPolyhedron(set.getNumInequalities(), set.getNumEqualities(),
set.getNumDims() + set.getNumSymbols() + 1,
PresburgerSpace::getSetSpace(set.getNumDims(),
set.getNumSymbols(),
/*numLocals=*/0)) {
-
- // Resize values.
- values.resize(getNumDimAndSymbolVars(), std::nullopt);
+ // Populate values.
+ if (operands.empty()) {
+ values.resize(getNumDimAndSymbolVars(), std::nullopt);
+ } else {
+ assert(set.getNumInputs() == operands.size() && "operand count mismatch");
+ values.assign(operands.begin(), operands.end());
+ }
// Flatten expressions and add them to the constraint system.
std::vector<SmallVector<int64_t, 8>> flatExprs;
@@ -718,12 +723,14 @@ FlatAffineValueConstraints::addDomainFromSliceMaps(ArrayRef<AffineMap> lbMaps,
}
void FlatAffineValueConstraints::addAffineIfOpDomain(AffineIfOp ifOp) {
- // Create the base constraints from the integer set attached to ifOp.
- FlatAffineValueConstraints cst(ifOp.getIntegerSet());
+ IntegerSet set = ifOp.getIntegerSet();
+ // Canonicalize set and operands to ensure unique values for
+ // FlatAffineValueConstraints below and for early simplification.
+ SmallVector<Value> operands(ifOp.getOperands());
+ canonicalizeSetAndOperands(&set, &operands);
- // Bind vars in the constraints to ifOp operands.
- SmallVector<Value, 4> operands = ifOp.getOperands();
- cst.setValues(0, cst.getNumDimAndSymbolVars(), operands);
+ // Create the base constraints from the integer set attached to ifOp.
+ FlatAffineValueConstraints cst(set, operands);
// Merge the constraints from ifOp to the current domain. We need first merge
// and align the IDs from both constraints, and then append the constraints
diff --git a/mlir/test/Transforms/memref-dependence-check.mlir b/mlir/test/Transforms/memref-dependence-check.mlir
index 2e28a4cc7e312..d9bf2ffeb15ab 100644
--- a/mlir/test/Transforms/memref-dependence-check.mlir
+++ b/mlir/test/Transforms/memref-dependence-check.mlir
@@ -1080,3 +1080,21 @@ func.func @parallel_dependence_check_failure() {
}
return
}
+
+// -----
+
+func.func @affine_if_no_dependence() {
+ %c1 = arith.constant 1 : index
+ %alloc = memref.alloc() : memref<15xi1>
+ %true = arith.constant true
+ affine.store %true, %alloc[%c1] : memref<15xi1>
+ // expected-remark at above {{dependence from 0 to 0 at depth 1 = false}}
+ // expected-remark at above {{dependence from 0 to 1 at depth 1 = false}}
+ // This set is empty.
+ affine.if affine_set<(d0, d1, d2, d3) : ((d0 + 1) mod 8 >= 0, d0 * -8 >= 0)>(%c1, %c1, %c1, %c1){
+ %265 = affine.load %alloc[%c1] : memref<15xi1>
+ // expected-remark at above {{dependence from 1 to 0 at depth 1 = false}}
+ // expected-remark at above {{dependence from 1 to 1 at depth 1 = false}}
+ }
+ return
+}
More information about the Mlir-commits
mailing list