Skip to content

[MLIR][Affine] Add affine value map difference operator #127163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

bondhugula
Copy link
Contributor

Add affine value map difference operator. NFC otherwise.

Add affine value map difference operator. NFC otherwise.
@llvmbot
Copy link
Member

llvmbot commented Feb 14, 2025

@llvm/pr-subscribers-mlir-affine

@llvm/pr-subscribers-mlir

Author: Uday Bondhugula (bondhugula)

Changes

Add affine value map difference operator. NFC otherwise.


Full diff: https://github.com/llvm/llvm-project/pull/127163.diff

3 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Affine/IR/AffineValueMap.h (+7)
  • (modified) mlir/lib/Dialect/Affine/Analysis/Utils.cpp (+1-3)
  • (modified) mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp (+8)
diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineValueMap.h b/mlir/include/mlir/Dialect/Affine/IR/AffineValueMap.h
index 7ad0e4a1e5ea0..ac480d6997ef4 100644
--- a/mlir/include/mlir/Dialect/Affine/IR/AffineValueMap.h
+++ b/mlir/include/mlir/Dialect/Affine/IR/AffineValueMap.h
@@ -84,6 +84,13 @@ class AffineValueMap {
   /// and/or operands have been modified.
   LogicalResult canonicalize();
 
+  /// Checks if the application of this map to its operands is semantically
+  /// equal to `other`'s.
+  bool operator==(const AffineValueMap &other) const;
+  bool operator!=(const AffineValueMap &other) const {
+    return !(*this == other);
+  }
+
 private:
   // A mutable affine map.
   MutableAffineMap map;
diff --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
index b829633252fdd..93d8bffdcd8a4 100644
--- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp
@@ -2001,9 +2001,7 @@ bool MemRefAccess::operator==(const MemRefAccess &rhs) const {
   AffineValueMap diff, thisMap, rhsMap;
   getAccessMap(&thisMap);
   rhs.getAccessMap(&rhsMap);
-  AffineValueMap::difference(thisMap, rhsMap, &diff);
-  return llvm::all_of(diff.getAffineMap().getResults(),
-                      [](AffineExpr e) { return e == 0; });
+  return thisMap == rhsMap;
 }
 
 void mlir::affine::getAffineIVs(Operation &op, SmallVectorImpl<Value> &ivs) {
diff --git a/mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp b/mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp
index 6a52849186872..6d2d3212c696b 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineValueMap.cpp
@@ -109,4 +109,12 @@ ArrayRef<Value> AffineValueMap::getOperands() const {
 
 AffineMap AffineValueMap::getAffineMap() const { return map.getAffineMap(); }
 
+bool AffineValueMap::operator==(const AffineValueMap &other) const {
+  AffineValueMap diff;
+  AffineValueMap::difference(*this, other, &diff);
+  return llvm::all_of(diff.getAffineMap().getResults(), [](AffineExpr e) {
+    return e == getAffineConstantExpr(0, e.getContext());
+  });
+}
+
 AffineValueMap::~AffineValueMap() = default;

Copy link
Contributor

@arnab-polymage arnab-polymage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@patel-vimal patel-vimal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bondhugula bondhugula merged commit c1b7037 into llvm:main Feb 14, 2025
11 checks passed
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
Add affine value map difference operator. NFC otherwise.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
Add affine value map difference operator. NFC otherwise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants