Skip to content

Commit 92cc805

Browse files
authored
[IR] Add ICmpInst::isCommutative and FCmpInst::isCommutative static wrappers (#116398)
Add static variants that can used with the Predicate enum directly.
1 parent e67e09a commit 92cc805

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

llvm/include/llvm/IR/Instructions.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,9 +1248,13 @@ class ICmpInst: public CmpInst {
12481248
return isEquality(getPredicate());
12491249
}
12501250

1251+
/// @returns true if the predicate is commutative
1252+
/// Determine if this relation is commutative.
1253+
static bool isCommutative(Predicate P) { return isEquality(P); }
1254+
12511255
/// @returns true if the predicate of this ICmpInst is commutative
12521256
/// Determine if this relation is commutative.
1253-
bool isCommutative() const { return isEquality(); }
1257+
bool isCommutative() const { return isCommutative(getPredicate()); }
12541258

12551259
/// Return true if the predicate is relational (not EQ or NE).
12561260
///
@@ -1369,7 +1373,7 @@ class FCmpInst: public CmpInst {
13691373
AssertOK();
13701374
}
13711375

1372-
/// @returns true if the predicate of this instruction is EQ or NE.
1376+
/// @returns true if the predicate is EQ or NE.
13731377
/// Determine if this is an equality predicate.
13741378
static bool isEquality(Predicate Pred) {
13751379
return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
@@ -1380,16 +1384,17 @@ class FCmpInst: public CmpInst {
13801384
/// Determine if this is an equality predicate.
13811385
bool isEquality() const { return isEquality(getPredicate()); }
13821386

1383-
/// @returns true if the predicate of this instruction is commutative.
1387+
/// @returns true if the predicate is commutative.
13841388
/// Determine if this is a commutative predicate.
1385-
bool isCommutative() const {
1386-
return isEquality() ||
1387-
getPredicate() == FCMP_FALSE ||
1388-
getPredicate() == FCMP_TRUE ||
1389-
getPredicate() == FCMP_ORD ||
1390-
getPredicate() == FCMP_UNO;
1389+
static bool isCommutative(Predicate Pred) {
1390+
return isEquality(Pred) || Pred == FCMP_FALSE || Pred == FCMP_TRUE ||
1391+
Pred == FCMP_ORD || Pred == FCMP_UNO;
13911392
}
13921393

1394+
/// @returns true if the predicate of this instruction is commutative.
1395+
/// Determine if this is a commutative predicate.
1396+
bool isCommutative() const { return isCommutative(getPredicate()); }
1397+
13931398
/// @returns true if the predicate is relational (not EQ or NE).
13941399
/// Determine if this a relational predicate.
13951400
bool isRelational() const { return !isEquality(); }

0 commit comments

Comments
 (0)