Skip to content

Commit 7fe3741

Browse files
committed
CmpInst: de-duplicate code; address review
1 parent e57f9eb commit 7fe3741

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,9 +913,8 @@ class CmpInst : public Instruction {
913913
bool isEquality() const { return isEquality(getPredicate()); }
914914

915915
/// Determine if one operand of this compare can always be replaced by the
916-
/// other operand, ignoring provenance considerations. If \p Invert is false,
917-
/// check for equivalence with an equals predicate; otherwise, check for
918-
/// equivalence with a not-equals predicate.
916+
/// other operand, ignoring provenance considerations. If \p Invert, check for
917+
/// equivalence with the inverse predicate.
919918
bool isEquivalence(bool Invert = false) const;
920919

921920
/// Return true if the predicate is relational (not EQ or NE).

llvm/lib/IR/Instructions.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,23 +3488,15 @@ static bool hasNonZeroFPOperands(const CmpInst *Cmp) {
34883488
// -0.0, when comparing NaN with another value, or when flushing
34893489
// denormals-to-zero.
34903490
bool CmpInst::isEquivalence(bool Invert) const {
3491-
switch (getPredicate()) {
3491+
switch (Invert ? getInversePredicate() : getPredicate()) {
34923492
case CmpInst::Predicate::ICMP_EQ:
3493-
return !Invert;
3494-
case CmpInst::Predicate::ICMP_NE:
3495-
return Invert;
3493+
return true;
34963494
case CmpInst::Predicate::FCMP_UEQ:
34973495
if (!hasNoNaNs())
34983496
return false;
34993497
[[fallthrough]];
35003498
case CmpInst::Predicate::FCMP_OEQ:
3501-
return !Invert && hasNonZeroFPOperands(this);
3502-
case CmpInst::Predicate::FCMP_ONE:
3503-
if (!hasNoNaNs())
3504-
return false;
3505-
[[fallthrough]];
3506-
case CmpInst::Predicate::FCMP_UNE:
3507-
return Invert && hasNonZeroFPOperands(this);
3499+
return hasNonZeroFPOperands(this);
35083500
default:
35093501
return false;
35103502
}

0 commit comments

Comments
 (0)