Skip to content

Conversation

@RKSimon
Copy link
Collaborator

@RKSimon RKSimon commented Nov 15, 2024

Add static variants that can used with the Predicate enum directly.

…rappers

Add static variants that can used with the Predicate enum directly.
@RKSimon RKSimon requested review from dtcxzyw and nikic November 15, 2024 15:24
@github-actions
Copy link

github-actions bot commented Nov 15, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

LG

@RKSimon RKSimon merged commit 92cc805 into llvm:main Nov 15, 2024
4 of 7 checks passed
@RKSimon RKSimon deleted the ir-cmp-static-commutative branch November 15, 2024 17:13
@llvmbot
Copy link
Member

llvmbot commented Nov 16, 2024

@llvm/pr-subscribers-llvm-ir

Author: Simon Pilgrim (RKSimon)

Changes

Add static variants that can used with the Predicate enum directly.


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

1 Files Affected:

  • (modified) llvm/include/llvm/IR/Instructions.h (+14-9)
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index bc29a4801e4ff4..8eea659a00caf3 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -1248,9 +1248,13 @@ class ICmpInst: public CmpInst {
     return isEquality(getPredicate());
   }
 
+  /// @returns true if the predicate is commutative
+  /// Determine if this relation is commutative.
+  static bool isCommutative(Predicate P) { return isEquality(P); }
+
   /// @returns true if the predicate of this ICmpInst is commutative
   /// Determine if this relation is commutative.
-  bool isCommutative() const { return isEquality(); }
+  bool isCommutative() const { return isCommutative(getPredicate()); }
 
   /// Return true if the predicate is relational (not EQ or NE).
   ///
@@ -1369,7 +1373,7 @@ class FCmpInst: public CmpInst {
     AssertOK();
   }
 
-  /// @returns true if the predicate of this instruction is EQ or NE.
+  /// @returns true if the predicate is EQ or NE.
   /// Determine if this is an equality predicate.
   static bool isEquality(Predicate Pred) {
     return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
@@ -1380,16 +1384,17 @@ class FCmpInst: public CmpInst {
   /// Determine if this is an equality predicate.
   bool isEquality() const { return isEquality(getPredicate()); }
 
-  /// @returns true if the predicate of this instruction is commutative.
+  /// @returns true if the predicate is commutative.
   /// Determine if this is a commutative predicate.
-  bool isCommutative() const {
-    return isEquality() ||
-           getPredicate() == FCMP_FALSE ||
-           getPredicate() == FCMP_TRUE ||
-           getPredicate() == FCMP_ORD ||
-           getPredicate() == FCMP_UNO;
+  static bool isCommutative(Predicate Pred) {
+    return isEquality(Pred) || Pred == FCMP_FALSE || Pred == FCMP_TRUE ||
+           Pred == FCMP_ORD || Pred == FCMP_UNO;
   }
 
+  /// @returns true if the predicate of this instruction is commutative.
+  /// Determine if this is a commutative predicate.
+  bool isCommutative() const { return isCommutative(getPredicate()); }
+
   /// @returns true if the predicate is relational (not EQ or NE).
   /// Determine if this a relational predicate.
   bool isRelational() const { return !isEquality(); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants