Skip to content

Commit f46e64f

Browse files
committed
PatternMatch, CmpPredicate: address review
1 parent 2cd636a commit f46e64f

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

llvm/include/llvm/IR/CmpPredicate.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ class CmpPredicate {
6262
bool operator==(CmpPredicate) const = delete;
6363
bool operator!=(CmpPredicate) const = delete;
6464

65-
/// TypeSwitch over the CmpInst and either do ICmpInst::getCmpPredicate() or
66-
/// FCmpInst::getPredicate().
65+
/// Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as
66+
/// appropriate.
6767
static CmpPredicate get(const CmpInst *Cmp);
6868

69-
/// Get the swapped predicate of a CmpPredicate, using
70-
/// CmpInst::isIntPredicate().
69+
/// Get the swapped predicate of a CmpPredicate.
7170
static CmpPredicate getSwapped(CmpPredicate P);
7271

7372
/// Get the swapped predicate of a CmpInst.

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ struct icmp_pred_with_threshold {
695695
/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
696696
/// to Threshold. For vectors, this includes constants with undefined elements.
697697
inline cst_pred_ty<icmp_pred_with_threshold>
698-
m_SpecificInt_ICMP(CmpPredicate Predicate, const APInt &Threshold) {
698+
m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold) {
699699
cst_pred_ty<icmp_pred_with_threshold> P;
700700
P.Pred = Predicate;
701701
P.Thr = &Threshold;

llvm/lib/IR/Instructions.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/ADT/SmallBitVector.h"
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/ADT/Twine.h"
19-
#include "llvm/ADT/TypeSwitch.h"
2019
#include "llvm/IR/Attributes.h"
2120
#include "llvm/IR/BasicBlock.h"
2221
#include "llvm/IR/Constant.h"
@@ -3934,15 +3933,13 @@ std::optional<CmpPredicate> CmpPredicate::getMatching(CmpPredicate A,
39343933
}
39353934

39363935
CmpPredicate CmpPredicate::get(const CmpInst *Cmp) {
3937-
return TypeSwitch<const CmpInst *, CmpPredicate>(Cmp)
3938-
.Case<ICmpInst>([](auto *ICI) { return ICI->getCmpPredicate(); })
3939-
.Case<FCmpInst>([](auto *FCI) { return FCI->getPredicate(); });
3936+
if (auto *ICI = dyn_cast<ICmpInst>(Cmp))
3937+
return ICI->getCmpPredicate();
3938+
return Cmp->getPredicate();
39403939
}
39413940

39423941
CmpPredicate CmpPredicate::getSwapped(CmpPredicate P) {
3943-
return CmpInst::isIntPredicate(P)
3944-
? ICmpInst::getSwappedCmpPredicate(P)
3945-
: CmpPredicate{CmpInst::getSwappedPredicate(P)};
3942+
return {CmpInst::getSwappedPredicate(P), P.hasSameSign()};
39463943
}
39473944

39483945
CmpPredicate CmpPredicate::getSwapped(const CmpInst *Cmp) {

0 commit comments

Comments
 (0)