Skip to content

Commit cf32c5b

Browse files
committed
IR: de-duplicate two CmpInst routines (NFC)
De-duplicate the functions getSignedPredicate and getUnsignedPredicate, nearly identical versions of which were present in CmpInst and ICmpInst, creating less confusion.
1 parent 37feced commit cf32c5b

File tree

3 files changed

+47
-86
lines changed

3 files changed

+47
-86
lines changed

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -935,28 +935,29 @@ class CmpInst : public Instruction {
935935
return isUnsigned(getPredicate());
936936
}
937937

938-
/// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert
939-
/// @returns the signed version of the unsigned predicate pred.
940-
/// return the signed version of a predicate
938+
/// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
939+
/// @returns the predicate that would be the result if the operand were
940+
/// regarded as signed. Asserts on FP predicates.
941+
/// Static variant.
941942
static Predicate getSignedPredicate(Predicate pred);
942943

943-
/// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert
944-
/// @returns the signed version of the predicate for this instruction (which
945-
/// has to be an unsigned predicate).
946-
/// return the signed version of a predicate
947-
Predicate getSignedPredicate() {
944+
/// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
945+
/// @returns the predicate that would be the result if the operand were
946+
/// regarded as signed. Asserts on FP predicates.
947+
Predicate getSignedPredicate() const {
948948
return getSignedPredicate(getPredicate());
949949
}
950950

951-
/// For example, SLT->ULT, SLE->ULE, SGT->UGT, SGE->UGE, ULT->Failed assert
952-
/// @returns the unsigned version of the signed predicate pred.
951+
/// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
952+
/// @returns the predicate that would be the result if the operand were
953+
/// regarded as unsigned. Asserts on FP predicates.
954+
/// Static variant.
953955
static Predicate getUnsignedPredicate(Predicate pred);
954956

955-
/// For example, SLT->ULT, SLE->ULE, SGT->UGT, SGE->UGE, ULT->Failed assert
956-
/// @returns the unsigned version of the predicate for this instruction (which
957-
/// has to be an signed predicate).
958-
/// return the unsigned version of a predicate
959-
Predicate getUnsignedPredicate() {
957+
/// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
958+
/// @returns the predicate that would be the result if the operand were
959+
/// regarded as unsigned. Asserts on FP predicates.
960+
Predicate getUnsignedPredicate() const {
960961
return getUnsignedPredicate(getPredicate());
961962
}
962963

@@ -968,7 +969,7 @@ class CmpInst : public Instruction {
968969
/// For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->Failed assert
969970
/// @returns the unsigned version of the signed predicate pred or
970971
/// the signed version of the signed predicate pred.
971-
Predicate getFlippedSignednessPredicate() {
972+
Predicate getFlippedSignednessPredicate() const {
972973
return getFlippedSignednessPredicate(getPredicate());
973974
}
974975

llvm/include/llvm/IR/Instructions.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,30 +1203,6 @@ class ICmpInst: public CmpInst {
12031203
#endif
12041204
}
12051205

1206-
/// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1207-
/// @returns the predicate that would be the result if the operand were
1208-
/// regarded as signed.
1209-
/// Return the signed version of the predicate
1210-
Predicate getSignedPredicate() const {
1211-
return getSignedPredicate(getPredicate());
1212-
}
1213-
1214-
/// This is a static version that you can use without an instruction.
1215-
/// Return the signed version of the predicate.
1216-
static Predicate getSignedPredicate(Predicate pred);
1217-
1218-
/// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1219-
/// @returns the predicate that would be the result if the operand were
1220-
/// regarded as unsigned.
1221-
/// Return the unsigned version of the predicate
1222-
Predicate getUnsignedPredicate() const {
1223-
return getUnsignedPredicate(getPredicate());
1224-
}
1225-
1226-
/// This is a static version that you can use without an instruction.
1227-
/// Return the unsigned version of the predicate.
1228-
static Predicate getUnsignedPredicate(Predicate pred);
1229-
12301206
void setSameSign(bool B = true) {
12311207
SubclassOptionalData = (SubclassOptionalData & ~SameSign) | (B * SameSign);
12321208
}

llvm/lib/IR/Instructions.cpp

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,32 +3573,6 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, CmpInst::Predicate Pred) {
35733573
return OS;
35743574
}
35753575

3576-
ICmpInst::Predicate ICmpInst::getSignedPredicate(Predicate pred) {
3577-
switch (pred) {
3578-
default: llvm_unreachable("Unknown icmp predicate!");
3579-
case ICMP_EQ: case ICMP_NE:
3580-
case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE:
3581-
return pred;
3582-
case ICMP_UGT: return ICMP_SGT;
3583-
case ICMP_ULT: return ICMP_SLT;
3584-
case ICMP_UGE: return ICMP_SGE;
3585-
case ICMP_ULE: return ICMP_SLE;
3586-
}
3587-
}
3588-
3589-
ICmpInst::Predicate ICmpInst::getUnsignedPredicate(Predicate pred) {
3590-
switch (pred) {
3591-
default: llvm_unreachable("Unknown icmp predicate!");
3592-
case ICMP_EQ: case ICMP_NE:
3593-
case ICMP_UGT: case ICMP_ULT: case ICMP_UGE: case ICMP_ULE:
3594-
return pred;
3595-
case ICMP_SGT: return ICMP_UGT;
3596-
case ICMP_SLT: return ICMP_ULT;
3597-
case ICMP_SGE: return ICMP_UGE;
3598-
case ICMP_SLE: return ICMP_ULE;
3599-
}
3600-
}
3601-
36023576
CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
36033577
switch (pred) {
36043578
default: llvm_unreachable("Unknown cmp predicate!");
@@ -3719,36 +3693,46 @@ CmpInst::Predicate CmpInst::getFlippedStrictnessPredicate(Predicate pred) {
37193693
}
37203694

37213695
CmpInst::Predicate CmpInst::getSignedPredicate(Predicate pred) {
3722-
assert(CmpInst::isUnsigned(pred) && "Call only with unsigned predicates!");
3723-
37243696
switch (pred) {
37253697
default:
37263698
llvm_unreachable("Unknown predicate!");
3727-
case CmpInst::ICMP_ULT:
3728-
return CmpInst::ICMP_SLT;
3729-
case CmpInst::ICMP_ULE:
3730-
return CmpInst::ICMP_SLE;
3731-
case CmpInst::ICMP_UGT:
3732-
return CmpInst::ICMP_SGT;
3733-
case CmpInst::ICMP_UGE:
3734-
return CmpInst::ICMP_SGE;
3699+
case ICMP_EQ:
3700+
case ICMP_NE:
3701+
case ICMP_SGT:
3702+
case ICMP_SLT:
3703+
case ICMP_SGE:
3704+
case ICMP_SLE:
3705+
return pred;
3706+
case ICMP_UGT:
3707+
return ICMP_SGT;
3708+
case ICMP_ULT:
3709+
return ICMP_SLT;
3710+
case ICMP_UGE:
3711+
return ICMP_SGE;
3712+
case ICMP_ULE:
3713+
return ICMP_SLE;
37353714
}
37363715
}
37373716

37383717
CmpInst::Predicate CmpInst::getUnsignedPredicate(Predicate pred) {
3739-
assert(CmpInst::isSigned(pred) && "Call only with signed predicates!");
3740-
37413718
switch (pred) {
37423719
default:
37433720
llvm_unreachable("Unknown predicate!");
3744-
case CmpInst::ICMP_SLT:
3745-
return CmpInst::ICMP_ULT;
3746-
case CmpInst::ICMP_SLE:
3747-
return CmpInst::ICMP_ULE;
3748-
case CmpInst::ICMP_SGT:
3749-
return CmpInst::ICMP_UGT;
3750-
case CmpInst::ICMP_SGE:
3751-
return CmpInst::ICMP_UGE;
3721+
case ICMP_EQ:
3722+
case ICMP_NE:
3723+
case ICMP_UGT:
3724+
case ICMP_ULT:
3725+
case ICMP_UGE:
3726+
case ICMP_ULE:
3727+
return pred;
3728+
case ICMP_SGT:
3729+
return ICMP_UGT;
3730+
case ICMP_SLT:
3731+
return ICMP_ULT;
3732+
case ICMP_SGE:
3733+
return ICMP_UGE;
3734+
case ICMP_SLE:
3735+
return ICMP_ULE;
37523736
}
37533737
}
37543738

0 commit comments

Comments
 (0)