diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index dd73213878f..cd024d09ea9 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -141,10 +141,10 @@ public: bool isCommutative() const { return isCommutative(getOpcode()); } static bool isCommutative(unsigned op); - /// isRelational - Return true if the instruction is a Set* instruction: + /// isComparison - Return true if the instruction is a Set* instruction: /// - bool isRelational() const { return isRelational(getOpcode()); } - static bool isRelational(unsigned op); + bool isComparison() const { return isComparison(getOpcode()); } + static bool isComparison(unsigned op); /// isTrappingInstruction - Return true if the instruction may trap. diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index a3d70f8f146..ed407acfb76 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -454,7 +454,18 @@ public: /// static BinaryOps getSwappedCondition(BinaryOps Opcode); - + /// isEquality - Return true if this comparison is an ==/!= comparison. + /// + bool isEquality() const { + return getOpcode() == SetEQ || getOpcode() == SetNE; + } + + /// isRelational - Return true if this comparison is a /<=/>= comparison. + /// + bool isRelational() const { + return !isEquality(); + } + // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const SetCondInst *) { return true; } static inline bool classof(const Instruction *I) { diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 2263d5ed83d..32945c290f2 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -1212,7 +1212,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, // If we successfully folded the expression, return it now. if (C) return C; - if (SetCondInst::isRelational(Opcode)) { + if (SetCondInst::isComparison(Opcode)) { if (isa(V1) || isa(V2)) return UndefValue::get(Type::BoolTy); switch (evaluateRelation(const_cast(V1), diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 8a1ae1eeca2..621e2ca94bf 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1419,7 +1419,7 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode, assert(C1->getType() == C2->getType() && "Operand types in binary constant expression should match"); - if (ReqTy == C1->getType() || (Instruction::isRelational(Opcode) && + if (ReqTy == C1->getType() || (Instruction::isComparison(Opcode) && ReqTy == Type::BoolTy)) if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2)) return FC; // Fold a few common cases... @@ -1462,7 +1462,7 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { } #endif - if (Instruction::isRelational(Opcode)) + if (Instruction::isComparison(Opcode)) return getTy(Type::BoolTy, Opcode, C1, C2); else return getTy(C1->getType(), Opcode, C1, C2); diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index ab4aaac7450..b2951461d7c 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -200,9 +200,9 @@ bool Instruction::isCommutative(unsigned op) { } } -/// isRelational - Return true if the instruction is a Set* instruction: +/// isComparison - Return true if the instruction is a Set* instruction: /// -bool Instruction::isRelational(unsigned op) { +bool Instruction::isComparison(unsigned op) { switch (op) { case SetEQ: case SetNE: