Index: include/llvm/Analysis/ConstantFolding.h =================================================================== --- include/llvm/Analysis/ConstantFolding.h +++ include/llvm/Analysis/ConstantFolding.h @@ -20,6 +20,8 @@ #ifndef LLVM_ANALYSIS_CONSTANTFOLDING_H #define LLVM_ANALYSIS_CONSTANTFOLDING_H +#include "llvm/Support/Predicate.h" + namespace llvm { class APInt; template class ArrayRef; @@ -68,8 +70,8 @@ /// returns a constant expression of the specified operands. /// Constant * -ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, - Constant *RHS, const DataLayout &DL, +ConstantFoldCompareInstOperands(Predicate Pred, Constant *LHS, Constant *RHS, + const DataLayout &DL, const TargetLibraryInfo *TLI = nullptr); /// \brief Attempt to constant fold a binary operation with the specified Index: include/llvm/Analysis/DependenceAnalysis.h =================================================================== --- include/llvm/Analysis/DependenceAnalysis.h +++ include/llvm/Analysis/DependenceAnalysis.h @@ -563,9 +563,7 @@ /// Basically a wrapper for SCEV::isKnownPredicate, /// but tries harder, especially in the presence of sign and zero /// extensions and symbolics. - bool isKnownPredicate(ICmpInst::Predicate Pred, - const SCEV *X, - const SCEV *Y) const; + bool isKnownPredicate(Predicate Pred, const SCEV *X, const SCEV *Y) const; /// collectUpperBound - All subscripts are the same type (on my machine, /// an i64). The loop bound may be a smaller type. collectUpperBound Index: include/llvm/Analysis/InstructionSimplify.h =================================================================== --- include/llvm/Analysis/InstructionSimplify.h +++ include/llvm/Analysis/InstructionSimplify.h @@ -33,6 +33,7 @@ #define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H #include "llvm/IR/User.h" +#include "llvm/Support/Predicate.h" namespace llvm { template @@ -183,7 +184,7 @@ const Instruction *CxtI = nullptr); /// Given operands for an ICmpInst, fold the result or return null. - Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, + Value *SimplifyICmpInst(Predicate Pred, Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI = nullptr, const DominatorTree *DT = nullptr, @@ -191,7 +192,7 @@ const Instruction *CxtI = nullptr); /// Given operands for an FCmpInst, fold the result or return null. - Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, + Value *SimplifyFCmpInst(Predicate Pred, Value *LHS, Value *RHS, FastMathFlags FMF, const DataLayout &DL, const TargetLibraryInfo *TLI = nullptr, const DominatorTree *DT = nullptr, @@ -250,7 +251,7 @@ /// Given operands for a CmpInst, fold the result or return null. - Value *SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, + Value *SimplifyCmpInst(Predicate Pred, Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI = nullptr, const DominatorTree *DT = nullptr, Index: include/llvm/Analysis/LazyValueInfo.h =================================================================== --- include/llvm/Analysis/LazyValueInfo.h +++ include/llvm/Analysis/LazyValueInfo.h @@ -17,6 +17,7 @@ #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" +#include "llvm/Support/Predicate.h" namespace llvm { class AssumptionCache; @@ -67,14 +68,14 @@ /// Determine whether the specified value comparison with a constant is known /// to be true or false on the specified CFG edge. /// Pred is a CmpInst predicate. - Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C, + Tristate getPredicateOnEdge(Predicate Pred, Value *V, Constant *C, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI = nullptr); /// Determine whether the specified value comparison with a constant is known /// to be true or false at the specified instruction /// (from an assume intrinsic). Pred is a CmpInst predicate. - Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C, + Tristate getPredicateAt(Predicate Pred, Value *V, Constant *C, Instruction *CxtI); /// Determine whether the specified value is known to be a Index: include/llvm/Analysis/ScalarEvolution.h =================================================================== --- include/llvm/Analysis/ScalarEvolution.h +++ include/llvm/Analysis/ScalarEvolution.h @@ -934,10 +934,8 @@ /// Given an exit condition of 'icmp op load X, cst', try to see if we can /// compute the backedge-taken count. - ExitLimit computeLoadConstantCompareExitLimit(LoadInst *LI, - Constant *RHS, - const Loop *L, - ICmpInst::Predicate p); + ExitLimit computeLoadConstantCompareExitLimit(LoadInst *LI, Constant *RHS, + const Loop *L, Predicate p); /// Compute the exit limit of a loop that is controlled by a /// "(IV >> 1) != 0" type comparison. We cannot compute the exact trip @@ -947,8 +945,7 @@ /// Return an ExitLimit for a loop whose backedge is guarded by `LHS Pred /// RHS`. ExitLimit computeShiftCompareExitLimit(Value *LHS, Value *RHS, - const Loop *L, - ICmpInst::Predicate Pred); + const Loop *L, Predicate Pred); /// If the loop is known to execute a constant number of times (the /// condition evolves only from constants), try to evaluate a few iterations @@ -999,46 +996,41 @@ /// Test whether the condition described by Pred, LHS, and RHS is true /// whenever the given FoundCondValue value evaluates to true. - bool isImpliedCond(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS, - Value *FoundCondValue, - bool Inverse); + bool isImpliedCond(Predicate Pred, const SCEV *LHS, const SCEV *RHS, + Value *FoundCondValue, bool Inverse); /// Test whether the condition described by Pred, LHS, and RHS is true /// whenever the condition described by FoundPred, FoundLHS, FoundRHS is /// true. - bool isImpliedCond(ICmpInst::Predicate Pred, const SCEV *LHS, - const SCEV *RHS, ICmpInst::Predicate FoundPred, - const SCEV *FoundLHS, const SCEV *FoundRHS); + bool isImpliedCond(Predicate Pred, const SCEV *LHS, const SCEV *RHS, + Predicate FoundPred, const SCEV *FoundLHS, + const SCEV *FoundRHS); /// Test whether the condition described by Pred, LHS, and RHS is true /// whenever the condition described by Pred, FoundLHS, and FoundRHS is /// true. - bool isImpliedCondOperands(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS, + bool isImpliedCondOperands(Predicate Pred, const SCEV *LHS, const SCEV *RHS, const SCEV *FoundLHS, const SCEV *FoundRHS); /// Test whether the condition described by Pred, LHS, and RHS is true /// whenever the condition described by Pred, FoundLHS, and FoundRHS is /// true. - bool isImpliedCondOperandsHelper(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS, - const SCEV *FoundLHS, + bool isImpliedCondOperandsHelper(Predicate Pred, const SCEV *LHS, + const SCEV *RHS, const SCEV *FoundLHS, const SCEV *FoundRHS); /// Test whether the condition described by Pred, LHS, and RHS is true /// whenever the condition described by Pred, FoundLHS, and FoundRHS is /// true. Utility function used by isImpliedCondOperands. Tries to get /// cases like "X `sgt` 0 => X - 1 `sgt` -1". - bool isImpliedCondOperandsViaRanges(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS, - const SCEV *FoundLHS, + bool isImpliedCondOperandsViaRanges(Predicate Pred, const SCEV *LHS, + const SCEV *RHS, const SCEV *FoundLHS, const SCEV *FoundRHS); /// Return true if the condition denoted by \p LHS \p Pred \p RHS is implied /// by a call to \c @llvm.experimental.guard in \p BB. - bool isImpliedViaGuard(BasicBlock *BB, ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS); + bool isImpliedViaGuard(BasicBlock *BB, Predicate Pred, const SCEV *LHS, + const SCEV *RHS); /// Test whether the condition described by Pred, LHS, and RHS is true /// whenever the condition described by Pred, FoundLHS, and FoundRHS is @@ -1046,8 +1038,8 @@ /// /// This routine tries to rule out certain kinds of integer overflow, and /// then tries to reason about arithmetic properties of the predicates. - bool isImpliedCondOperandsViaNoOverflow(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS, + bool isImpliedCondOperandsViaNoOverflow(Predicate Pred, const SCEV *LHS, + const SCEV *RHS, const SCEV *FoundLHS, const SCEV *FoundRHS); @@ -1060,20 +1052,20 @@ /// Test if the given expression is known to satisfy the condition described /// by Pred and the known constant ranges of LHS and RHS. /// - bool isKnownPredicateViaConstantRanges(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS); + bool isKnownPredicateViaConstantRanges(Predicate Pred, const SCEV *LHS, + const SCEV *RHS); /// Try to prove the condition described by "LHS Pred RHS" by ruling out /// integer overflow. /// /// For instance, this will return true for "A s< (A + C)" if C is /// positive. - bool isKnownPredicateViaNoOverflow(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS); + bool isKnownPredicateViaNoOverflow(Predicate Pred, const SCEV *LHS, + const SCEV *RHS); /// Try to split Pred LHS RHS into logical conjunctions (and's) and try to /// prove them individually. - bool isKnownPredicateViaSplitting(ICmpInst::Predicate Pred, const SCEV *LHS, + bool isKnownPredicateViaSplitting(Predicate Pred, const SCEV *LHS, const SCEV *RHS); /// Try to match the Expr as "(L + R)". @@ -1112,8 +1104,8 @@ /// Try to prove NSW or NUW on \p AR relying on ConstantRange manipulation. SCEV::NoWrapFlags proveNoWrapViaConstantRanges(const SCEVAddRecExpr *AR); - bool isMonotonicPredicateImpl(const SCEVAddRecExpr *LHS, - ICmpInst::Predicate Pred, bool &Increasing); + bool isMonotonicPredicateImpl(const SCEVAddRecExpr *LHS, Predicate Pred, + bool &Increasing); /// Return true if, for all loop invariant X, the predicate "LHS `Pred` X" /// is monotonically increasing or decreasing. In the former case set @@ -1124,8 +1116,8 @@ /// around. A predicate is said to be monotonically decreasing if may go /// from being true to being false as the loop iterates, but never the other /// way around. - bool isMonotonicPredicate(const SCEVAddRecExpr *LHS, - ICmpInst::Predicate Pred, bool &Increasing); + bool isMonotonicPredicate(const SCEVAddRecExpr *LHS, Predicate Pred, + bool &Increasing); /// Return SCEV no-wrap flags that can be proven based on reasoning about /// how poison produced from no-wrap flags on this value (e.g. a nuw add) @@ -1342,12 +1334,12 @@ /// Test whether entry to the loop is protected by a conditional between LHS /// and RHS. This is used to help avoid max expressions in loop trip /// counts, and to eliminate casts. - bool isLoopEntryGuardedByCond(const Loop *L, ICmpInst::Predicate Pred, + bool isLoopEntryGuardedByCond(const Loop *L, Predicate Pred, const SCEV *LHS, const SCEV *RHS); /// Test whether the backedge of the loop is protected by a conditional /// between LHS and RHS. This is used to to eliminate casts. - bool isLoopBackedgeGuardedByCond(const Loop *L, ICmpInst::Predicate Pred, + bool isLoopBackedgeGuardedByCond(const Loop *L, Predicate Pred, const SCEV *LHS, const SCEV *RHS); /// Returns the maximum trip count of the loop if it is a single-exit @@ -1474,16 +1466,15 @@ /// Test if the given expression is known to satisfy the condition described /// by Pred, LHS, and RHS. /// - bool isKnownPredicate(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS); + bool isKnownPredicate(Predicate Pred, const SCEV *LHS, const SCEV *RHS); /// Return true if the result of the predicate LHS `Pred` RHS is loop /// invariant with respect to L. Set InvariantPred, InvariantLHS and /// InvariantLHS so that InvariantLHS `InvariantPred` InvariantRHS is the /// loop invariant form of LHS `Pred` RHS. - bool isLoopInvariantPredicate(ICmpInst::Predicate Pred, const SCEV *LHS, + bool isLoopInvariantPredicate(Predicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, - ICmpInst::Predicate &InvariantPred, + Predicate &InvariantPred, const SCEV *&InvariantLHS, const SCEV *&InvariantRHS); @@ -1492,10 +1483,8 @@ /// unequal, LHS and RHS are set to the same value and Pred is set to either /// ICMP_EQ or ICMP_NE. /// - bool SimplifyICmpOperands(ICmpInst::Predicate &Pred, - const SCEV *&LHS, - const SCEV *&RHS, - unsigned Depth = 0); + bool SimplifyICmpOperands(Predicate &Pred, const SCEV *&LHS, + const SCEV *&RHS, unsigned Depth = 0); /// Return the "disposition" of the given SCEV with respect to the given /// loop. Index: include/llvm/Analysis/TargetFolder.h =================================================================== --- include/llvm/Analysis/TargetFolder.h +++ include/llvm/Analysis/TargetFolder.h @@ -222,12 +222,10 @@ // Compare Instructions //===--------------------------------------------------------------------===// - Constant *CreateICmp(CmpInst::Predicate P, Constant *LHS, - Constant *RHS) const { + Constant *CreateICmp(Predicate P, Constant *LHS, Constant *RHS) const { return Fold(ConstantExpr::getCompare(P, LHS, RHS)); } - Constant *CreateFCmp(CmpInst::Predicate P, Constant *LHS, - Constant *RHS) const { + Constant *CreateFCmp(Predicate P, Constant *LHS, Constant *RHS) const { return Fold(ConstantExpr::getCompare(P, LHS, RHS)); } Index: include/llvm/CodeGen/Analysis.h =================================================================== --- include/llvm/CodeGen/Analysis.h +++ include/llvm/CodeGen/Analysis.h @@ -86,7 +86,7 @@ /// the given LLVM IR floating-point condition code. This includes /// consideration of global floating-point math flags. /// -ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred); +ISD::CondCode getFCmpCondCode(Predicate Pred); /// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats, /// return the equivalent code if we're allowed to assume that NaNs won't occur. @@ -95,7 +95,7 @@ /// getICmpCondCode - Return the ISD condition code corresponding to /// the given LLVM IR integer condition code. /// -ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred); +ISD::CondCode getICmpCondCode(Predicate Pred); /// Test if the given instruction is in a position to be optimized /// with a tail-call. This roughly means that it's in a block with Index: include/llvm/CodeGen/FastISel.h =================================================================== --- include/llvm/CodeGen/FastISel.h +++ include/llvm/CodeGen/FastISel.h @@ -504,7 +504,7 @@ /// \brief Create a machine mem operand from the given instruction. MachineMemOperand *createMachineMemOperandFor(const Instruction *I) const; - CmpInst::Predicate optimizeCmpPredicate(const CmpInst *CI) const; + Predicate optimizeCmpPredicate(const CmpInst *CI) const; bool lowerCallTo(const CallInst *CI, MCSymbol *Symbol, unsigned NumArgs); bool lowerCallTo(const CallInst *CI, const char *SymbolName, Index: include/llvm/IR/ConstantFolder.h =================================================================== --- include/llvm/IR/ConstantFolder.h +++ include/llvm/IR/ConstantFolder.h @@ -198,12 +198,10 @@ // Compare Instructions //===--------------------------------------------------------------------===// - Constant *CreateICmp(CmpInst::Predicate P, Constant *LHS, - Constant *RHS) const { + Constant *CreateICmp(Predicate P, Constant *LHS, Constant *RHS) const { return ConstantExpr::getCompare(P, LHS, RHS); } - Constant *CreateFCmp(CmpInst::Predicate P, Constant *LHS, - Constant *RHS) const { + Constant *CreateFCmp(Predicate P, Constant *LHS, Constant *RHS) const { return ConstantExpr::getCompare(P, LHS, RHS); } Index: include/llvm/IR/ConstantRange.h =================================================================== --- include/llvm/IR/ConstantRange.h +++ include/llvm/IR/ConstantRange.h @@ -68,7 +68,7 @@ /// proper superset of the above. /// /// Example: Pred = ult and Other = i8 [2, 5) returns Result = [0, 4) - static ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred, + static ConstantRange makeAllowedICmpRegion(Predicate Pred, const ConstantRange &Other); /// Produce the largest range such that all values in the returned range @@ -79,7 +79,7 @@ /// will be a proper subset of the above. /// /// Example: Pred = ult and Other = i8 [2, 5) returns [0, 2) - static ConstantRange makeSatisfyingICmpRegion(CmpInst::Predicate Pred, + static ConstantRange makeSatisfyingICmpRegion(Predicate Pred, const ConstantRange &Other); /// Produce the exact range such that all values in the returned range satisfy @@ -89,8 +89,7 @@ /// { x : icmp op x y is true}'. /// /// Example: Pred = ult and Other = i8 3 returns [0, 3) - static ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred, - const APInt &Other); + static ConstantRange makeExactICmpRegion(Predicate Pred, const APInt &Other); /// Return the largest range containing all X such that "X BinOpC Y" is /// guaranteed not to wrap (overflow) for all Y in Other. @@ -117,7 +116,7 @@ /// Set up \p Pred and \p RHS such that /// ConstantRange::makeExactICmpRegion(Pred, RHS) == *this. Return true if /// successful. - bool getEquivalentICmp(CmpInst::Predicate &Pred, APInt &RHS) const; + bool getEquivalentICmp(Predicate &Pred, APInt &RHS) const; /// Return the lower value for this range. /// Index: include/llvm/IR/Constants.h =================================================================== --- include/llvm/IR/Constants.h +++ include/llvm/IR/Constants.h @@ -27,6 +27,7 @@ #include "llvm/IR/Constant.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/OperandTraits.h" +#include "llvm/Support/Predicate.h" namespace llvm { @@ -1057,15 +1058,15 @@ /// \brief Return an ICmp or FCmp comparison operator constant expression. /// /// \param OnlyIfReduced see \a getWithOperands() docs. - static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2, + static Constant *getCompare(Predicate pred, Constant *C1, Constant *C2, bool OnlyIfReduced = false); /// get* - Return some common constants without having to /// specify the full Instruction::OPCODE identifier. /// - static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS, + static Constant *getICmp(Predicate pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced = false); - static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, + static Constant *getFCmp(Predicate pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced = false); /// Getelementptr form. Value* is only accepted for convenience; @@ -1128,7 +1129,7 @@ /// Return the ICMP or FCMP predicate value. Assert if this is not an ICMP or /// FCMP constant expression. - unsigned getPredicate() const; + Predicate getPredicate() const; /// Assert that this is an insertvalue or exactvalue /// expression and return the list of indices. Index: include/llvm/IR/IRBuilder.h =================================================================== --- include/llvm/IR/IRBuilder.h +++ include/llvm/IR/IRBuilder.h @@ -1452,102 +1452,102 @@ //===--------------------------------------------------------------------===// Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") { - return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name); + return CreateICmp(Predicate::ICMP_EQ, LHS, RHS, Name); } Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") { - return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name); + return CreateICmp(Predicate::ICMP_NE, LHS, RHS, Name); } Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") { - return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name); + return CreateICmp(Predicate::ICMP_UGT, LHS, RHS, Name); } Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") { - return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name); + return CreateICmp(Predicate::ICMP_UGE, LHS, RHS, Name); } Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") { - return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name); + return CreateICmp(Predicate::ICMP_ULT, LHS, RHS, Name); } Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") { - return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name); + return CreateICmp(Predicate::ICMP_ULE, LHS, RHS, Name); } Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") { - return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name); + return CreateICmp(Predicate::ICMP_SGT, LHS, RHS, Name); } Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") { - return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name); + return CreateICmp(Predicate::ICMP_SGE, LHS, RHS, Name); } Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") { - return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name); + return CreateICmp(Predicate::ICMP_SLT, LHS, RHS, Name); } Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") { - return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name); + return CreateICmp(Predicate::ICMP_SLE, LHS, RHS, Name); } Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_OEQ, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_OGT, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_OGE, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_OLT, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_OLE, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_ONE, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_ORD, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_UNO, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_UEQ, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_UGT, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_UGE, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_ULT, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_ULE, LHS, RHS, Name, FPMathTag); } Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "", MDNode *FPMathTag = nullptr) { - return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag); + return CreateFCmp(Predicate::FCMP_UNE, LHS, RHS, Name, FPMathTag); } - Value *CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, + Value *CreateICmp(Predicate P, Value *LHS, Value *RHS, const Twine &Name = "") { if (Constant *LC = dyn_cast(LHS)) if (Constant *RC = dyn_cast(RHS)) return Insert(Folder.CreateICmp(P, LC, RC), Name); return Insert(new ICmpInst(P, LHS, RHS), Name); } - Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, - const Twine &Name = "", MDNode *FPMathTag = nullptr) { + Value *CreateFCmp(Predicate P, Value *LHS, Value *RHS, const Twine &Name = "", + MDNode *FPMathTag = nullptr) { if (Constant *LC = dyn_cast(LHS)) if (Constant *RC = dyn_cast(RHS)) return Insert(Folder.CreateFCmp(P, LC, RC), Name); Index: include/llvm/IR/InstrTypes.h =================================================================== --- include/llvm/IR/InstrTypes.h +++ include/llvm/IR/InstrTypes.h @@ -23,6 +23,7 @@ #include "llvm/IR/Instruction.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/OperandTraits.h" +#include "llvm/Support/Predicate.h" namespace llvm { @@ -854,51 +855,6 @@ /// This class is the base class for the comparison instructions. /// @brief Abstract base class of comparison instructions. class CmpInst : public Instruction { -public: - /// This enumeration lists the possible predicates for CmpInst subclasses. - /// Values in the range 0-31 are reserved for FCmpInst, while values in the - /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the - /// predicate values are not overlapping between the classes. - /// - /// Some passes (e.g. InstCombine) depend on the bit-wise characteristics of - /// FCMP_* values. Changing the bit patterns requires a potential change to - /// those passes. - enum Predicate { - // Opcode U L G E Intuitive operation - FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded) - FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal - FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than - FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal - FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than - FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal - FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal - FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans) - FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y) - FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal - FCMP_UGT = 10, ///< 1 0 1 0 True if unordered or greater than - FCMP_UGE = 11, ///< 1 0 1 1 True if unordered, greater than, or equal - FCMP_ULT = 12, ///< 1 1 0 0 True if unordered or less than - FCMP_ULE = 13, ///< 1 1 0 1 True if unordered, less than, or equal - FCMP_UNE = 14, ///< 1 1 1 0 True if unordered or not equal - FCMP_TRUE = 15, ///< 1 1 1 1 Always true (always folded) - FIRST_FCMP_PREDICATE = FCMP_FALSE, - LAST_FCMP_PREDICATE = FCMP_TRUE, - BAD_FCMP_PREDICATE = FCMP_TRUE + 1, - ICMP_EQ = 32, ///< equal - ICMP_NE = 33, ///< not equal - ICMP_UGT = 34, ///< unsigned greater than - ICMP_UGE = 35, ///< unsigned greater or equal - ICMP_ULT = 36, ///< unsigned less than - ICMP_ULE = 37, ///< unsigned less or equal - ICMP_SGT = 38, ///< signed greater than - ICMP_SGE = 39, ///< signed greater or equal - ICMP_SLT = 40, ///< signed less than - ICMP_SLE = 41, ///< signed less or equal - FIRST_ICMP_PREDICATE = ICMP_EQ, - LAST_ICMP_PREDICATE = ICMP_SLE, - BAD_ICMP_PREDICATE = ICMP_SLE + 1 - }; - private: void *operator new(size_t, unsigned) = delete; CmpInst() = delete; @@ -947,32 +903,18 @@ } /// @brief Set the predicate for this instruction to the specified value. - void setPredicate(Predicate P) { setInstructionSubclassData(P); } - - static bool isFPPredicate(Predicate P) { - return P >= FIRST_FCMP_PREDICATE && P <= LAST_FCMP_PREDICATE; - } - - static bool isIntPredicate(Predicate P) { - return P >= FIRST_ICMP_PREDICATE && P <= LAST_ICMP_PREDICATE; + void setPredicate(Predicate P) { + setInstructionSubclassData(static_cast(P.getKind())); } - bool isFPPredicate() const { return isFPPredicate(getPredicate()); } - bool isIntPredicate() const { return isIntPredicate(getPredicate()); } + bool isFPPredicate() const { return getPredicate().isFP(); } + bool isIntPredicate() const { return getPredicate().isInt(); } /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc. /// @returns the inverse predicate for the instruction's current predicate. /// @brief Return the inverse of the instruction's predicate. - Predicate getInversePredicate() const { - return getInversePredicate(getPredicate()); - } - - /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, - /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc. - /// @returns the inverse predicate for predicate provided in \p pred. - /// @brief Return the inverse of a given predicate - static Predicate getInversePredicate(Predicate pred); + Predicate getInversePredicate() const { return getPredicate().getInverse(); } /// For example, EQ->EQ, SLE->SGE, ULT->UGT, /// OEQ->OEQ, ULE->UGE, OLT->OGT, etc. @@ -980,14 +922,7 @@ /// operands of the CmpInst instruction without changing the result /// produced. /// @brief Return the predicate as if the operands were swapped - Predicate getSwappedPredicate() const { - return getSwappedPredicate(getPredicate()); - } - - /// This is a static version that you can use without an instruction - /// available. - /// @brief Return the predicate as if the operands were swapped. - static Predicate getSwappedPredicate(Predicate pred); + Predicate getSwappedPredicate() const { return getPredicate().getSwapped(); } /// @brief Provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -997,91 +932,58 @@ /// the same comparison. void swapOperands(); - /// This is just a convenience that dispatches to the subclasses. /// @brief Determine if this CmpInst is commutative. - bool isCommutative() const; + bool isCommutative() const { return getPredicate().isCommutative(); } + + /// @returns true if the predicate is relational (i.e. not commutative). + bool isRelational() const { return getPredicate().isRelational(); } /// This is just a convenience that dispatches to the subclasses. /// @brief Determine if this is an equals/not equals predicate. - bool isEquality() const; + bool isEquality() const { return getPredicate().isEquality(); } /// @returns true if the comparison is signed, false otherwise. /// @brief Determine if this instruction is using a signed comparison. - bool isSigned() const { - return isSigned(getPredicate()); - } + bool isSigned() const { return getPredicate().isSigned(); } /// @returns true if the comparison is unsigned, false otherwise. /// @brief Determine if this instruction is using an unsigned comparison. - bool isUnsigned() const { - return isUnsigned(getPredicate()); - } - - /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert - /// @returns the signed version of the unsigned predicate pred. - /// @brief return the signed version of a predicate - static Predicate getSignedPredicate(Predicate pred); + bool isUnsigned() const { return getPredicate().isUnsigned(); } /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert /// @returns the signed version of the predicate for this instruction (which /// has to be an unsigned predicate). /// @brief return the signed version of a predicate - Predicate getSignedPredicate() { - return getSignedPredicate(getPredicate()); + Predicate getSignedPredicate() { return getPredicate().getSigned(); } + + /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc. + /// @returns the predicate that would be the result if the operand were + /// regarded as unsigned. + /// \brief Return the unsigned version of the predicate + Predicate getUnsignedPredicate() const { + return getPredicate().getUnsigned(); } /// This is just a convenience. /// @brief Determine if this is true when both operands are the same. - bool isTrueWhenEqual() const { - return isTrueWhenEqual(getPredicate()); - } + bool isTrueWhenEqual() const { return getPredicate().isTrueWhenEqual(); } /// This is just a convenience. /// @brief Determine if this is false when both operands are the same. - bool isFalseWhenEqual() const { - return isFalseWhenEqual(getPredicate()); - } + bool isFalseWhenEqual() const { return getPredicate().isFalseWhenEqual(); } /// @brief Determine if Pred1 implies Pred2 is true when two compares have /// matching operands. bool isImpliedTrueByMatchingCmp(Predicate Pred2) { - return isImpliedTrueByMatchingCmp(getPredicate(), Pred2); + return getPredicate().isImpliedTrueByMatchingCmp(Pred2); } /// @brief Determine if Pred1 implies Pred2 is false when two compares have /// matching operands. bool isImpliedFalseByMatchingCmp(Predicate Pred2) { - return isImpliedFalseByMatchingCmp(getPredicate(), Pred2); + return getPredicate().isImpliedFalseByMatchingCmp(Pred2); } - /// @returns true if the predicate is unsigned, false otherwise. - /// @brief Determine if the predicate is an unsigned operation. - static bool isUnsigned(Predicate predicate); - - /// @returns true if the predicate is signed, false otherwise. - /// @brief Determine if the predicate is an signed operation. - static bool isSigned(Predicate predicate); - - /// @brief Determine if the predicate is an ordered operation. - static bool isOrdered(Predicate predicate); - - /// @brief Determine if the predicate is an unordered operation. - static bool isUnordered(Predicate predicate); - - /// Determine if the predicate is true when comparing a value with itself. - static bool isTrueWhenEqual(Predicate predicate); - - /// Determine if the predicate is false when comparing a value with itself. - static bool isFalseWhenEqual(Predicate predicate); - - /// Determine if Pred1 implies Pred2 is true when two compares have matching - /// operands. - static bool isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2); - - /// Determine if Pred1 implies Pred2 is false when two compares have matching - /// operands. - static bool isImpliedFalseByMatchingCmp(Predicate Pred1, Predicate Pred2); - /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const Instruction *I) { return I->getOpcode() == Instruction::ICmp || Index: include/llvm/IR/Instructions.h =================================================================== --- include/llvm/IR/Instructions.h +++ include/llvm/IR/Instructions.h @@ -1072,9 +1072,7 @@ void anchor() override; void AssertOK() { - assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE && - getPredicate() <= CmpInst::LAST_ICMP_PREDICATE && - "Invalid ICmp predicate value"); + assert(getPredicate().isInt() && "Invalid ICmp predicate value"); assert(getOperand(0)->getType() == getOperand(1)->getType() && "Both operands to ICmp instruction are not of the same type!"); // Check that the operands are the right type @@ -1133,58 +1131,6 @@ #endif } - /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc. - /// @returns the predicate that would be the result if the operand were - /// regarded as signed. - /// Return the signed version of the predicate - Predicate getSignedPredicate() const { - return getSignedPredicate(getPredicate()); - } - - /// This is a static version that you can use without an instruction. - /// Return the signed version of the predicate. - static Predicate getSignedPredicate(Predicate pred); - - /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc. - /// @returns the predicate that would be the result if the operand were - /// regarded as unsigned. - /// Return the unsigned version of the predicate - Predicate getUnsignedPredicate() const { - return getUnsignedPredicate(getPredicate()); - } - - /// This is a static version that you can use without an instruction. - /// Return the unsigned version of the predicate. - static Predicate getUnsignedPredicate(Predicate pred); - - /// Return true if this predicate is either EQ or NE. This also - /// tests for commutativity. - static bool isEquality(Predicate P) { - return P == ICMP_EQ || P == ICMP_NE; - } - - /// Return true if this predicate is either EQ or NE. This also - /// tests for commutativity. - bool isEquality() const { - return isEquality(getPredicate()); - } - - /// @returns true if the predicate of this ICmpInst is commutative - /// Determine if this relation is commutative. - bool isCommutative() const { return isEquality(); } - - /// Return true if the predicate is relational (not EQ or NE). - /// - bool isRelational() const { - return !isEquality(); - } - - /// Return true if the predicate is relational (not EQ or NE). - /// - static bool isRelational(Predicate P) { - return !isEquality(P); - } - /// Initialize a set of values that all satisfy the predicate with C. /// Make a ConstantRange for a relation with a constant value. static ConstantRange makeConstantRange(Predicate pred, const APInt &C); @@ -1234,8 +1180,7 @@ ) : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS, RHS, NameStr, InsertBefore) { - assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && - "Invalid FCmp predicate value"); + assert(pred.isFP() && "Invalid FCmp predicate value"); assert(getOperand(0)->getType() == getOperand(1)->getType() && "Both operands to FCmp instruction are not of the same type!"); // Check that the operands are the right type @@ -1253,8 +1198,7 @@ ) : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS, RHS, NameStr, &InsertAtEnd) { - assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && - "Invalid FCmp predicate value"); + assert(pred.isFP() && "Invalid FCmp predicate value"); assert(getOperand(0)->getType() == getOperand(1)->getType() && "Both operands to FCmp instruction are not of the same type!"); // Check that the operands are the right type @@ -1270,8 +1214,7 @@ const Twine &NameStr = "" ///< Name of the instruction ) : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS, RHS, NameStr) { - assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && - "Invalid FCmp predicate value"); + assert(pred.isFP() && "Invalid FCmp predicate value"); assert(getOperand(0)->getType() == getOperand(1)->getType() && "Both operands to FCmp instruction are not of the same type!"); // Check that the operands are the right type @@ -1279,31 +1222,6 @@ "Invalid operand types for FCmp instruction"); } - /// @returns true if the predicate of this instruction is EQ or NE. - /// Determine if this is an equality predicate. - static bool isEquality(Predicate Pred) { - return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ || - Pred == FCMP_UNE; - } - - /// @returns true if the predicate of this instruction is EQ or NE. - /// Determine if this is an equality predicate. - bool isEquality() const { return isEquality(getPredicate()); } - - /// @returns true if the predicate of this instruction is commutative. - /// Determine if this is a commutative predicate. - bool isCommutative() const { - return isEquality() || - getPredicate() == FCMP_FALSE || - getPredicate() == FCMP_TRUE || - getPredicate() == FCMP_ORD || - getPredicate() == FCMP_UNO; - } - - /// @returns true if the predicate is relational (not EQ or NE). - /// Determine if this a relational predicate. - bool isRelational() const { return !isEquality(); } - /// Exchange the two operands to this instruction in such a way that it does /// not modify the semantics of the instruction. The predicate value may be /// changed to retain the same result if the predicate is order dependent Index: include/llvm/IR/NoFolder.h =================================================================== --- include/llvm/IR/NoFolder.h +++ include/llvm/IR/NoFolder.h @@ -251,12 +251,10 @@ // Compare Instructions //===--------------------------------------------------------------------===// - Instruction *CreateICmp(CmpInst::Predicate P, - Constant *LHS, Constant *RHS) const { + Instruction *CreateICmp(Predicate P, Constant *LHS, Constant *RHS) const { return new ICmpInst(P, LHS, RHS); } - Instruction *CreateFCmp(CmpInst::Predicate P, - Constant *LHS, Constant *RHS) const { + Instruction *CreateFCmp(Predicate P, Constant *LHS, Constant *RHS) const { return new FCmpInst(P, LHS, RHS); } Index: include/llvm/IR/PatternMatch.h =================================================================== --- include/llvm/IR/PatternMatch.h +++ include/llvm/IR/PatternMatch.h @@ -716,21 +716,21 @@ }; template -inline CmpClass_match -m_Cmp(CmpInst::Predicate &Pred, const LHS &L, const RHS &R) { - return CmpClass_match(Pred, L, R); +inline CmpClass_match +m_Cmp(Predicate &Pred, const LHS &L, const RHS &R) { + return CmpClass_match(Pred, L, R); } template -inline CmpClass_match -m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) { - return CmpClass_match(Pred, L, R); +inline CmpClass_match +m_ICmp(Predicate &Pred, const LHS &L, const RHS &R) { + return CmpClass_match(Pred, L, R); } template -inline CmpClass_match -m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) { - return CmpClass_match(Pred, L, R); +inline CmpClass_match +m_FCmp(Predicate &Pred, const LHS &L, const RHS &R) { + return CmpClass_match(Pred, L, R); } //===----------------------------------------------------------------------===// @@ -971,7 +971,7 @@ if ((TrueVal != LHS || FalseVal != RHS) && (TrueVal != RHS || FalseVal != LHS)) return false; - typename CmpInst_t::Predicate Pred = + Predicate Pred = LHS == TrueVal ? Cmp->getPredicate() : Cmp->getSwappedPredicate(); // Does "(x pred y) ? x : y" represent the desired max/min operation? if (!Pred_t::match(Pred)) @@ -983,57 +983,57 @@ /// \brief Helper class for identifying signed max predicates. struct smax_pred_ty { - static bool match(ICmpInst::Predicate Pred) { - return Pred == CmpInst::ICMP_SGT || Pred == CmpInst::ICMP_SGE; + static bool match(Predicate Pred) { + return Pred.isOneOf(Predicate::ICMP_SGT, Predicate::ICMP_SGE); } }; /// \brief Helper class for identifying signed min predicates. struct smin_pred_ty { - static bool match(ICmpInst::Predicate Pred) { - return Pred == CmpInst::ICMP_SLT || Pred == CmpInst::ICMP_SLE; + static bool match(Predicate Pred) { + return Pred.isOneOf(Predicate::ICMP_SLT, Predicate::ICMP_SLE); } }; /// \brief Helper class for identifying unsigned max predicates. struct umax_pred_ty { - static bool match(ICmpInst::Predicate Pred) { - return Pred == CmpInst::ICMP_UGT || Pred == CmpInst::ICMP_UGE; + static bool match(Predicate Pred) { + return Pred.isOneOf(Predicate::ICMP_UGT, Predicate::ICMP_UGE); } }; /// \brief Helper class for identifying unsigned min predicates. struct umin_pred_ty { - static bool match(ICmpInst::Predicate Pred) { - return Pred == CmpInst::ICMP_ULT || Pred == CmpInst::ICMP_ULE; + static bool match(Predicate Pred) { + return Pred.isOneOf(Predicate::ICMP_ULT, Predicate::ICMP_ULE); } }; /// \brief Helper class for identifying ordered max predicates. struct ofmax_pred_ty { - static bool match(FCmpInst::Predicate Pred) { - return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE; + static bool match(Predicate Pred) { + return Pred.isOneOf(Predicate::FCMP_OGT, Predicate::FCMP_OGE); } }; /// \brief Helper class for identifying ordered min predicates. struct ofmin_pred_ty { - static bool match(FCmpInst::Predicate Pred) { - return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE; + static bool match(Predicate Pred) { + return Pred.isOneOf(Predicate::FCMP_OLT, Predicate::FCMP_OLE); } }; /// \brief Helper class for identifying unordered max predicates. struct ufmax_pred_ty { - static bool match(FCmpInst::Predicate Pred) { - return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE; + static bool match(Predicate Pred) { + return Pred.isOneOf(Predicate::FCMP_UGT, Predicate::FCMP_UGE); } }; /// \brief Helper class for identifying unordered min predicates. struct ufmin_pred_ty { - static bool match(FCmpInst::Predicate Pred) { - return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE; + static bool match(Predicate Pred) { + return Pred.isOneOf(Predicate::FCMP_ULT, Predicate::FCMP_ULE); } }; @@ -1121,7 +1121,7 @@ template bool match(OpTy *V) { Value *ICmpLHS, *ICmpRHS; - ICmpInst::Predicate Pred; + Predicate Pred; if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V)) return false; @@ -1129,12 +1129,12 @@ auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS)); // (a + b) u< a, (a + b) u< b - if (Pred == ICmpInst::ICMP_ULT) + if (Pred.isOneOf(Predicate::ICMP_ULT)) if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS)) return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS); // a >u (a + b), b >u (a + b) - if (Pred == ICmpInst::ICMP_UGT) + if (Pred.isOneOf(Predicate::ICMP_UGT)) if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS)) return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS); @@ -1318,10 +1318,10 @@ /// \brief Matches an ICmp with a predicate over LHS and RHS in either order. /// Does not swap the predicate. -template -inline match_combine_or, - CmpClass_match> -m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) { +template +inline match_combine_or, + CmpClass_match> +m_c_ICmp(Predicate &Pred, const LHS &L, const RHS &R) { return m_CombineOr(m_ICmp(Pred, L, R), m_ICmp(Pred, R, L)); } Index: include/llvm/Support/Predicate.h =================================================================== --- /dev/null +++ include/llvm/Support/Predicate.h @@ -0,0 +1,149 @@ +#ifndef LLVM_SUPPORT_PREDICATE +#define LLVM_SUPPORT_PREDICATE + +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/ErrorHandling.h" + +namespace llvm { + +class Predicate { +public: + /// This enumeration lists the possible predicates for CmpInst subclasses. + /// Values in the range 0-31 are reserved for FCmpInst, while values in the + /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the + /// predicate values are not overlapping between the classes. + /// + /// Some passes (e.g. InstCombine) depend on the bit-wise characteristics of + /// FCMP_* values. Changing the bit patterns requires a potential change to + /// those passes. + enum PredicateKind { + // Opcode U L G E Intuitive operation + FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded) + FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal + FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than + FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal + FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than + FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal + FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal + FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans) + FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y) + FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal + FCMP_UGT = 10, ///< 1 0 1 0 True if unordered or greater than + FCMP_UGE = 11, ///< 1 0 1 1 True if unordered, greater than, or equal + FCMP_ULT = 12, ///< 1 1 0 0 True if unordered or less than + FCMP_ULE = 13, ///< 1 1 0 1 True if unordered, less than, or equal + FCMP_UNE = 14, ///< 1 1 1 0 True if unordered or not equal + FCMP_TRUE = 15, ///< 1 1 1 1 Always true (always folded) + FIRST_FCMP_PREDICATE = FCMP_FALSE, + LAST_FCMP_PREDICATE = FCMP_TRUE, + BAD_FCMP_PREDICATE = FCMP_TRUE + 1, + ICMP_EQ = 32, ///< equal + ICMP_NE = 33, ///< not equal + ICMP_UGT = 34, ///< unsigned greater than + ICMP_UGE = 35, ///< unsigned greater or equal + ICMP_ULT = 36, ///< unsigned less than + ICMP_ULE = 37, ///< unsigned less or equal + ICMP_SGT = 38, ///< signed greater than + ICMP_SGE = 39, ///< signed greater or equal + ICMP_SLT = 40, ///< signed less than + ICMP_SLE = 41, ///< signed less or equal + FIRST_ICMP_PREDICATE = ICMP_EQ, + LAST_ICMP_PREDICATE = ICMP_SLE, + BAD_ICMP_PREDICATE = ICMP_SLE + 1 + }; + + Predicate() : Pred(BAD_ICMP_PREDICATE) {} + + Predicate(PredicateKind K) : Pred(K) {} + + explicit Predicate(unsigned K) : Pred(static_cast(K)) {} + + bool operator==(const Predicate &Other) const { return Pred == Other.Pred; } + bool operator!=(const Predicate &Other) const { return Pred != Other.Pred; } + + PredicateKind getKind() const { return Pred; } + + bool isFP() const { + return Pred >= FIRST_FCMP_PREDICATE && Pred <= LAST_FCMP_PREDICATE; + } + + bool isInt() const { + return Pred >= FIRST_ICMP_PREDICATE && Pred <= LAST_ICMP_PREDICATE; + } + + /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, + /// OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc. + /// @returns the inverse predicate for predicate provided in \p pred. + /// @brief Return the inverse of a given predicate + Predicate getInverse() const; + + /// For example, EQ->EQ, SLE->SGE, ULT->UGT, + /// OEQ->OEQ, ULE->UGE, OLT->OGT, etc. + /// @returns the predicate that would be the result of exchanging the two + /// operands of the CmpInst instruction without changing the result + /// produced. + /// @brief Return the predicate as if the operands were swapped + Predicate getSwapped() const; + + /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert + /// @returns the signed version of the unsigned predicate pred. + /// @brief return the signed version of a predicate + Predicate getSigned() const; + + /// For example, ULT->SLT, ULE->SLE, UGT->SGT, UGE->SGE, SLT->Failed assert + /// @returns the signed version of the unsigned predicate pred. + /// @brief return the signed version of a predicate + Predicate getUnsigned() const; + + /// @returns true if the predicate is unsigned, false otherwise. + /// @brief Determine if the predicate is an unsigned operation. + bool isUnsigned() const; + + /// @returns true if the predicate is signed, false otherwise. + /// @brief Determine if the predicate is an signed operation. + bool isSigned() const; + + /// @brief Determine if the predicate is an ordered operation. + bool isOrdered() const; + + /// @brief Determine if the predicate is an unordered operation. + bool isUnordered() const; + + /// Determine if the predicate is true when comparing a value with itself. + bool isTrueWhenEqual() const; + + /// Determine if the predicate is false when comparing a value with itself. + bool isFalseWhenEqual() const; + + /// Determine if the predicate is testing for equality. FIXME: floats???? + bool isEquality() const; + + /// Determine if the predicate is commutative (equality, true, false, ord or + /// uno). + bool isCommutative() const; + + /// Return true if the predicate is relational (not EQ or NE). + bool isRelational() const; + + /// Determine if Pred1 implies Pred2 is true when two compares have matching + /// operands. + bool isImpliedTrueByMatchingCmp(Predicate Pred2) const; + + /// Determine if Pred1 implies Pred2 is false when two compares have matching + /// operands. + bool isImpliedFalseByMatchingCmp(Predicate Pred2) const; + + StringRef getName() const; + + bool isOneOf() const { return false; } + + template + bool isOneOf(PredicateKind Kind, Kinds... Others) { + return (Pred == Kind) || isOneOf(Others...); + } + +private: + PredicateKind Pred; +}; +} +#endif Index: include/llvm/Transforms/Scalar/GVN.h =================================================================== --- include/llvm/Transforms/Scalar/GVN.h +++ include/llvm/Transforms/Scalar/GVN.h @@ -73,8 +73,8 @@ uint32_t nextValueNumber; Expression createExpr(Instruction *I); - Expression createCmpExpr(unsigned Opcode, CmpInst::Predicate Predicate, - Value *LHS, Value *RHS); + Expression createCmpExpr(unsigned Opcode, Predicate Predicate, Value *LHS, + Value *RHS); Expression createExtractvalueExpr(ExtractValueInst *EI); uint32_t lookupOrAddCall(CallInst *C); @@ -86,8 +86,8 @@ uint32_t lookupOrAdd(Value *V); uint32_t lookup(Value *V) const; - uint32_t lookupOrAddCmp(unsigned Opcode, CmpInst::Predicate Pred, - Value *LHS, Value *RHS); + uint32_t lookupOrAddCmp(unsigned Opcode, Predicate Pred, Value *LHS, + Value *RHS); bool exists(Value *V) const; void add(Value *V, uint32_t num); void clear(); Index: include/llvm/Transforms/Utils/CmpInstAnalysis.h =================================================================== --- include/llvm/Transforms/Utils/CmpInstAnalysis.h +++ include/llvm/Transforms/Utils/CmpInstAnalysis.h @@ -54,16 +54,16 @@ /// NULL return means a new ICmp is needed. The predicate for which is output /// in NewICmpPred. Value *getICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, - CmpInst::Predicate &NewICmpPred); + Predicate &NewICmpPred); /// Return true if both predicates match sign or if at least one of them is an /// equality comparison (which is signless). - bool PredicatesFoldable(CmpInst::Predicate p1, CmpInst::Predicate p2); + bool PredicatesFoldable(Predicate p1, Predicate p2); /// Decompose an icmp into the form ((X & Y) pred Z) if possible. The returned /// predicate is either == or !=. Returns false if decomposition fails. - bool decomposeBitTestICmp(const ICmpInst *I, CmpInst::Predicate &Pred, - Value *&X, Value *&Y, Value *&Z); + bool decomposeBitTestICmp(const ICmpInst *I, Predicate &Pred, Value *&X, + Value *&Y, Value *&Z); } // end namespace llvm Index: lib/Analysis/BranchProbabilityInfo.cpp =================================================================== --- lib/Analysis/BranchProbabilityInfo.cpp +++ lib/Analysis/BranchProbabilityInfo.cpp @@ -329,7 +329,7 @@ // p != q -> isProb = true // p == q -> isProb = false; unsigned TakenIdx = 0, NonTakenIdx = 1; - bool isProb = CI->getPredicate() == ICmpInst::ICMP_NE; + bool isProb = CI->getPredicate() == Predicate::ICMP_NE; if (!isProb) std::swap(TakenIdx, NonTakenIdx); @@ -425,41 +425,41 @@ bool isProb; if (CV->isZero()) { - switch (CI->getPredicate()) { - case CmpInst::ICMP_EQ: + switch (CI->getPredicate().getKind()) { + case Predicate::ICMP_EQ: // X == 0 -> Unlikely isProb = false; break; - case CmpInst::ICMP_NE: + case Predicate::ICMP_NE: // X != 0 -> Likely isProb = true; break; - case CmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: // X < 0 -> Unlikely isProb = false; break; - case CmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: // X > 0 -> Likely isProb = true; break; default: return false; } - } else if (CV->isOne() && CI->getPredicate() == CmpInst::ICMP_SLT) { + } else if (CV->isOne() && CI->getPredicate() == Predicate::ICMP_SLT) { // InstCombine canonicalizes X <= 0 into X < 1. // X <= 0 -> Unlikely isProb = false; } else if (CV->isAllOnesValue()) { - switch (CI->getPredicate()) { - case CmpInst::ICMP_EQ: + switch (CI->getPredicate().getKind()) { + case Predicate::ICMP_EQ: // X == -1 -> Unlikely isProb = false; break; - case CmpInst::ICMP_NE: + case Predicate::ICMP_NE: // X != -1 -> Likely isProb = true; break; - case CmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: // InstCombine canonicalizes X >= 0 into X > -1. // X >= 0 -> Likely isProb = true; @@ -498,10 +498,10 @@ // f1 == f2 -> Unlikely // f1 != f2 -> Likely isProb = !FCmp->isTrueWhenEqual(); - } else if (FCmp->getPredicate() == FCmpInst::FCMP_ORD) { + } else if (FCmp->getPredicate() == Predicate::FCMP_ORD) { // !isnan -> Likely isProb = true; - } else if (FCmp->getPredicate() == FCmpInst::FCMP_UNO) { + } else if (FCmp->getPredicate() == Predicate::FCMP_UNO) { // isnan -> Unlikely isProb = false; } else { Index: lib/Analysis/ConstantFolding.cpp =================================================================== --- lib/Analysis/ConstantFolding.cpp +++ lib/Analysis/ConstantFolding.cpp @@ -1107,8 +1107,8 @@ return ConstantFoldInstOperandsImpl(I, I->getOpcode(), Ops, DL, TLI); } -Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, - Constant *Ops0, Constant *Ops1, +Constant *llvm::ConstantFoldCompareInstOperands(Predicate Pred, Constant *Ops0, + Constant *Ops1, const DataLayout &DL, const TargetLibraryInfo *TLI) { // fold: icmp (inttoptr x), null -> icmp x, 0 @@ -1128,7 +1128,7 @@ Constant *C = ConstantExpr::getIntegerCast(CE0->getOperand(0), IntPtrTy, false); Constant *Null = Constant::getNullValue(C->getType()); - return ConstantFoldCompareInstOperands(Predicate, C, Null, DL, TLI); + return ConstantFoldCompareInstOperands(Pred, C, Null, DL, TLI); } // Only do this transformation if the int is intptrty in size, otherwise @@ -1138,7 +1138,7 @@ if (CE0->getType() == IntPtrTy) { Constant *C = CE0->getOperand(0); Constant *Null = Constant::getNullValue(C->getType()); - return ConstantFoldCompareInstOperands(Predicate, C, Null, DL, TLI); + return ConstantFoldCompareInstOperands(Pred, C, Null, DL, TLI); } } } @@ -1154,7 +1154,7 @@ IntPtrTy, false); Constant *C1 = ConstantExpr::getIntegerCast(CE1->getOperand(0), IntPtrTy, false); - return ConstantFoldCompareInstOperands(Predicate, C0, C1, DL, TLI); + return ConstantFoldCompareInstOperands(Pred, C0, C1, DL, TLI); } // Only do this transformation if the int is intptrty in size, otherwise @@ -1163,8 +1163,8 @@ Type *IntPtrTy = DL.getIntPtrType(CE0->getOperand(0)->getType()); if (CE0->getType() == IntPtrTy && CE0->getOperand(0)->getType() == CE1->getOperand(0)->getType()) { - return ConstantFoldCompareInstOperands( - Predicate, CE0->getOperand(0), CE1->getOperand(0), DL, TLI); + return ConstantFoldCompareInstOperands(Pred, CE0->getOperand(0), + CE1->getOperand(0), DL, TLI); } } } @@ -1172,19 +1172,19 @@ // icmp eq (or x, y), 0 -> (icmp eq x, 0) & (icmp eq y, 0) // icmp ne (or x, y), 0 -> (icmp ne x, 0) | (icmp ne y, 0) - if ((Predicate == ICmpInst::ICMP_EQ || Predicate == ICmpInst::ICMP_NE) && + if ((Pred == Predicate::ICMP_EQ || Pred == Predicate::ICMP_NE) && CE0->getOpcode() == Instruction::Or && Ops1->isNullValue()) { - Constant *LHS = ConstantFoldCompareInstOperands( - Predicate, CE0->getOperand(0), Ops1, DL, TLI); - Constant *RHS = ConstantFoldCompareInstOperands( - Predicate, CE0->getOperand(1), Ops1, DL, TLI); + Constant *LHS = ConstantFoldCompareInstOperands(Pred, CE0->getOperand(0), + Ops1, DL, TLI); + Constant *RHS = ConstantFoldCompareInstOperands(Pred, CE0->getOperand(1), + Ops1, DL, TLI); unsigned OpC = - Predicate == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or; + Pred == Predicate::ICMP_EQ ? Instruction::And : Instruction::Or; return ConstantFoldBinaryOpOperands(OpC, LHS, RHS, DL); } } - return ConstantExpr::getCompare(Predicate, Ops0, Ops1); + return ConstantExpr::getCompare(Pred, Ops0, Ops1); } Constant *llvm::ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Index: lib/Analysis/DependenceAnalysis.cpp =================================================================== --- lib/Analysis/DependenceAnalysis.cpp +++ lib/Analysis/DependenceAnalysis.cpp @@ -433,9 +433,9 @@ if (X->isDistance() && Y->isDistance()) { DEBUG(dbgs() << "\t intersect 2 distances\n"); - if (isKnownPredicate(CmpInst::ICMP_EQ, X->getD(), Y->getD())) + if (isKnownPredicate(Predicate::ICMP_EQ, X->getD(), Y->getD())) return false; - if (isKnownPredicate(CmpInst::ICMP_NE, X->getD(), Y->getD())) { + if (isKnownPredicate(Predicate::ICMP_NE, X->getD(), Y->getD())) { X->setEmpty(); ++DeltaSuccesses; return true; @@ -462,21 +462,21 @@ DEBUG(dbgs() << "\t intersect 2 lines\n"); const SCEV *Prod1 = SE->getMulExpr(X->getA(), Y->getB()); const SCEV *Prod2 = SE->getMulExpr(X->getB(), Y->getA()); - if (isKnownPredicate(CmpInst::ICMP_EQ, Prod1, Prod2)) { + if (isKnownPredicate(Predicate::ICMP_EQ, Prod1, Prod2)) { // slopes are equal, so lines are parallel DEBUG(dbgs() << "\t\tsame slope\n"); Prod1 = SE->getMulExpr(X->getC(), Y->getB()); Prod2 = SE->getMulExpr(X->getB(), Y->getC()); - if (isKnownPredicate(CmpInst::ICMP_EQ, Prod1, Prod2)) + if (isKnownPredicate(Predicate::ICMP_EQ, Prod1, Prod2)) return false; - if (isKnownPredicate(CmpInst::ICMP_NE, Prod1, Prod2)) { + if (isKnownPredicate(Predicate::ICMP_NE, Prod1, Prod2)) { X->setEmpty(); ++DeltaSuccesses; return true; } return false; } - if (isKnownPredicate(CmpInst::ICMP_NE, Prod1, Prod2)) { + if (isKnownPredicate(Predicate::ICMP_NE, Prod1, Prod2)) { // slopes differ, so lines intersect DEBUG(dbgs() << "\t\tdifferent slopes\n"); const SCEV *C1B2 = SE->getMulExpr(X->getC(), Y->getB()); @@ -548,9 +548,9 @@ const SCEV *A1X1 = SE->getMulExpr(Y->getA(), X->getX()); const SCEV *B1Y1 = SE->getMulExpr(Y->getB(), X->getY()); const SCEV *Sum = SE->getAddExpr(A1X1, B1Y1); - if (isKnownPredicate(CmpInst::ICMP_EQ, Sum, Y->getC())) + if (isKnownPredicate(Predicate::ICMP_EQ, Sum, Y->getC())) return false; - if (isKnownPredicate(CmpInst::ICMP_NE, Sum, Y->getC())) { + if (isKnownPredicate(Predicate::ICMP_NE, Sum, Y->getC())) { X->setEmpty(); ++DeltaSuccesses; return true; @@ -935,10 +935,9 @@ // If SCEV::isKnownPredicate can't prove the predicate, // we try simple subtraction, which seems to help in some cases // involving symbolics. -bool DependenceInfo::isKnownPredicate(ICmpInst::Predicate Pred, const SCEV *X, +bool DependenceInfo::isKnownPredicate(Predicate Pred, const SCEV *X, const SCEV *Y) const { - if (Pred == CmpInst::ICMP_EQ || - Pred == CmpInst::ICMP_NE) { + if (Pred == Predicate::ICMP_EQ || Pred == Predicate::ICMP_NE) { if ((isa(X) && isa(Y)) || (isa(X) && @@ -961,18 +960,18 @@ // By testing with SE->isKnownPredicate first, we avoid // the possibility of overflow when the arguments are constants. const SCEV *Delta = SE->getMinusSCEV(X, Y); - switch (Pred) { - case CmpInst::ICMP_EQ: + switch (Pred.getKind()) { + case Predicate::ICMP_EQ: return Delta->isZero(); - case CmpInst::ICMP_NE: + case Predicate::ICMP_NE: return SE->isKnownNonZero(Delta); - case CmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: return SE->isKnownNonNegative(Delta); - case CmpInst::ICMP_SLE: + case Predicate::ICMP_SLE: return SE->isKnownNonPositive(Delta); - case CmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: return SE->isKnownPositive(Delta); - case CmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: return SE->isKnownNegative(Delta); default: llvm_unreachable("unexpected predicate in isKnownPredicate"); @@ -1021,11 +1020,11 @@ DEBUG(dbgs() << " src = " << *Src << "\n"); DEBUG(dbgs() << " dst = " << *Dst << "\n"); ++ZIVapplications; - if (isKnownPredicate(CmpInst::ICMP_EQ, Src, Dst)) { + if (isKnownPredicate(Predicate::ICMP_EQ, Src, Dst)) { DEBUG(dbgs() << " provably dependent\n"); return false; // provably dependent } - if (isKnownPredicate(CmpInst::ICMP_NE, Src, Dst)) { + if (isKnownPredicate(Predicate::ICMP_NE, Src, Dst)) { DEBUG(dbgs() << " provably independent\n"); ++ZIVindependence; return true; // provably independent @@ -1091,7 +1090,7 @@ const SCEV *AbsCoeff = SE->isKnownNonNegative(Coeff) ? Coeff : SE->getNegativeSCEV(Coeff); const SCEV *Product = SE->getMulExpr(UpperBound, AbsCoeff); - if (isKnownPredicate(CmpInst::ICMP_SGT, AbsDelta, Product)) { + if (isKnownPredicate(Predicate::ICMP_SGT, AbsDelta, Product)) { // Distance greater than trip count - no dependence ++StrongSIVindependence; ++StrongSIVsuccesses; @@ -1267,13 +1266,13 @@ const SCEV *ML = SE->getMulExpr(SE->getMulExpr(ConstCoeff, UpperBound), ConstantTwo); DEBUG(dbgs() << "\t ML = " << *ML << "\n"); - if (isKnownPredicate(CmpInst::ICMP_SGT, Delta, ML)) { + if (isKnownPredicate(Predicate::ICMP_SGT, Delta, ML)) { // Delta too big, no dependence ++WeakCrossingSIVindependence; ++WeakCrossingSIVsuccesses; return true; } - if (isKnownPredicate(CmpInst::ICMP_EQ, Delta, ML)) { + if (isKnownPredicate(Predicate::ICMP_EQ, Delta, ML)) { // i = i' = UB Result.DV[Level].Direction &= unsigned(~Dependence::DVEntry::LT); Result.DV[Level].Direction &= unsigned(~Dependence::DVEntry::GT); @@ -1640,7 +1639,7 @@ NewConstraint.setLine(SE->getZero(Delta->getType()), DstCoeff, Delta, CurLoop); DEBUG(dbgs() << "\t Delta = " << *Delta << "\n"); - if (isKnownPredicate(CmpInst::ICMP_EQ, SrcConst, DstConst)) { + if (isKnownPredicate(Predicate::ICMP_EQ, SrcConst, DstConst)) { if (Level < CommonLevels) { Result.DV[Level].Direction &= Dependence::DVEntry::LE; Result.DV[Level].PeelFirst = true; @@ -1662,12 +1661,12 @@ if (const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->getType())) { DEBUG(dbgs() << "\t UpperBound = " << *UpperBound << "\n"); const SCEV *Product = SE->getMulExpr(AbsCoeff, UpperBound); - if (isKnownPredicate(CmpInst::ICMP_SGT, NewDelta, Product)) { + if (isKnownPredicate(Predicate::ICMP_SGT, NewDelta, Product)) { ++WeakZeroSIVindependence; ++WeakZeroSIVsuccesses; return true; } - if (isKnownPredicate(CmpInst::ICMP_EQ, NewDelta, Product)) { + if (isKnownPredicate(Predicate::ICMP_EQ, NewDelta, Product)) { // dependences caused by last iteration if (Level < CommonLevels) { Result.DV[Level].Direction &= Dependence::DVEntry::GE; @@ -1749,7 +1748,7 @@ NewConstraint.setLine(SrcCoeff, SE->getZero(Delta->getType()), Delta, CurLoop); DEBUG(dbgs() << "\t Delta = " << *Delta << "\n"); - if (isKnownPredicate(CmpInst::ICMP_EQ, DstConst, SrcConst)) { + if (isKnownPredicate(Predicate::ICMP_EQ, DstConst, SrcConst)) { if (Level < CommonLevels) { Result.DV[Level].Direction &= Dependence::DVEntry::LE; Result.DV[Level].PeelFirst = true; @@ -1771,12 +1770,12 @@ if (const SCEV *UpperBound = collectUpperBound(CurLoop, Delta->getType())) { DEBUG(dbgs() << "\t UpperBound = " << *UpperBound << "\n"); const SCEV *Product = SE->getMulExpr(AbsCoeff, UpperBound); - if (isKnownPredicate(CmpInst::ICMP_SGT, NewDelta, Product)) { + if (isKnownPredicate(Predicate::ICMP_SGT, NewDelta, Product)) { ++WeakZeroSIVindependence; ++WeakZeroSIVsuccesses; return true; } - if (isKnownPredicate(CmpInst::ICMP_EQ, NewDelta, Product)) { + if (isKnownPredicate(Predicate::ICMP_EQ, NewDelta, Product)) { // dependences caused by last iteration if (Level < CommonLevels) { Result.DV[Level].Direction &= Dependence::DVEntry::GE; @@ -1981,7 +1980,7 @@ // make sure that c2 - c1 <= a1*N1 const SCEV *A1N1 = SE->getMulExpr(A1, N1); DEBUG(dbgs() << "\t A1*N1 = " << *A1N1 << "\n"); - if (isKnownPredicate(CmpInst::ICMP_SGT, C2_C1, A1N1)) { + if (isKnownPredicate(Predicate::ICMP_SGT, C2_C1, A1N1)) { ++SymbolicRDIVindependence; return true; } @@ -1990,7 +1989,7 @@ // make sure that -a2*N2 <= c2 - c1, or a2*N2 >= c1 - c2 const SCEV *A2N2 = SE->getMulExpr(A2, N2); DEBUG(dbgs() << "\t A2*N2 = " << *A2N2 << "\n"); - if (isKnownPredicate(CmpInst::ICMP_SLT, A2N2, C1_C2)) { + if (isKnownPredicate(Predicate::ICMP_SLT, A2N2, C1_C2)) { ++SymbolicRDIVindependence; return true; } @@ -2004,7 +2003,7 @@ const SCEV *A2N2 = SE->getMulExpr(A2, N2); const SCEV *A1N1_A2N2 = SE->getMinusSCEV(A1N1, A2N2); DEBUG(dbgs() << "\t A1*N1 - A2*N2 = " << *A1N1_A2N2 << "\n"); - if (isKnownPredicate(CmpInst::ICMP_SGT, C2_C1, A1N1_A2N2)) { + if (isKnownPredicate(Predicate::ICMP_SGT, C2_C1, A1N1_A2N2)) { ++SymbolicRDIVindependence; return true; } @@ -2025,7 +2024,7 @@ const SCEV *A2N2 = SE->getMulExpr(A2, N2); const SCEV *A1N1_A2N2 = SE->getMinusSCEV(A1N1, A2N2); DEBUG(dbgs() << "\t A1*N1 - A2*N2 = " << *A1N1_A2N2 << "\n"); - if (isKnownPredicate(CmpInst::ICMP_SGT, A1N1_A2N2, C2_C1)) { + if (isKnownPredicate(Predicate::ICMP_SGT, A1N1_A2N2, C2_C1)) { ++SymbolicRDIVindependence; return true; } @@ -2042,7 +2041,7 @@ // make sure that a1*N1 <= c2 - c1 const SCEV *A1N1 = SE->getMulExpr(A1, N1); DEBUG(dbgs() << "\t A1*N1 = " << *A1N1 << "\n"); - if (isKnownPredicate(CmpInst::ICMP_SGT, A1N1, C2_C1)) { + if (isKnownPredicate(Predicate::ICMP_SGT, A1N1, C2_C1)) { ++SymbolicRDIVindependence; return true; } @@ -2051,7 +2050,7 @@ // make sure that c2 - c1 <= -a2*N2, or c1 - c2 >= a2*N2 const SCEV *A2N2 = SE->getMulExpr(A2, N2); DEBUG(dbgs() << "\t A2*N2 = " << *A2N2 << "\n"); - if (isKnownPredicate(CmpInst::ICMP_SLT, C1_C2, A2N2)) { + if (isKnownPredicate(Predicate::ICMP_SLT, C1_C2, A2N2)) { ++SymbolicRDIVindependence; return true; } @@ -2632,10 +2631,10 @@ BoundInfo *Bound, const SCEV *Delta) const { Bound[Level].Direction = DirKind; if (const SCEV *LowerBound = getLowerBound(Bound)) - if (isKnownPredicate(CmpInst::ICMP_SGT, LowerBound, Delta)) + if (isKnownPredicate(Predicate::ICMP_SGT, LowerBound, Delta)) return false; if (const SCEV *UpperBound = getUpperBound(Bound)) - if (isKnownPredicate(CmpInst::ICMP_SGT, Delta, UpperBound)) + if (isKnownPredicate(Predicate::ICMP_SGT, Delta, UpperBound)) return false; return true; } @@ -2670,10 +2669,10 @@ } else { // If the difference is 0, we won't need to know the number of iterations. - if (isKnownPredicate(CmpInst::ICMP_EQ, A[K].NegPart, B[K].PosPart)) + if (isKnownPredicate(Predicate::ICMP_EQ, A[K].NegPart, B[K].PosPart)) Bound[K].Lower[Dependence::DVEntry::ALL] = SE->getZero(A[K].Coeff->getType()); - if (isKnownPredicate(CmpInst::ICMP_EQ, A[K].PosPart, B[K].NegPart)) + if (isKnownPredicate(Predicate::ICMP_EQ, A[K].PosPart, B[K].NegPart)) Bound[K].Upper[Dependence::DVEntry::ALL] = SE->getZero(A[K].Coeff->getType()); } @@ -3066,8 +3065,7 @@ Src = zeroCoefficient(Src, CurLoop); if (!findCoefficient(Dst, CurLoop)->isZero()) Consistent = false; - } - else if (isKnownPredicate(CmpInst::ICMP_EQ, A, B)) { + } else if (isKnownPredicate(Predicate::ICMP_EQ, A, B)) { const SCEVConstant *Aconst = dyn_cast(A); const SCEVConstant *Cconst = dyn_cast(C); if (!Aconst || !Cconst) return false; @@ -3149,18 +3147,15 @@ Level.Scalar = false; Level.Distance = nullptr; unsigned NewDirection = Dependence::DVEntry::NONE; - if (!isKnownPredicate(CmpInst::ICMP_NE, - CurConstraint.getY(), + if (!isKnownPredicate(Predicate::ICMP_NE, CurConstraint.getY(), CurConstraint.getX())) // if X may be = Y NewDirection |= Dependence::DVEntry::EQ; - if (!isKnownPredicate(CmpInst::ICMP_SLE, - CurConstraint.getY(), + if (!isKnownPredicate(Predicate::ICMP_SLE, CurConstraint.getY(), CurConstraint.getX())) // if Y may be > X NewDirection |= Dependence::DVEntry::LT; - if (!isKnownPredicate(CmpInst::ICMP_SGE, - CurConstraint.getY(), + if (!isKnownPredicate(Predicate::ICMP_SGE, CurConstraint.getY(), CurConstraint.getX())) // if Y may be < X NewDirection |= Dependence::DVEntry::GT; Index: lib/Analysis/InlineCost.cpp =================================================================== --- lib/Analysis/InlineCost.cpp +++ lib/Analysis/InlineCost.cpp @@ -717,7 +717,7 @@ // if we know the value (argument) can't be null if (I.isEquality() && isa(I.getOperand(1)) && isKnownNonNullInCallee(I.getOperand(0))) { - bool IsNotEqual = I.getPredicate() == CmpInst::ICMP_NE; + bool IsNotEqual = I.getPredicate() == Predicate::ICMP_NE; SimplifiedValues[&I] = IsNotEqual ? ConstantInt::getTrue(I.getType()) : ConstantInt::getFalse(I.getType()); return true; Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -65,7 +65,7 @@ unsigned); static Value *SimplifyFPBinOp(unsigned, Value *, Value *, const FastMathFlags &, const Query &, unsigned); -static Value *SimplifyCmpInst(unsigned, Value *, Value *, const Query &, +static Value *SimplifyCmpInst(Predicate, Value *, Value *, const Query &, unsigned); static Value *SimplifyOrInst(Value *, Value *, const Query &, unsigned); static Value *SimplifyXorInst(Value *, Value *, const Query &, unsigned); @@ -89,17 +89,15 @@ } /// isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"? -static bool isSameCompare(Value *V, CmpInst::Predicate Pred, Value *LHS, - Value *RHS) { +static bool isSameCompare(Value *V, Predicate Pred, Value *LHS, Value *RHS) { CmpInst *Cmp = dyn_cast(V); if (!Cmp) return false; - CmpInst::Predicate CPred = Cmp->getPredicate(); + Predicate CPred = Cmp->getPredicate(); Value *CLHS = Cmp->getOperand(0), *CRHS = Cmp->getOperand(1); if (CPred == Pred && CLHS == LHS && CRHS == RHS) return true; - return CPred == CmpInst::getSwappedPredicate(Pred) && CLHS == RHS && - CRHS == LHS; + return CPred == Pred.getSwapped() && CLHS == RHS && CRHS == LHS; } /// Does the given value dominate the specified phi node? @@ -367,9 +365,8 @@ /// In the case of a comparison with a select instruction, try to simplify the /// comparison by seeing whether both branches of the select result in the same /// value. Returns the common value if so, otherwise returns null. -static Value *ThreadCmpOverSelect(CmpInst::Predicate Pred, Value *LHS, - Value *RHS, const Query &Q, - unsigned MaxRecurse) { +static Value *ThreadCmpOverSelect(Predicate Pred, Value *LHS, Value *RHS, + const Query &Q, unsigned MaxRecurse) { // Recursion is always used, so bail out at once if we already hit the limit. if (!MaxRecurse--) return nullptr; @@ -377,7 +374,7 @@ // Make sure the select is on the LHS. if (!isa(LHS)) { std::swap(LHS, RHS); - Pred = CmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); } assert(isa(LHS) && "Not comparing with a select instruction!"); SelectInst *SI = cast(LHS); @@ -491,7 +488,7 @@ /// comparison by seeing whether comparing with all of the incoming phi values /// yields the same result every time. If so returns the common result, /// otherwise returns null. -static Value *ThreadCmpOverPHI(CmpInst::Predicate Pred, Value *LHS, Value *RHS, +static Value *ThreadCmpOverPHI(Predicate Pred, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse) { // Recursion is always used, so bail out at once if we already hit the limit. if (!MaxRecurse--) @@ -500,7 +497,7 @@ // Make sure the phi is on the LHS. if (!isa(LHS)) { std::swap(LHS, RHS); - Pred = CmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); } assert(isa(LHS) && "Not comparing with a phi instruction!"); PHINode *PI = cast(LHS); @@ -1462,37 +1459,37 @@ ICmpInst *UnsignedICmp, bool IsAnd) { Value *X, *Y; - ICmpInst::Predicate EqPred; + Predicate EqPred; if (!match(ZeroICmp, m_ICmp(EqPred, m_Value(Y), m_Zero())) || - !ICmpInst::isEquality(EqPred)) + !EqPred.isEquality()) return nullptr; - ICmpInst::Predicate UnsignedPred; + Predicate UnsignedPred; if (match(UnsignedICmp, m_ICmp(UnsignedPred, m_Value(X), m_Specific(Y))) && - ICmpInst::isUnsigned(UnsignedPred)) + UnsignedPred.isUnsigned()) ; else if (match(UnsignedICmp, m_ICmp(UnsignedPred, m_Value(Y), m_Specific(X))) && - ICmpInst::isUnsigned(UnsignedPred)) - UnsignedPred = ICmpInst::getSwappedPredicate(UnsignedPred); + UnsignedPred.isUnsigned()) + UnsignedPred = UnsignedPred.getSwapped(); else return nullptr; // X < Y && Y != 0 --> X < Y // X < Y || Y != 0 --> Y != 0 - if (UnsignedPred == ICmpInst::ICMP_ULT && EqPred == ICmpInst::ICMP_NE) + if (UnsignedPred == Predicate::ICMP_ULT && EqPred == Predicate::ICMP_NE) return IsAnd ? UnsignedICmp : ZeroICmp; // X >= Y || Y != 0 --> true // X >= Y || Y == 0 --> X >= Y - if (UnsignedPred == ICmpInst::ICMP_UGE && !IsAnd) { - if (EqPred == ICmpInst::ICMP_NE) + if (UnsignedPred == Predicate::ICMP_UGE && !IsAnd) { + if (EqPred == Predicate::ICMP_NE) return getTrue(UnsignedICmp->getType()); return UnsignedICmp; } // X < Y && Y == 0 --> false - if (UnsignedPred == ICmpInst::ICMP_ULT && EqPred == ICmpInst::ICMP_EQ && + if (UnsignedPred == Predicate::ICMP_ULT && EqPred == Predicate::ICMP_EQ && IsAnd) return getFalse(UnsignedICmp->getType()); @@ -1501,7 +1498,7 @@ static Value *SimplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1) { Type *ITy = Op0->getType(); - ICmpInst::Predicate Pred0, Pred1; + Predicate Pred0, Pred1; ConstantInt *CI1, *CI2; Value *V; @@ -1536,24 +1533,24 @@ const APInt Delta = CI2V - CI1V; if (CI1V.isStrictlyPositive()) { if (Delta == 2) { - if (Pred0 == ICmpInst::ICMP_ULT && Pred1 == ICmpInst::ICMP_SGT) + if (Pred0 == Predicate::ICMP_ULT && Pred1 == Predicate::ICMP_SGT) return getFalse(ITy); - if (Pred0 == ICmpInst::ICMP_SLT && Pred1 == ICmpInst::ICMP_SGT && isNSW) + if (Pred0 == Predicate::ICMP_SLT && Pred1 == Predicate::ICMP_SGT && isNSW) return getFalse(ITy); } if (Delta == 1) { - if (Pred0 == ICmpInst::ICMP_ULE && Pred1 == ICmpInst::ICMP_SGT) + if (Pred0 == Predicate::ICMP_ULE && Pred1 == Predicate::ICMP_SGT) return getFalse(ITy); - if (Pred0 == ICmpInst::ICMP_SLE && Pred1 == ICmpInst::ICMP_SGT && isNSW) + if (Pred0 == Predicate::ICMP_SLE && Pred1 == Predicate::ICMP_SGT && isNSW) return getFalse(ITy); } } if (CI1V.getBoolValue() && isNUW) { if (Delta == 2) - if (Pred0 == ICmpInst::ICMP_ULT && Pred1 == ICmpInst::ICMP_UGT) + if (Pred0 == Predicate::ICMP_ULT && Pred1 == Predicate::ICMP_UGT) return getFalse(ITy); if (Delta == 1) - if (Pred0 == ICmpInst::ICMP_ULE && Pred1 == ICmpInst::ICMP_UGT) + if (Pred0 == Predicate::ICMP_ULE && Pred1 == Predicate::ICMP_UGT) return getFalse(ITy); } @@ -1685,7 +1682,7 @@ /// Simplify (or (icmp ...) (icmp ...)) to true when we can tell that the union /// contains all possible values. static Value *SimplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1) { - ICmpInst::Predicate Pred0, Pred1; + Predicate Pred0, Pred1; ConstantInt *CI1, *CI2; Value *V; @@ -1710,24 +1707,24 @@ const APInt Delta = CI2V - CI1V; if (CI1V.isStrictlyPositive()) { if (Delta == 2) { - if (Pred0 == ICmpInst::ICMP_UGE && Pred1 == ICmpInst::ICMP_SLE) + if (Pred0 == Predicate::ICMP_UGE && Pred1 == Predicate::ICMP_SLE) return getTrue(ITy); - if (Pred0 == ICmpInst::ICMP_SGE && Pred1 == ICmpInst::ICMP_SLE && isNSW) + if (Pred0 == Predicate::ICMP_SGE && Pred1 == Predicate::ICMP_SLE && isNSW) return getTrue(ITy); } if (Delta == 1) { - if (Pred0 == ICmpInst::ICMP_UGT && Pred1 == ICmpInst::ICMP_SLE) + if (Pred0 == Predicate::ICMP_UGT && Pred1 == Predicate::ICMP_SLE) return getTrue(ITy); - if (Pred0 == ICmpInst::ICMP_SGT && Pred1 == ICmpInst::ICMP_SLE && isNSW) + if (Pred0 == Predicate::ICMP_SGT && Pred1 == Predicate::ICMP_SLE && isNSW) return getTrue(ITy); } } if (CI1V.getBoolValue() && isNUW) { if (Delta == 2) - if (Pred0 == ICmpInst::ICMP_UGE && Pred1 == ICmpInst::ICMP_ULE) + if (Pred0 == Predicate::ICMP_UGE && Pred1 == Predicate::ICMP_ULE) return getTrue(ITy); if (Delta == 1) - if (Pred0 == ICmpInst::ICMP_UGT && Pred1 == ICmpInst::ICMP_ULE) + if (Pred0 == Predicate::ICMP_UGT && Pred1 == Predicate::ICMP_ULE) return getTrue(ITy); } @@ -1928,8 +1925,8 @@ /// Rummage around inside V looking for something equivalent to the comparison /// "LHS Pred RHS". Return such a value if found, otherwise return null. /// Helper function for analyzing max/min idioms. -static Value *ExtractEquivalentCondition(Value *V, CmpInst::Predicate Pred, - Value *LHS, Value *RHS) { +static Value *ExtractEquivalentCondition(Value *V, Predicate Pred, Value *LHS, + Value *RHS) { SelectInst *SI = dyn_cast(V); if (!SI) return nullptr; @@ -1939,8 +1936,8 @@ Value *CmpLHS = Cmp->getOperand(0), *CmpRHS = Cmp->getOperand(1); if (Pred == Cmp->getPredicate() && LHS == CmpLHS && RHS == CmpRHS) return Cmp; - if (Pred == CmpInst::getSwappedPredicate(Cmp->getPredicate()) && - LHS == CmpRHS && RHS == CmpLHS) + if (Pred == Cmp->getPredicate().getSwapped() && LHS == CmpRHS && + RHS == CmpLHS) return Cmp; return nullptr; } @@ -1973,39 +1970,39 @@ // If the C and C++ standards are ever made sufficiently restrictive in this // area, it may be possible to update LLVM's semantics accordingly and reinstate // this optimization. -static Constant * -computePointerICmp(const DataLayout &DL, const TargetLibraryInfo *TLI, - const DominatorTree *DT, CmpInst::Predicate Pred, - const Instruction *CxtI, Value *LHS, Value *RHS) { +static Constant *computePointerICmp(const DataLayout &DL, + const TargetLibraryInfo *TLI, + const DominatorTree *DT, Predicate Pred, + const Instruction *CxtI, Value *LHS, + Value *RHS) { // First, skip past any trivial no-ops. LHS = LHS->stripPointerCasts(); RHS = RHS->stripPointerCasts(); // A non-null pointer is not equal to a null pointer. if (llvm::isKnownNonNull(LHS) && isa(RHS) && - (Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE)) - return ConstantInt::get(GetCompareTy(LHS), - !CmpInst::isTrueWhenEqual(Pred)); + (Pred == Predicate::ICMP_EQ || Pred == Predicate::ICMP_NE)) + return ConstantInt::get(GetCompareTy(LHS), !Pred.isTrueWhenEqual()); // We can only fold certain predicates on pointer comparisons. - switch (Pred) { + switch (Pred.getKind()) { default: return nullptr; // Equality comaprisons are easy to fold. - case CmpInst::ICMP_EQ: - case CmpInst::ICMP_NE: + case Predicate::ICMP_EQ: + case Predicate::ICMP_NE: break; // We can only handle unsigned relational comparisons because 'inbounds' on // a GEP only protects against unsigned wrapping. - case CmpInst::ICMP_UGT: - case CmpInst::ICMP_UGE: - case CmpInst::ICMP_ULT: - case CmpInst::ICMP_ULE: + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: // However, we have to switch them to their signed variants to handle // negative indices from the base pointer. - Pred = ICmpInst::getSignedPredicate(Pred); + Pred = Pred.getSigned(); break; } @@ -2024,7 +2021,7 @@ return ConstantExpr::getICmp(Pred, LHSOffset, RHSOffset); // Various optimizations for (in)equality comparisons. - if (Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE) { + if (Pred == Predicate::ICMP_EQ || Pred == Predicate::ICMP_NE) { // Different non-empty allocations that exist at the same time have // different addresses (if the program can tell). Global variables always // exist, so they always exist during the lifetime of each other and all @@ -2068,8 +2065,7 @@ !RHSOffsetValue.isNegative() && LHSOffsetValue.ult(LHSSize) && RHSOffsetValue.ult(RHSSize)) { - return ConstantInt::get(GetCompareTy(LHS), - !CmpInst::isTrueWhenEqual(Pred)); + return ConstantInt::get(GetCompareTy(LHS), !Pred.isTrueWhenEqual()); } } @@ -2079,8 +2075,7 @@ !cast(RHS->getType())->isEmptyTy() && LHSOffset->isNullValue() && RHSOffset->isNullValue()) - return ConstantInt::get(GetCompareTy(LHS), - !CmpInst::isTrueWhenEqual(Pred)); + return ConstantInt::get(GetCompareTy(LHS), !Pred.isTrueWhenEqual()); } // Even if an non-inbounds GEP occurs along the path we can still optimize @@ -2130,8 +2125,7 @@ if ((IsNAC(LHSUObjs) && IsAllocDisjoint(RHSUObjs)) || (IsNAC(RHSUObjs) && IsAllocDisjoint(LHSUObjs))) - return ConstantInt::get(GetCompareTy(LHS), - !CmpInst::isTrueWhenEqual(Pred)); + return ConstantInt::get(GetCompareTy(LHS), !Pred.isTrueWhenEqual()); // Fold comparisons for non-escaping pointer even if the allocation call // cannot be elided. We cannot fold malloc comparison to null. Also, the @@ -2144,8 +2138,7 @@ // FIXME: We should also fold the compare when the pointer escapes, but the // compare dominates the pointer escape if (MI && !PointerMayBeCaptured(MI, true, true)) - return ConstantInt::get(GetCompareTy(LHS), - CmpInst::isFalseWhenEqual(Pred)); + return ConstantInt::get(GetCompareTy(LHS), Pred.isFalseWhenEqual()); } // Otherwise, fail. @@ -2154,10 +2147,9 @@ /// Given operands for an ICmpInst, see if we can fold the result. /// If not, this returns null. -static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, +static Value *SimplifyICmpInst(Predicate Pred, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse) { - CmpInst::Predicate Pred = (CmpInst::Predicate)Predicate; - assert(CmpInst::isIntPredicate(Pred) && "Not an integer compare!"); + assert(Pred.isInt() && "Not an integer compare!"); if (Constant *CLHS = dyn_cast(LHS)) { if (Constant *CRHS = dyn_cast(RHS)) @@ -2165,7 +2157,7 @@ // If we have a constant, make sure it is on the RHS. std::swap(LHS, RHS); - Pred = CmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); } Type *ITy = GetCompareTy(LHS); // The return type. @@ -2175,28 +2167,28 @@ // X icmp undef -> true/false. For example, icmp ugt %X, undef -> false // because X could be 0. if (LHS == RHS || isa(RHS)) - return ConstantInt::get(ITy, CmpInst::isTrueWhenEqual(Pred)); + return ConstantInt::get(ITy, Pred.isTrueWhenEqual()); // Special case logic when the operands have i1 type. if (OpTy->getScalarType()->isIntegerTy(1)) { - switch (Pred) { + switch (Pred.getKind()) { default: break; - case ICmpInst::ICMP_EQ: + case Predicate::ICMP_EQ: // X == 1 -> X if (match(RHS, m_One())) return LHS; break; - case ICmpInst::ICMP_NE: + case Predicate::ICMP_NE: // X != 0 -> X if (match(RHS, m_Zero())) return LHS; break; - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_UGT: // X >u 0 -> X if (match(RHS, m_Zero())) return LHS; break; - case ICmpInst::ICMP_UGE: { + case Predicate::ICMP_UGE: { // X >=u 1 -> X if (match(RHS, m_One())) return LHS; @@ -2204,7 +2196,7 @@ return getTrue(ITy); break; } - case ICmpInst::ICMP_SGE: { + case Predicate::ICMP_SGE: { /// For signed comparison, the values for an i1 are 0 and -1 /// respectively. This maps into a truth table of: /// LHS | RHS | LHS >=s RHS | LHS implies RHS @@ -2216,17 +2208,17 @@ return getTrue(ITy); break; } - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: // X X if (match(RHS, m_Zero())) return LHS; break; - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLE: // X <=s -1 -> X if (match(RHS, m_One())) return LHS; break; - case ICmpInst::ICMP_ULE: { + case Predicate::ICMP_ULE: { if (isImpliedCondition(LHS, RHS, Q.DL).getValueOr(false)) return getTrue(ITy); break; @@ -2237,23 +2229,23 @@ // If we are comparing with zero then try hard since this is a common case. if (match(RHS, m_Zero())) { bool LHSKnownNonNegative, LHSKnownNegative; - switch (Pred) { + switch (Pred.getKind()) { default: llvm_unreachable("Unknown ICmp predicate!"); - case ICmpInst::ICMP_ULT: + case Predicate::ICMP_ULT: return getFalse(ITy); - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: return getTrue(ITy); - case ICmpInst::ICMP_EQ: - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_EQ: + case Predicate::ICMP_ULE: if (isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT)) return getFalse(ITy); break; - case ICmpInst::ICMP_NE: - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_NE: + case Predicate::ICMP_UGT: if (isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT)) return getTrue(ITy); break; - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (LHSKnownNegative) @@ -2261,7 +2253,7 @@ if (LHSKnownNonNegative) return getFalse(ITy); break; - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLE: ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (LHSKnownNegative) @@ -2270,7 +2262,7 @@ isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT)) return getFalse(ITy); break; - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (LHSKnownNegative) @@ -2278,7 +2270,7 @@ if (LHSKnownNonNegative) return getTrue(ITy); break; - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (LHSKnownNegative) @@ -2441,8 +2433,8 @@ if (Satisfied_CR.contains(LHS_CR)) return ConstantInt::getTrue(RHS->getContext()); - auto InversedSatisfied_CR = ConstantRange::makeSatisfyingICmpRegion( - CmpInst::getInversePredicate(Pred), RHS_CR); + auto InversedSatisfied_CR = + ConstantRange::makeSatisfyingICmpRegion(Pred.getInverse(), RHS_CR); if (InversedSatisfied_CR.contains(LHS_CR)) return ConstantInt::getFalse(RHS->getContext()); } @@ -2480,9 +2472,8 @@ if (ZExtInst *RI = dyn_cast(RHS)) { if (MaxRecurse && SrcTy == RI->getOperand(0)->getType()) // Compare X and Y. Note that signed predicates become unsigned. - if (Value *V = SimplifyICmpInst(ICmpInst::getUnsignedPredicate(Pred), - SrcOp, RI->getOperand(0), Q, - MaxRecurse-1)) + if (Value *V = SimplifyICmpInst(Pred.getUnsigned(), SrcOp, + RI->getOperand(0), Q, MaxRecurse - 1)) return V; } // Turn icmp (zext X), Cst into a compare of X and Cst if Cst is extended @@ -2496,36 +2487,36 @@ // If the re-extended constant didn't change then this is effectively // also a case of comparing two zero-extended values. if (RExt == CI && MaxRecurse) - if (Value *V = SimplifyICmpInst(ICmpInst::getUnsignedPredicate(Pred), - SrcOp, Trunc, Q, MaxRecurse-1)) + if (Value *V = SimplifyICmpInst(Pred.getUnsigned(), SrcOp, Trunc, Q, + MaxRecurse - 1)) return V; // Otherwise the upper bits of LHS are zero while RHS has a non-zero bit // there. Use this to work out the result of the comparison. if (RExt != CI) { - switch (Pred) { + switch (Pred.getKind()) { default: llvm_unreachable("Unknown ICmp predicate!"); // LHS getContext()); - case ICmpInst::ICMP_NE: - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_NE: + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: return ConstantInt::getTrue(CI->getContext()); // LHS is non-negative. If RHS is negative then LHS >s LHS. If RHS // is non-negative then LHS getValue().isNegative() ? ConstantInt::getTrue(CI->getContext()) : ConstantInt::getFalse(CI->getContext()); - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: return CI->getValue().isNegative() ? ConstantInt::getFalse(CI->getContext()) : ConstantInt::getTrue(CI->getContext()); @@ -2561,44 +2552,44 @@ // Otherwise the upper bits of LHS are all equal, while RHS has varying // bits there. Use this to work out the result of the comparison. if (RExt != CI) { - switch (Pred) { + switch (Pred.getKind()) { default: llvm_unreachable("Unknown ICmp predicate!"); - case ICmpInst::ICMP_EQ: + case Predicate::ICMP_EQ: return ConstantInt::getFalse(CI->getContext()); - case ICmpInst::ICMP_NE: + case Predicate::ICMP_NE: return ConstantInt::getTrue(CI->getContext()); // If RHS is non-negative then LHS s RHS. - case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGT: + case Predicate::ICMP_SGE: return CI->getValue().isNegative() ? ConstantInt::getTrue(CI->getContext()) : ConstantInt::getFalse(CI->getContext()); - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: return CI->getValue().isNegative() ? ConstantInt::getFalse(CI->getContext()) : ConstantInt::getTrue(CI->getContext()); // If LHS is non-negative then LHS u RHS. - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: // Comparison is true iff the LHS =s 0. if (MaxRecurse) - if (Value *V = SimplifyICmpInst(ICmpInst::ICMP_SGE, SrcOp, - Constant::getNullValue(SrcTy), - Q, MaxRecurse-1)) + if (Value *V = SimplifyICmpInst(Predicate::ICMP_SGE, SrcOp, + Constant::getNullValue(SrcTy), Q, + MaxRecurse - 1)) return V; break; } @@ -2608,11 +2599,11 @@ } // icmp eq|ne X, Y -> false|true if X != Y - if ((Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE) && + if ((Pred == Predicate::ICMP_EQ || Pred == Predicate::ICMP_NE) && isKnownNonEqual(LHS, RHS, Q.DL, Q.AC, Q.CxtI, Q.DT)) { LLVMContext &Ctx = LHS->getType()->getContext(); - return Pred == ICmpInst::ICMP_NE ? - ConstantInt::getTrue(Ctx) : ConstantInt::getFalse(Ctx); + return Pred == Predicate::ICMP_NE ? ConstantInt::getTrue(Ctx) + : ConstantInt::getFalse(Ctx); } // Special logic for binary operators. @@ -2625,15 +2616,15 @@ bool NoLHSWrapProblem = false, NoRHSWrapProblem = false; if (LBO && LBO->getOpcode() == Instruction::Add) { A = LBO->getOperand(0); B = LBO->getOperand(1); - NoLHSWrapProblem = ICmpInst::isEquality(Pred) || - (CmpInst::isUnsigned(Pred) && LBO->hasNoUnsignedWrap()) || - (CmpInst::isSigned(Pred) && LBO->hasNoSignedWrap()); + NoLHSWrapProblem = Pred.isEquality() || + (Pred.isUnsigned() && LBO->hasNoUnsignedWrap()) || + (Pred.isSigned() && LBO->hasNoSignedWrap()); } if (RBO && RBO->getOpcode() == Instruction::Add) { C = RBO->getOperand(0); D = RBO->getOperand(1); - NoRHSWrapProblem = ICmpInst::isEquality(Pred) || - (CmpInst::isUnsigned(Pred) && RBO->hasNoUnsignedWrap()) || - (CmpInst::isSigned(Pred) && RBO->hasNoSignedWrap()); + NoRHSWrapProblem = Pred.isEquality() || + (Pred.isUnsigned() && RBO->hasNoUnsignedWrap()) || + (Pred.isSigned() && RBO->hasNoSignedWrap()); } // icmp (X+Y), X -> icmp Y, 0 for equalities or if there is no overflow. @@ -2682,12 +2673,12 @@ Value *Y = nullptr; // icmp pred (or X, Y), X if (LBO && match(LBO, m_c_Or(m_Value(Y), m_Specific(RHS)))) { - if (Pred == ICmpInst::ICMP_ULT) + if (Pred == Predicate::ICMP_ULT) return getFalse(ITy); - if (Pred == ICmpInst::ICMP_UGE) + if (Pred == Predicate::ICMP_UGE) return getTrue(ITy); - if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SGE) { + if (Pred == Predicate::ICMP_SLT || Pred == Predicate::ICMP_SGE) { bool RHSKnownNonNegative, RHSKnownNegative; bool YKnownNonNegative, YKnownNegative; ComputeSignBit(RHS, RHSKnownNonNegative, RHSKnownNegative, Q.DL, 0, @@ -2695,19 +2686,19 @@ ComputeSignBit(Y, YKnownNonNegative, YKnownNegative, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (RHSKnownNonNegative && YKnownNegative) - return Pred == ICmpInst::ICMP_SLT ? getTrue(ITy) : getFalse(ITy); + return Pred == Predicate::ICMP_SLT ? getTrue(ITy) : getFalse(ITy); if (RHSKnownNegative || YKnownNonNegative) - return Pred == ICmpInst::ICMP_SLT ? getFalse(ITy) : getTrue(ITy); + return Pred == Predicate::ICMP_SLT ? getFalse(ITy) : getTrue(ITy); } } // icmp pred X, (or X, Y) if (RBO && match(RBO, m_c_Or(m_Value(Y), m_Specific(LHS)))) { - if (Pred == ICmpInst::ICMP_ULE) + if (Pred == Predicate::ICMP_ULE) return getTrue(ITy); - if (Pred == ICmpInst::ICMP_UGT) + if (Pred == Predicate::ICMP_UGT) return getFalse(ITy); - if (Pred == ICmpInst::ICMP_SGT || Pred == ICmpInst::ICMP_SLE) { + if (Pred == Predicate::ICMP_SGT || Pred == Predicate::ICMP_SLE) { bool LHSKnownNonNegative, LHSKnownNegative; bool YKnownNonNegative, YKnownNegative; ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, @@ -2715,9 +2706,9 @@ ComputeSignBit(Y, YKnownNonNegative, YKnownNegative, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (LHSKnownNonNegative && YKnownNegative) - return Pred == ICmpInst::ICMP_SGT ? getTrue(ITy) : getFalse(ITy); + return Pred == Predicate::ICMP_SGT ? getTrue(ITy) : getFalse(ITy); if (LHSKnownNegative || YKnownNonNegative) - return Pred == ICmpInst::ICMP_SGT ? getFalse(ITy) : getTrue(ITy); + return Pred == Predicate::ICMP_SGT ? getFalse(ITy) : getTrue(ITy); } } } @@ -2725,37 +2716,37 @@ // icmp pred (and X, Y), X if (LBO && match(LBO, m_CombineOr(m_And(m_Value(), m_Specific(RHS)), m_And(m_Specific(RHS), m_Value())))) { - if (Pred == ICmpInst::ICMP_UGT) + if (Pred == Predicate::ICMP_UGT) return getFalse(ITy); - if (Pred == ICmpInst::ICMP_ULE) + if (Pred == Predicate::ICMP_ULE) return getTrue(ITy); } // icmp pred X, (and X, Y) if (RBO && match(RBO, m_CombineOr(m_And(m_Value(), m_Specific(LHS)), m_And(m_Specific(LHS), m_Value())))) { - if (Pred == ICmpInst::ICMP_UGE) + if (Pred == Predicate::ICMP_UGE) return getTrue(ITy); - if (Pred == ICmpInst::ICMP_ULT) + if (Pred == Predicate::ICMP_ULT) return getFalse(ITy); } // 0 - (zext X) pred C - if (!CmpInst::isUnsigned(Pred) && match(LHS, m_Neg(m_ZExt(m_Value())))) { + if (!Pred.isUnsigned() && match(LHS, m_Neg(m_ZExt(m_Value())))) { if (ConstantInt *RHSC = dyn_cast(RHS)) { if (RHSC->getValue().isStrictlyPositive()) { - if (Pred == ICmpInst::ICMP_SLT) + if (Pred == Predicate::ICMP_SLT) return ConstantInt::getTrue(RHSC->getContext()); - if (Pred == ICmpInst::ICMP_SGE) + if (Pred == Predicate::ICMP_SGE) return ConstantInt::getFalse(RHSC->getContext()); - if (Pred == ICmpInst::ICMP_EQ) + if (Pred == Predicate::ICMP_EQ) return ConstantInt::getFalse(RHSC->getContext()); - if (Pred == ICmpInst::ICMP_NE) + if (Pred == Predicate::ICMP_NE) return ConstantInt::getTrue(RHSC->getContext()); } if (RHSC->getValue().isNonNegative()) { - if (Pred == ICmpInst::ICMP_SLE) + if (Pred == Predicate::ICMP_SLE) return ConstantInt::getTrue(RHSC->getContext()); - if (Pred == ICmpInst::ICMP_SGT) + if (Pred == Predicate::ICMP_SGT) return ConstantInt::getFalse(RHSC->getContext()); } } @@ -2764,30 +2755,30 @@ // icmp pred (urem X, Y), Y if (LBO && match(LBO, m_URem(m_Value(), m_Specific(RHS)))) { bool KnownNonNegative, KnownNegative; - switch (Pred) { + switch (Pred.getKind()) { default: break; - case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGT: + case Predicate::ICMP_SGE: ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (!KnownNonNegative) break; // fall-through - case ICmpInst::ICMP_EQ: - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_EQ: + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: return getFalse(ITy); - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (!KnownNonNegative) break; // fall-through - case ICmpInst::ICMP_NE: - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_NE: + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: return getTrue(ITy); } } @@ -2795,30 +2786,30 @@ // icmp pred X, (urem Y, X) if (RBO && match(RBO, m_URem(m_Value(), m_Specific(LHS)))) { bool KnownNonNegative, KnownNegative; - switch (Pred) { + switch (Pred.getKind()) { default: break; - case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGT: + case Predicate::ICMP_SGE: ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (!KnownNonNegative) break; // fall-through - case ICmpInst::ICMP_NE: - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_NE: + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: return getTrue(ITy); - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (!KnownNonNegative) break; // fall-through - case ICmpInst::ICMP_EQ: - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_EQ: + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: return getFalse(ITy); } } @@ -2828,9 +2819,9 @@ if (LBO && (match(LBO, m_LShr(m_Specific(RHS), m_Value())) || match(LBO, m_UDiv(m_Specific(RHS), m_Value())))) { // icmp pred (X op Y), X - if (Pred == ICmpInst::ICMP_UGT) + if (Pred == Predicate::ICMP_UGT) return getFalse(ITy); - if (Pred == ICmpInst::ICMP_ULE) + if (Pred == Predicate::ICMP_ULE) return getTrue(ITy); } @@ -2854,16 +2845,16 @@ // - CI isn't zero if (LBO->hasNoSignedWrap() || LBO->hasNoUnsignedWrap() || *CI2Val == 1 || !CI->isZero()) { - if (Pred == ICmpInst::ICMP_EQ) + if (Pred == Predicate::ICMP_EQ) return ConstantInt::getFalse(RHS->getContext()); - if (Pred == ICmpInst::ICMP_NE) + if (Pred == Predicate::ICMP_NE) return ConstantInt::getTrue(RHS->getContext()); } } if (CIVal->isSignBit() && *CI2Val == 1) { - if (Pred == ICmpInst::ICMP_UGT) + if (Pred == Predicate::ICMP_UGT) return ConstantInt::getFalse(RHS->getContext()); - if (Pred == ICmpInst::ICMP_ULE) + if (Pred == Predicate::ICMP_ULE) return ConstantInt::getTrue(RHS->getContext()); } } @@ -2875,7 +2866,7 @@ default: break; case Instruction::UDiv: case Instruction::LShr: - if (ICmpInst::isSigned(Pred)) + if (Pred.isSigned()) break; // fall-through case Instruction::SDiv: @@ -2891,7 +2882,7 @@ bool NSW = LBO->hasNoSignedWrap() && RBO->hasNoSignedWrap(); if (!NUW && !NSW) break; - if (!NSW && ICmpInst::isSigned(Pred)) + if (!NSW && Pred.isSigned()) break; if (Value *V = SimplifyICmpInst(Pred, LBO->getOperand(0), RBO->getOperand(0), Q, MaxRecurse-1)) @@ -2903,43 +2894,43 @@ // Simplify comparisons involving max/min. Value *A, *B; - CmpInst::Predicate P = CmpInst::BAD_ICMP_PREDICATE; - CmpInst::Predicate EqP; // Chosen so that "A == max/min(A,B)" iff "A EqP B". + Predicate P = Predicate::BAD_ICMP_PREDICATE; + Predicate EqP; // Chosen so that "A == max/min(A,B)" iff "A EqP B". // Signed variants on "max(a,b)>=a -> true". if (match(LHS, m_SMax(m_Value(A), m_Value(B))) && (A == RHS || B == RHS)) { if (A != RHS) std::swap(A, B); // smax(A, B) pred A. - EqP = CmpInst::ICMP_SGE; // "A == smax(A, B)" iff "A sge B". + EqP = Predicate::ICMP_SGE; // "A == smax(A, B)" iff "A sge B". // We analyze this as smax(A, B) pred A. P = Pred; } else if (match(RHS, m_SMax(m_Value(A), m_Value(B))) && (A == LHS || B == LHS)) { if (A != LHS) std::swap(A, B); // A pred smax(A, B). - EqP = CmpInst::ICMP_SGE; // "A == smax(A, B)" iff "A sge B". + EqP = Predicate::ICMP_SGE; // "A == smax(A, B)" iff "A sge B". // We analyze this as smax(A, B) swapped-pred A. - P = CmpInst::getSwappedPredicate(Pred); + P = Pred.getSwapped(); } else if (match(LHS, m_SMin(m_Value(A), m_Value(B))) && (A == RHS || B == RHS)) { if (A != RHS) std::swap(A, B); // smin(A, B) pred A. - EqP = CmpInst::ICMP_SLE; // "A == smin(A, B)" iff "A sle B". + EqP = Predicate::ICMP_SLE; // "A == smin(A, B)" iff "A sle B". // We analyze this as smax(-A, -B) swapped-pred -A. // Note that we do not need to actually form -A or -B thanks to EqP. - P = CmpInst::getSwappedPredicate(Pred); + P = Pred.getSwapped(); } else if (match(RHS, m_SMin(m_Value(A), m_Value(B))) && (A == LHS || B == LHS)) { if (A != LHS) std::swap(A, B); // A pred smin(A, B). - EqP = CmpInst::ICMP_SLE; // "A == smin(A, B)" iff "A sle B". + EqP = Predicate::ICMP_SLE; // "A == smin(A, B)" iff "A sle B". // We analyze this as smax(-A, -B) pred -A. // Note that we do not need to actually form -A or -B thanks to EqP. P = Pred; } - if (P != CmpInst::BAD_ICMP_PREDICATE) { + if (P != Predicate::BAD_ICMP_PREDICATE) { // Cases correspond to "max(A, B) p A". - switch (P) { + switch (P.getKind()) { default: break; - case CmpInst::ICMP_EQ: - case CmpInst::ICMP_SLE: + case Predicate::ICMP_EQ: + case Predicate::ICMP_SLE: // Equivalent to "A EqP B". This may be the same as the condition tested // in the max/min; if so, we can just return that. if (Value *V = ExtractEquivalentCondition(LHS, EqP, A, B)) @@ -2951,9 +2942,9 @@ if (Value *V = SimplifyICmpInst(EqP, A, B, Q, MaxRecurse-1)) return V; break; - case CmpInst::ICMP_NE: - case CmpInst::ICMP_SGT: { - CmpInst::Predicate InvEqP = CmpInst::getInversePredicate(EqP); + case Predicate::ICMP_NE: + case Predicate::ICMP_SGT: { + Predicate InvEqP = EqP.getInverse(); // Equivalent to "A InvEqP B". This may be the same as the condition // tested in the max/min; if so, we can just return that. if (Value *V = ExtractEquivalentCondition(LHS, InvEqP, A, B)) @@ -2966,50 +2957,50 @@ return V; break; } - case CmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: // Always true. return getTrue(ITy); - case CmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: // Always false. return getFalse(ITy); } } // Unsigned variants on "max(a,b)>=a -> true". - P = CmpInst::BAD_ICMP_PREDICATE; + P = Predicate::BAD_ICMP_PREDICATE; if (match(LHS, m_UMax(m_Value(A), m_Value(B))) && (A == RHS || B == RHS)) { if (A != RHS) std::swap(A, B); // umax(A, B) pred A. - EqP = CmpInst::ICMP_UGE; // "A == umax(A, B)" iff "A uge B". + EqP = Predicate::ICMP_UGE; // "A == umax(A, B)" iff "A uge B". // We analyze this as umax(A, B) pred A. P = Pred; } else if (match(RHS, m_UMax(m_Value(A), m_Value(B))) && (A == LHS || B == LHS)) { if (A != LHS) std::swap(A, B); // A pred umax(A, B). - EqP = CmpInst::ICMP_UGE; // "A == umax(A, B)" iff "A uge B". + EqP = Predicate::ICMP_UGE; // "A == umax(A, B)" iff "A uge B". // We analyze this as umax(A, B) swapped-pred A. - P = CmpInst::getSwappedPredicate(Pred); + P = Pred.getSwapped(); } else if (match(LHS, m_UMin(m_Value(A), m_Value(B))) && (A == RHS || B == RHS)) { if (A != RHS) std::swap(A, B); // umin(A, B) pred A. - EqP = CmpInst::ICMP_ULE; // "A == umin(A, B)" iff "A ule B". + EqP = Predicate::ICMP_ULE; // "A == umin(A, B)" iff "A ule B". // We analyze this as umax(-A, -B) swapped-pred -A. // Note that we do not need to actually form -A or -B thanks to EqP. - P = CmpInst::getSwappedPredicate(Pred); + P = Pred.getSwapped(); } else if (match(RHS, m_UMin(m_Value(A), m_Value(B))) && (A == LHS || B == LHS)) { if (A != LHS) std::swap(A, B); // A pred umin(A, B). - EqP = CmpInst::ICMP_ULE; // "A == umin(A, B)" iff "A ule B". + EqP = Predicate::ICMP_ULE; // "A == umin(A, B)" iff "A ule B". // We analyze this as umax(-A, -B) pred -A. // Note that we do not need to actually form -A or -B thanks to EqP. P = Pred; } - if (P != CmpInst::BAD_ICMP_PREDICATE) { + if (P != Predicate::BAD_ICMP_PREDICATE) { // Cases correspond to "max(A, B) p A". - switch (P) { + switch (P.getKind()) { default: break; - case CmpInst::ICMP_EQ: - case CmpInst::ICMP_ULE: + case Predicate::ICMP_EQ: + case Predicate::ICMP_ULE: // Equivalent to "A EqP B". This may be the same as the condition tested // in the max/min; if so, we can just return that. if (Value *V = ExtractEquivalentCondition(LHS, EqP, A, B)) @@ -3021,9 +3012,9 @@ if (Value *V = SimplifyICmpInst(EqP, A, B, Q, MaxRecurse-1)) return V; break; - case CmpInst::ICMP_NE: - case CmpInst::ICMP_UGT: { - CmpInst::Predicate InvEqP = CmpInst::getInversePredicate(EqP); + case Predicate::ICMP_NE: + case Predicate::ICMP_UGT: { + Predicate InvEqP = EqP.getInverse(); // Equivalent to "A InvEqP B". This may be the same as the condition // tested in the max/min; if so, we can just return that. if (Value *V = ExtractEquivalentCondition(LHS, InvEqP, A, B)) @@ -3036,10 +3027,10 @@ return V; break; } - case CmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: // Always true. return getTrue(ITy); - case CmpInst::ICMP_ULT: + case Predicate::ICMP_ULT: // Always false. return getFalse(ITy); } @@ -3051,40 +3042,40 @@ match(RHS, m_SMin(m_Value(C), m_Value(D))) && (A == C || A == D || B == C || B == D)) { // max(x, ?) pred min(x, ?). - if (Pred == CmpInst::ICMP_SGE) + if (Pred == Predicate::ICMP_SGE) // Always true. return getTrue(ITy); - if (Pred == CmpInst::ICMP_SLT) + if (Pred == Predicate::ICMP_SLT) // Always false. return getFalse(ITy); } else if (match(LHS, m_SMin(m_Value(A), m_Value(B))) && match(RHS, m_SMax(m_Value(C), m_Value(D))) && (A == C || A == D || B == C || B == D)) { // min(x, ?) pred max(x, ?). - if (Pred == CmpInst::ICMP_SLE) + if (Pred == Predicate::ICMP_SLE) // Always true. return getTrue(ITy); - if (Pred == CmpInst::ICMP_SGT) + if (Pred == Predicate::ICMP_SGT) // Always false. return getFalse(ITy); } else if (match(LHS, m_UMax(m_Value(A), m_Value(B))) && match(RHS, m_UMin(m_Value(C), m_Value(D))) && (A == C || A == D || B == C || B == D)) { // max(x, ?) pred min(x, ?). - if (Pred == CmpInst::ICMP_UGE) + if (Pred == Predicate::ICMP_UGE) // Always true. return getTrue(ITy); - if (Pred == CmpInst::ICMP_ULT) + if (Pred == Predicate::ICMP_ULT) // Always false. return getFalse(ITy); } else if (match(LHS, m_UMin(m_Value(A), m_Value(B))) && match(RHS, m_UMax(m_Value(C), m_Value(D))) && (A == C || A == D || B == C || B == D)) { // min(x, ?) pred max(x, ?). - if (Pred == CmpInst::ICMP_ULE) + if (Pred == Predicate::ICMP_ULE) // Always true. return getTrue(ITy); - if (Pred == CmpInst::ICMP_UGT) + if (Pred == Predicate::ICMP_UGT) // Always false. return getFalse(ITy); } @@ -3109,9 +3100,8 @@ if (GEPOperator *GRHS = dyn_cast(RHS)) { if (GLHS->getPointerOperand() == GRHS->getPointerOperand() && GLHS->hasAllConstantIndices() && GRHS->hasAllConstantIndices() && - (ICmpInst::isEquality(Pred) || - (GLHS->isInBounds() && GRHS->isInBounds() && - Pred == ICmpInst::getSignedPredicate(Pred)))) { + (Pred.isEquality() || (GLHS->isInBounds() && GRHS->isInBounds() && + Pred == Pred.getSigned()))) { // The bases are equal and the indices are constant. Build a constant // expression GEP with the same indices and a null base pointer to see // what constant folding can make out of it. @@ -3130,7 +3120,7 @@ // If a bit is known to be zero for A and known to be one for B, // then A and B cannot be equal. - if (ICmpInst::isEquality(Pred)) { + if (Pred.isEquality()) { const APInt *RHSVal; if (match(RHS, m_APInt(RHSVal))) { unsigned BitWidth = RHSVal->getBitWidth(); @@ -3139,8 +3129,8 @@ computeKnownBits(LHS, LHSKnownZero, LHSKnownOne, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT); if (((LHSKnownZero & *RHSVal) != 0) || ((LHSKnownOne & ~(*RHSVal)) != 0)) - return Pred == ICmpInst::ICMP_EQ ? ConstantInt::getFalse(ITy) - : ConstantInt::getTrue(ITy); + return Pred == Predicate::ICMP_EQ ? ConstantInt::getFalse(ITy) + : ConstantInt::getTrue(ITy); } } @@ -3159,22 +3149,21 @@ return nullptr; } -Value *llvm::SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, +Value *llvm::SimplifyICmpInst(Predicate Pred, Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionCache *AC, const Instruction *CxtI) { - return ::SimplifyICmpInst(Predicate, LHS, RHS, Query(DL, TLI, DT, AC, CxtI), + return ::SimplifyICmpInst(Pred, LHS, RHS, Query(DL, TLI, DT, AC, CxtI), RecursionLimit); } /// Given operands for an FCmpInst, see if we can fold the result. /// If not, this returns null. -static Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, +static Value *SimplifyFCmpInst(Predicate Pred, Value *LHS, Value *RHS, FastMathFlags FMF, const Query &Q, unsigned MaxRecurse) { - CmpInst::Predicate Pred = (CmpInst::Predicate)Predicate; - assert(CmpInst::isFPPredicate(Pred) && "Not an FP compare!"); + assert(Pred.isFP() && "Not an FP compare!"); if (Constant *CLHS = dyn_cast(LHS)) { if (Constant *CRHS = dyn_cast(RHS)) @@ -3182,20 +3171,20 @@ // If we have a constant, make sure it is on the RHS. std::swap(LHS, RHS); - Pred = CmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); } // Fold trivial predicates. - if (Pred == FCmpInst::FCMP_FALSE) + if (Pred == Predicate::FCMP_FALSE) return ConstantInt::get(GetCompareTy(LHS), 0); - if (Pred == FCmpInst::FCMP_TRUE) + if (Pred == Predicate::FCMP_TRUE) return ConstantInt::get(GetCompareTy(LHS), 1); // UNO/ORD predicates can be trivially folded if NaNs are ignored. if (FMF.noNaNs()) { - if (Pred == FCmpInst::FCMP_UNO) + if (Pred == Predicate::FCMP_UNO) return ConstantInt::get(GetCompareTy(LHS), 0); - if (Pred == FCmpInst::FCMP_ORD) + if (Pred == Predicate::FCMP_ORD) return ConstantInt::get(GetCompareTy(LHS), 1); } @@ -3204,14 +3193,14 @@ if (isa(LHS) || isa(RHS)) { // Choosing NaN for the undef will always make unordered comparison succeed // and ordered comparison fail. - return ConstantInt::get(GetCompareTy(LHS), CmpInst::isUnordered(Pred)); + return ConstantInt::get(GetCompareTy(LHS), Pred.isUnordered()); } // fcmp x,x -> true/false. Not all compares are foldable. if (LHS == RHS) { - if (CmpInst::isTrueWhenEqual(Pred)) + if (Pred.isTrueWhenEqual()) return ConstantInt::get(GetCompareTy(LHS), 1); - if (CmpInst::isFalseWhenEqual(Pred)) + if (Pred.isFalseWhenEqual()) return ConstantInt::get(GetCompareTy(LHS), 0); } @@ -3226,9 +3215,9 @@ if (CFP) { // If the constant is a nan, see if we can fold the comparison based on it. if (CFP->getValueAPF().isNaN()) { - if (FCmpInst::isOrdered(Pred)) // True "if ordered and foo" + if (Pred.isOrdered()) // True "if ordered and foo" return ConstantInt::getFalse(CFP->getContext()); - assert(FCmpInst::isUnordered(Pred) && + assert(Pred.isUnordered() && "Comparison must be either ordered or unordered!"); // True if unordered. return ConstantInt::get(GetCompareTy(LHS), 1); @@ -3236,22 +3225,22 @@ // Check whether the constant is an infinity. if (CFP->getValueAPF().isInfinity()) { if (CFP->getValueAPF().isNegative()) { - switch (Pred) { - case FCmpInst::FCMP_OLT: + switch (Pred.getKind()) { + case Predicate::FCMP_OLT: // No value is ordered and less than negative infinity. return ConstantInt::get(GetCompareTy(LHS), 0); - case FCmpInst::FCMP_UGE: + case Predicate::FCMP_UGE: // All values are unordered with or at least negative infinity. return ConstantInt::get(GetCompareTy(LHS), 1); default: break; } } else { - switch (Pred) { - case FCmpInst::FCMP_OGT: + switch (Pred.getKind()) { + case Predicate::FCMP_OGT: // No value is ordered and greater than infinity. return ConstantInt::get(GetCompareTy(LHS), 0); - case FCmpInst::FCMP_ULE: + case Predicate::FCMP_ULE: // All values are unordered with and at most infinity. return ConstantInt::get(GetCompareTy(LHS), 1); default: @@ -3260,12 +3249,12 @@ } } if (CFP->getValueAPF().isZero()) { - switch (Pred) { - case FCmpInst::FCMP_UGE: + switch (Pred.getKind()) { + case Predicate::FCMP_UGE: if (CannotBeOrderedLessThanZero(LHS, Q.TLI)) return ConstantInt::get(GetCompareTy(LHS), 1); break; - case FCmpInst::FCMP_OLT: + case Predicate::FCMP_OLT: // X < 0 if (CannotBeOrderedLessThanZero(LHS, Q.TLI)) return ConstantInt::get(GetCompareTy(LHS), 0); @@ -3291,13 +3280,13 @@ return nullptr; } -Value *llvm::SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, +Value *llvm::SimplifyFCmpInst(Predicate Pred, Value *LHS, Value *RHS, FastMathFlags FMF, const DataLayout &DL, const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionCache *AC, const Instruction *CxtI) { - return ::SimplifyFCmpInst(Predicate, LHS, RHS, FMF, - Query(DL, TLI, DT, AC, CxtI), RecursionLimit); + return ::SimplifyFCmpInst(Pred, LHS, RHS, FMF, Query(DL, TLI, DT, AC, CxtI), + RecursionLimit); } /// See if V simplifies when its operand Op is replaced with RepOp. @@ -3452,26 +3441,26 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, Value *FalseVal, const Query &Q, unsigned MaxRecurse) { - ICmpInst::Predicate Pred; + Predicate Pred; Value *CmpLHS, *CmpRHS; if (!match(CondVal, m_ICmp(Pred, m_Value(CmpLHS), m_Value(CmpRHS)))) return nullptr; // FIXME: This code is nearly duplicated in InstCombine. Using/refactoring // decomposeBitTestICmp() might help. - if (ICmpInst::isEquality(Pred) && match(CmpRHS, m_Zero())) { + if (Pred.isEquality() && match(CmpRHS, m_Zero())) { Value *X; const APInt *Y; if (match(CmpLHS, m_And(m_Value(X), m_APInt(Y)))) if (Value *V = simplifySelectBitTest(TrueVal, FalseVal, X, Y, - Pred == ICmpInst::ICMP_EQ)) + Pred == Predicate::ICMP_EQ)) return V; - } else if (Pred == ICmpInst::ICMP_SLT && match(CmpRHS, m_Zero())) { + } else if (Pred == Predicate::ICMP_SLT && match(CmpRHS, m_Zero())) { // Comparing signed-less-than 0 checks if the sign bit is set. if (Value *V = simplifySelectWithFakeICmpEq(CmpLHS, TrueVal, FalseVal, false)) return V; - } else if (Pred == ICmpInst::ICMP_SGT && match(CmpRHS, m_AllOnes())) { + } else if (Pred == Predicate::ICMP_SGT && match(CmpRHS, m_AllOnes())) { // Comparing signed-greater-than -1 checks if the sign bit is not set. if (Value *V = simplifySelectWithFakeICmpEq(CmpLHS, TrueVal, FalseVal, true)) @@ -3482,16 +3471,16 @@ const APInt *C; if (match(CmpRHS, m_APInt(C))) { // X < MIN ? T : F --> F - if (Pred == ICmpInst::ICMP_SLT && C->isMinSignedValue()) + if (Pred == Predicate::ICMP_SLT && C->isMinSignedValue()) return FalseVal; // X < MIN ? T : F --> F - if (Pred == ICmpInst::ICMP_ULT && C->isMinValue()) + if (Pred == Predicate::ICMP_ULT && C->isMinValue()) return FalseVal; // X > MAX ? T : F --> F - if (Pred == ICmpInst::ICMP_SGT && C->isMaxSignedValue()) + if (Pred == Predicate::ICMP_SGT && C->isMaxSignedValue()) return FalseVal; // X > MAX ? T : F --> F - if (Pred == ICmpInst::ICMP_UGT && C->isMaxValue()) + if (Pred == Predicate::ICMP_UGT && C->isMaxValue()) return FalseVal; } } @@ -3499,7 +3488,7 @@ // If we have an equality comparison, then we know the value in one of the // arms of the select. See if substituting this value into the arm and // simplifying the result yields the same value as the other arm. - if (Pred == ICmpInst::ICMP_EQ) { + if (Pred == Predicate::ICMP_EQ) { if (SimplifyWithOpReplaced(FalseVal, CmpLHS, CmpRHS, Q, MaxRecurse) == TrueVal || SimplifyWithOpReplaced(FalseVal, CmpRHS, CmpLHS, Q, MaxRecurse) == @@ -3510,7 +3499,7 @@ SimplifyWithOpReplaced(TrueVal, CmpRHS, CmpLHS, Q, MaxRecurse) == FalseVal) return FalseVal; - } else if (Pred == ICmpInst::ICMP_NE) { + } else if (Pred == Predicate::ICMP_NE) { if (SimplifyWithOpReplaced(TrueVal, CmpLHS, CmpRHS, Q, MaxRecurse) == FalseVal || SimplifyWithOpReplaced(TrueVal, CmpRHS, CmpLHS, Q, MaxRecurse) == @@ -3966,18 +3955,18 @@ } /// Given operands for a CmpInst, see if we can fold the result. -static Value *SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, +static Value *SimplifyCmpInst(Predicate Pred, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse) { - if (CmpInst::isIntPredicate((CmpInst::Predicate)Predicate)) - return SimplifyICmpInst(Predicate, LHS, RHS, Q, MaxRecurse); - return SimplifyFCmpInst(Predicate, LHS, RHS, FastMathFlags(), Q, MaxRecurse); + if (Pred.isInt()) + return SimplifyICmpInst(Pred, LHS, RHS, Q, MaxRecurse); + return SimplifyFCmpInst(Pred, LHS, RHS, FastMathFlags(), Q, MaxRecurse); } -Value *llvm::SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, +Value *llvm::SimplifyCmpInst(Predicate Pred, Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionCache *AC, const Instruction *CxtI) { - return ::SimplifyCmpInst(Predicate, LHS, RHS, Query(DL, TLI, DT, AC, CxtI), + return ::SimplifyCmpInst(Pred, LHS, RHS, Query(DL, TLI, DT, AC, CxtI), RecursionLimit); } Index: lib/Analysis/LazyValueInfo.cpp =================================================================== --- lib/Analysis/LazyValueInfo.cpp +++ lib/Analysis/LazyValueInfo.cpp @@ -229,7 +229,8 @@ // move to overdefined. if (ConstantInt *Res = dyn_cast(ConstantFoldCompareInstOperands( - CmpInst::ICMP_NE, getConstant(), RHS.getNotConstant(), DL))) + Predicate::ICMP_NE, getConstant(), RHS.getNotConstant(), + DL))) if (Res->isOne()) return markNotConstant(RHS.getNotConstant()); @@ -248,7 +249,8 @@ // move to overdefined. if (ConstantInt *Res = dyn_cast(ConstantFoldCompareInstOperands( - CmpInst::ICMP_NE, getNotConstant(), RHS.getConstant(), DL))) + Predicate::ICMP_NE, getNotConstant(), RHS.getConstant(), + DL))) if (Res->isOne()) return false; @@ -970,7 +972,7 @@ // In general, this can handle any clamp idiom which tests the edge // condition via an equality or inequality. if (auto *ICI = dyn_cast(Cond)) { - ICmpInst::Predicate Pred = ICI->getPredicate(); + Predicate Pred = ICI->getPredicate(); Value *A = ICI->getOperand(0); if (ConstantInt *CIBase = dyn_cast(ICI->getOperand(1))) { auto addConstants = [](ConstantInt *A, ConstantInt *B) { @@ -981,9 +983,9 @@ // condition that A != C when that input is used. We can assume that // that input doesn't include C + C2. ConstantInt *CIAdded; - switch (Pred) { + switch (Pred.getKind()) { default: break; - case ICmpInst::ICMP_EQ: + case Predicate::ICMP_EQ: if (match(SI->getFalseValue(), m_Add(m_Specific(A), m_ConstantInt(CIAdded)))) { auto ResNot = addConstants(CIBase, CIAdded); @@ -991,7 +993,7 @@ LVILatticeVal::getNot(ResNot)); } break; - case ICmpInst::ICMP_NE: + case Predicate::ICMP_NE: if (match(SI->getTrueValue(), m_Add(m_Specific(A), m_ConstantInt(CIAdded)))) { auto ResNot = addConstants(CIBase, CIAdded); @@ -1185,13 +1187,13 @@ Value *LHS = ICI->getOperand(0); Value *RHS = ICI->getOperand(1); - CmpInst::Predicate Predicate = ICI->getPredicate(); + Predicate Pred = ICI->getPredicate(); if (isa(RHS)) { if (ICI->isEquality() && LHS == Val) { // We know that V has the RHS constant if this is a true SETEQ or // false SETNE. - if (isTrueDest == (Predicate == ICmpInst::ICMP_EQ)) + if (isTrueDest == (Pred == Predicate::ICMP_EQ)) Result = LVILatticeVal::get(cast(RHS)); else Result = LVILatticeVal::getNot(cast(RHS)); @@ -1201,7 +1203,7 @@ // Recognize the range checking idiom that InstCombine produces. // (X+C1) u< C2 --> [-C1, C2-C1) ConstantInt *Offset = nullptr; - if (Predicate == ICmpInst::ICMP_ULT) + if (Pred == Predicate::ICMP_ULT) match(LHS, m_Add(m_Specific(Val), m_ConstantInt(Offset))); ConstantInt *CI = dyn_cast(RHS); @@ -1210,8 +1212,7 @@ ConstantRange CmpRange(CI->getValue()); // If we're interested in the false dest, invert the condition - CmpInst::Predicate Pred = - isTrueDest ? Predicate : CmpInst::getInversePredicate(Predicate); + Pred = isTrueDest ? Pred : Pred.getInverse(); ConstantRange TrueValues = ConstantRange::makeAllowedICmpRegion(Pred, CmpRange); @@ -1547,7 +1548,7 @@ return nullptr; } -static LazyValueInfo::Tristate getPredicateResult(unsigned Pred, Constant *C, +static LazyValueInfo::Tristate getPredicateResult(Predicate Pred, Constant *C, LVILatticeVal &Result, const DataLayout &DL, TargetLibraryInfo *TLI) { @@ -1567,13 +1568,13 @@ if (!CI) return LazyValueInfo::Unknown; ConstantRange CR = Result.getConstantRange(); - if (Pred == ICmpInst::ICMP_EQ) { + if (Pred == Predicate::ICMP_EQ) { if (!CR.contains(CI->getValue())) return LazyValueInfo::False; if (CR.isSingleElement() && CR.contains(CI->getValue())) return LazyValueInfo::True; - } else if (Pred == ICmpInst::ICMP_NE) { + } else if (Pred == Predicate::ICMP_NE) { if (!CR.contains(CI->getValue())) return LazyValueInfo::True; @@ -1583,7 +1584,7 @@ // Handle more complex predicates. ConstantRange TrueValues = - ICmpInst::makeConstantRange((ICmpInst::Predicate)Pred, CI->getValue()); + ICmpInst::makeConstantRange(Pred, CI->getValue()); if (TrueValues.contains(CR)) return LazyValueInfo::True; if (TrueValues.inverse().contains(CR)) @@ -1594,18 +1595,16 @@ if (Result.isNotConstant()) { // If this is an equality comparison, we can try to fold it knowing that // "V != C1". - if (Pred == ICmpInst::ICMP_EQ) { + if (Pred == Predicate::ICMP_EQ) { // !C1 == C -> false iff C1 == C. - Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE, - Result.getNotConstant(), C, DL, - TLI); + Res = ConstantFoldCompareInstOperands( + Predicate::ICMP_NE, Result.getNotConstant(), C, DL, TLI); if (Res->isNullValue()) return LazyValueInfo::False; - } else if (Pred == ICmpInst::ICMP_NE) { + } else if (Pred == Predicate::ICMP_NE) { // !C1 != C -> true iff C1 == C. - Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE, - Result.getNotConstant(), C, DL, - TLI); + Res = ConstantFoldCompareInstOperands( + Predicate::ICMP_NE, Result.getNotConstant(), C, DL, TLI); if (Res->isNullValue()) return LazyValueInfo::True; } @@ -1617,10 +1616,11 @@ /// Determine whether the specified value comparison with a constant is known to /// be true or false on the specified CFG edge. Pred is a CmpInst predicate. -LazyValueInfo::Tristate -LazyValueInfo::getPredicateOnEdge(unsigned Pred, Value *V, Constant *C, - BasicBlock *FromBB, BasicBlock *ToBB, - Instruction *CxtI) { +LazyValueInfo::Tristate LazyValueInfo::getPredicateOnEdge(Predicate Pred, + Value *V, Constant *C, + BasicBlock *FromBB, + BasicBlock *ToBB, + Instruction *CxtI) { const DataLayout &DL = FromBB->getModule()->getDataLayout(); LVILatticeVal Result = getCache(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI); @@ -1628,9 +1628,9 @@ return getPredicateResult(Pred, C, Result, DL, TLI); } -LazyValueInfo::Tristate -LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C, - Instruction *CxtI) { +LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(Predicate Pred, Value *V, + Constant *C, + Instruction *CxtI) { const DataLayout &DL = CxtI->getModule()->getDataLayout(); LVILatticeVal Result = getCache(PImpl, AC, &DL, DT).getValueAt(V, CxtI); Tristate Ret = getPredicateResult(Pred, C, Result, DL, TLI); Index: lib/Analysis/ScalarEvolution.cpp =================================================================== --- lib/Analysis/ScalarEvolution.cpp +++ lib/Analysis/ScalarEvolution.cpp @@ -1149,16 +1149,16 @@ // signed overflow as long as the value of the recurrence within the // loop does not exceed this limit before incrementing. static const SCEV *getSignedOverflowLimitForStep(const SCEV *Step, - ICmpInst::Predicate *Pred, + Predicate *Pred, ScalarEvolution *SE) { unsigned BitWidth = SE->getTypeSizeInBits(Step->getType()); if (SE->isKnownPositive(Step)) { - *Pred = ICmpInst::ICMP_SLT; + *Pred = Predicate::ICMP_SLT; return SE->getConstant(APInt::getSignedMinValue(BitWidth) - SE->getSignedRange(Step).getSignedMax()); } if (SE->isKnownNegative(Step)) { - *Pred = ICmpInst::ICMP_SGT; + *Pred = Predicate::ICMP_SGT; return SE->getConstant(APInt::getSignedMaxValue(BitWidth) - SE->getSignedRange(Step).getSignedMin()); } @@ -1169,10 +1169,10 @@ // unsigned overflow as long as the value of the recurrence within the loop does // not exceed this limit before incrementing. static const SCEV *getUnsignedOverflowLimitForStep(const SCEV *Step, - ICmpInst::Predicate *Pred, + Predicate *Pred, ScalarEvolution *SE) { unsigned BitWidth = SE->getTypeSizeInBits(Step->getType()); - *Pred = ICmpInst::ICMP_ULT; + *Pred = Predicate::ICMP_ULT; return SE->getConstant(APInt::getMinValue(BitWidth) - SE->getUnsignedRange(Step).getUnsignedMax()); @@ -1193,7 +1193,7 @@ // static const ExtendOpTraitsBase::GetExtendExprTy GetExtendExpr; // // static const SCEV *getOverflowLimitForStep(const SCEV *Step, - // ICmpInst::Predicate *Pred, + // Predicate *Pred, // ScalarEvolution *SE); }; @@ -1203,8 +1203,7 @@ static const GetExtendExprTy GetExtendExpr; - static const SCEV *getOverflowLimitForStep(const SCEV *Step, - ICmpInst::Predicate *Pred, + static const SCEV *getOverflowLimitForStep(const SCEV *Step, Predicate *Pred, ScalarEvolution *SE) { return getSignedOverflowLimitForStep(Step, Pred, SE); } @@ -1219,8 +1218,7 @@ static const GetExtendExprTy GetExtendExpr; - static const SCEV *getOverflowLimitForStep(const SCEV *Step, - ICmpInst::Predicate *Pred, + static const SCEV *getOverflowLimitForStep(const SCEV *Step, Predicate *Pred, ScalarEvolution *SE) { return getUnsignedOverflowLimitForStep(Step, Pred, SE); } @@ -1299,7 +1297,7 @@ } // 3. Loop precondition. - ICmpInst::Predicate Pred; + Predicate Pred; const SCEV *OverflowLimit = ExtendOpTraits::getOverflowLimitForStep(Step, &Pred, SE); @@ -1390,7 +1388,7 @@ // actually constructing an add recurrence is relatively expensive. if (PreAR && PreAR->getNoWrapFlags(WrapType)) { // proves (2) const SCEV *DeltaS = getConstant(StartC->getType(), Delta); - ICmpInst::Predicate Pred = ICmpInst::BAD_ICMP_PREDICATE; + Predicate Pred = Predicate::BAD_ICMP_PREDICATE; const SCEV *Limit = ExtendOpTraits::getOverflowLimitForStep( DeltaS, &Pred, this); if (Limit && isKnownPredicate(Pred, PreAR, Limit)) // proves (1) @@ -1537,9 +1535,9 @@ if (isKnownPositive(Step)) { const SCEV *N = getConstant(APInt::getMinValue(BitWidth) - getUnsignedRange(Step).getUnsignedMax()); - if (isLoopBackedgeGuardedByCond(L, ICmpInst::ICMP_ULT, AR, N) || - (isLoopEntryGuardedByCond(L, ICmpInst::ICMP_ULT, Start, N) && - isLoopBackedgeGuardedByCond(L, ICmpInst::ICMP_ULT, + if (isLoopBackedgeGuardedByCond(L, Predicate::ICMP_ULT, AR, N) || + (isLoopEntryGuardedByCond(L, Predicate::ICMP_ULT, Start, N) && + isLoopBackedgeGuardedByCond(L, Predicate::ICMP_ULT, AR->getPostIncExpr(*this), N))) { // Cache knowledge of AR NUW, which is propagated to this // AddRec. @@ -1552,9 +1550,9 @@ } else if (isKnownNegative(Step)) { const SCEV *N = getConstant(APInt::getMaxValue(BitWidth) - getSignedRange(Step).getSignedMin()); - if (isLoopBackedgeGuardedByCond(L, ICmpInst::ICMP_UGT, AR, N) || - (isLoopEntryGuardedByCond(L, ICmpInst::ICMP_UGT, Start, N) && - isLoopBackedgeGuardedByCond(L, ICmpInst::ICMP_UGT, + if (isLoopBackedgeGuardedByCond(L, Predicate::ICMP_UGT, AR, N) || + (isLoopEntryGuardedByCond(L, Predicate::ICMP_UGT, Start, N) && + isLoopBackedgeGuardedByCond(L, Predicate::ICMP_UGT, AR->getPostIncExpr(*this), N))) { // Cache knowledge of AR NW, which is propagated to this // AddRec. Negative step causes unsigned wrap, but it @@ -1769,7 +1767,7 @@ // a comparison with the start value and the backedge is // guarded by a comparison with the post-inc value, the addrec // is safe. - ICmpInst::Predicate Pred; + Predicate Pred; const SCEV *OverflowLimit = getSignedOverflowLimitForStep(Step, &Pred, this); if (OverflowLimit && @@ -3092,11 +3090,11 @@ for (unsigned i = 0, e = Ops.size()-1; i != e; ++i) // X smax Y smax Y --> X smax Y // X smax Y --> X, if X is always greater than Y - if (Ops[i] == Ops[i+1] || - isKnownPredicate(ICmpInst::ICMP_SGE, Ops[i], Ops[i+1])) { + if (Ops[i] == Ops[i + 1] || + isKnownPredicate(Predicate::ICMP_SGE, Ops[i], Ops[i + 1])) { Ops.erase(Ops.begin()+i+1, Ops.begin()+i+2); --i; --e; - } else if (isKnownPredicate(ICmpInst::ICMP_SLE, Ops[i], Ops[i+1])) { + } else if (isKnownPredicate(Predicate::ICMP_SLE, Ops[i], Ops[i + 1])) { Ops.erase(Ops.begin()+i, Ops.begin()+i+1); --i; --e; } @@ -3193,11 +3191,11 @@ for (unsigned i = 0, e = Ops.size()-1; i != e; ++i) // X umax Y umax Y --> X umax Y // X umax Y --> X, if X is always greater than Y - if (Ops[i] == Ops[i+1] || - isKnownPredicate(ICmpInst::ICMP_UGE, Ops[i], Ops[i+1])) { + if (Ops[i] == Ops[i + 1] || + isKnownPredicate(Predicate::ICMP_UGE, Ops[i], Ops[i + 1])) { Ops.erase(Ops.begin()+i+1, Ops.begin()+i+2); --i; --e; - } else if (isKnownPredicate(ICmpInst::ICMP_ULE, Ops[i], Ops[i+1])) { + } else if (isKnownPredicate(Predicate::ICMP_ULE, Ops[i], Ops[i + 1])) { Ops.erase(Ops.begin()+i, Ops.begin()+i+1); --i; --e; } @@ -4242,13 +4240,13 @@ Value *LHS = ICI->getOperand(0); Value *RHS = ICI->getOperand(1); - switch (ICI->getPredicate()) { - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_SLE: + switch (ICI->getPredicate().getKind()) { + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: std::swap(LHS, RHS); // fall through - case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGT: + case Predicate::ICMP_SGE: // a >s b ? a+x : b+x -> smax(a, b)+x // a >s b ? b+x : a+x -> smin(a, b)+x if (getTypeSizeInBits(LHS->getType()) <= getTypeSizeInBits(I->getType())) { @@ -4266,12 +4264,12 @@ return getAddExpr(getSMinExpr(LS, RS), LDiff); } break; - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: std::swap(LHS, RHS); // fall through - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: // a >u b ? a+x : b+x -> umax(a, b)+x // a >u b ? b+x : a+x -> umin(a, b)+x if (getTypeSizeInBits(LHS->getType()) <= getTypeSizeInBits(I->getType())) { @@ -4289,7 +4287,7 @@ return getAddExpr(getUMinExpr(LS, RS), LDiff); } break; - case ICmpInst::ICMP_NE: + case Predicate::ICMP_NE: // n != 0 ? n+x : 1+x -> umax(n, 1)+x if (getTypeSizeInBits(LHS->getType()) <= getTypeSizeInBits(I->getType()) && isa(RHS) && cast(RHS)->isZero()) { @@ -4303,7 +4301,7 @@ return getAddExpr(getUMaxExpr(One, LS), LDiff); } break; - case ICmpInst::ICMP_EQ: + case Predicate::ICMP_EQ: // n == 0 ? 1+x : n+x -> umax(n, 1)+x if (getTypeSizeInBits(LHS->getType()) <= getTypeSizeInBits(I->getType()) && isa(RHS) && cast(RHS)->isZero()) { @@ -5938,7 +5936,7 @@ bool AllowPredicates) { // If the condition was exit on true, convert the condition to exit on false - ICmpInst::Predicate Cond; + Predicate Cond; if (!L->contains(FBB)) Cond = ExitCond->getPredicate(); else @@ -5965,7 +5963,7 @@ if (isLoopInvariant(LHS, L) && !isLoopInvariant(RHS, L)) { // If there is a loop-invariant, force it into the RHS. std::swap(LHS, RHS); - Cond = ICmpInst::getSwappedPredicate(Cond); + Cond = Cond.getSwapped(); } // Simplify the operands before analyzing them. @@ -5984,31 +5982,31 @@ if (!isa(Ret)) return Ret; } - switch (Cond) { - case ICmpInst::ICMP_NE: { // while (X != Y) + switch (Cond.getKind()) { + case Predicate::ICMP_NE: { // while (X != Y) // Convert to: while (X-Y != 0) ExitLimit EL = howFarToZero(getMinusSCEV(LHS, RHS), L, ControlsExit, AllowPredicates); if (EL.hasAnyInfo()) return EL; break; } - case ICmpInst::ICMP_EQ: { // while (X == Y) + case Predicate::ICMP_EQ: { // while (X == Y) // Convert to: while (X-Y == 0) ExitLimit EL = howFarToNonZero(getMinusSCEV(LHS, RHS), L); if (EL.hasAnyInfo()) return EL; break; } - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_ULT: { // while (X < Y) - bool IsSigned = Cond == ICmpInst::ICMP_SLT; + case Predicate::ICMP_SLT: + case Predicate::ICMP_ULT: { // while (X < Y) + bool IsSigned = Cond == Predicate::ICMP_SLT; ExitLimit EL = howManyLessThans(LHS, RHS, L, IsSigned, ControlsExit, AllowPredicates); if (EL.hasAnyInfo()) return EL; break; } - case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_UGT: { // while (X > Y) - bool IsSigned = Cond == ICmpInst::ICMP_SGT; + case Predicate::ICMP_SGT: + case Predicate::ICMP_UGT: { // while (X > Y) + bool IsSigned = Cond == Predicate::ICMP_SGT; ExitLimit EL = howManyGreaterThans(LHS, RHS, L, IsSigned, ControlsExit, AllowPredicates); @@ -6065,12 +6063,8 @@ /// Given an exit condition of 'icmp op load X, cst', try to see if we can /// compute the backedge execution count. -ScalarEvolution::ExitLimit -ScalarEvolution::computeLoadConstantCompareExitLimit( - LoadInst *LI, - Constant *RHS, - const Loop *L, - ICmpInst::Predicate predicate) { +ScalarEvolution::ExitLimit ScalarEvolution::computeLoadConstantCompareExitLimit( + LoadInst *LI, Constant *RHS, const Loop *L, Predicate predicate) { if (LI->isVolatile()) return getCouldNotCompute(); @@ -6142,8 +6136,9 @@ return getCouldNotCompute(); } -ScalarEvolution::ExitLimit ScalarEvolution::computeShiftCompareExitLimit( - Value *LHS, Value *RHSV, const Loop *L, ICmpInst::Predicate Pred) { +ScalarEvolution::ExitLimit +ScalarEvolution::computeShiftCompareExitLimit(Value *LHS, Value *RHSV, + const Loop *L, Predicate Pred) { ConstantInt *RHS = dyn_cast(RHSV); if (!RHS) return getCouldNotCompute(); @@ -7068,7 +7063,7 @@ const SCEVConstant *R2 = Roots->second; // Pick the smallest positive root value. if (ConstantInt *CB = dyn_cast(ConstantExpr::getICmp( - CmpInst::ICMP_ULT, R1->getValue(), R2->getValue()))) { + Predicate::ICMP_ULT, R1->getValue(), R2->getValue()))) { if (!CB->getZExtValue()) std::swap(R1, R2); // R1 is the minimum root now. @@ -7279,9 +7274,8 @@ return false; } -bool ScalarEvolution::SimplifyICmpOperands(ICmpInst::Predicate &Pred, - const SCEV *&LHS, const SCEV *&RHS, - unsigned Depth) { +bool ScalarEvolution::SimplifyICmpOperands(Predicate &Pred, const SCEV *&LHS, + const SCEV *&RHS, unsigned Depth) { bool Changed = false; // If we hit the max recursion limit bail out. @@ -7301,7 +7295,7 @@ } // Otherwise swap the operands to put the constant on the right. std::swap(LHS, RHS); - Pred = ICmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); Changed = true; } @@ -7312,7 +7306,7 @@ const Loop *L = AR->getLoop(); if (isLoopInvariant(LHS, L) && properlyDominates(LHS, L->getHeader())) { std::swap(LHS, RHS); - Pred = ICmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); Changed = true; } } @@ -7321,10 +7315,11 @@ // cases, and canonicalize *-or-equal comparisons to regular comparisons. if (const SCEVConstant *RC = dyn_cast(RHS)) { const APInt &RA = RC->getAPInt(); - switch (Pred) { - default: llvm_unreachable("Unexpected ICmpInst::Predicate value!"); - case ICmpInst::ICMP_EQ: - case ICmpInst::ICMP_NE: + switch (Pred.getKind()) { + default: + llvm_unreachable("Unexpected Predicate value!"); + case Predicate::ICMP_EQ: + case Predicate::ICMP_NE: // Fold ((-1) * %a) + %b == 0 (equivalent to %b-%a == 0) into %a == %b. if (!RA) if (const SCEVAddExpr *AE = dyn_cast(LHS)) @@ -7336,129 +7331,129 @@ Changed = true; } break; - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: if ((RA - 1).isMinValue()) { - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; RHS = getConstant(RA - 1); Changed = true; break; } if (RA.isMaxValue()) { - Pred = ICmpInst::ICMP_EQ; + Pred = Predicate::ICMP_EQ; Changed = true; break; } if (RA.isMinValue()) goto trivially_true; - Pred = ICmpInst::ICMP_UGT; + Pred = Predicate::ICMP_UGT; RHS = getConstant(RA - 1); Changed = true; break; - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULE: if ((RA + 1).isMaxValue()) { - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; RHS = getConstant(RA + 1); Changed = true; break; } if (RA.isMinValue()) { - Pred = ICmpInst::ICMP_EQ; + Pred = Predicate::ICMP_EQ; Changed = true; break; } if (RA.isMaxValue()) goto trivially_true; - Pred = ICmpInst::ICMP_ULT; + Pred = Predicate::ICMP_ULT; RHS = getConstant(RA + 1); Changed = true; break; - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: if ((RA - 1).isMinSignedValue()) { - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; RHS = getConstant(RA - 1); Changed = true; break; } if (RA.isMaxSignedValue()) { - Pred = ICmpInst::ICMP_EQ; + Pred = Predicate::ICMP_EQ; Changed = true; break; } if (RA.isMinSignedValue()) goto trivially_true; - Pred = ICmpInst::ICMP_SGT; + Pred = Predicate::ICMP_SGT; RHS = getConstant(RA - 1); Changed = true; break; - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLE: if ((RA + 1).isMaxSignedValue()) { - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; RHS = getConstant(RA + 1); Changed = true; break; } if (RA.isMinSignedValue()) { - Pred = ICmpInst::ICMP_EQ; + Pred = Predicate::ICMP_EQ; Changed = true; break; } if (RA.isMaxSignedValue()) goto trivially_true; - Pred = ICmpInst::ICMP_SLT; + Pred = Predicate::ICMP_SLT; RHS = getConstant(RA + 1); Changed = true; break; - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_UGT: if (RA.isMinValue()) { - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; Changed = true; break; } if ((RA + 1).isMaxValue()) { - Pred = ICmpInst::ICMP_EQ; + Pred = Predicate::ICMP_EQ; RHS = getConstant(RA + 1); Changed = true; break; } if (RA.isMaxValue()) goto trivially_false; break; - case ICmpInst::ICMP_ULT: + case Predicate::ICMP_ULT: if (RA.isMaxValue()) { - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; Changed = true; break; } if ((RA - 1).isMinValue()) { - Pred = ICmpInst::ICMP_EQ; + Pred = Predicate::ICMP_EQ; RHS = getConstant(RA - 1); Changed = true; break; } if (RA.isMinValue()) goto trivially_false; break; - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: if (RA.isMinSignedValue()) { - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; Changed = true; break; } if ((RA + 1).isMaxSignedValue()) { - Pred = ICmpInst::ICMP_EQ; + Pred = Predicate::ICMP_EQ; RHS = getConstant(RA + 1); Changed = true; break; } if (RA.isMaxSignedValue()) goto trivially_false; break; - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: if (RA.isMaxSignedValue()) { - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; Changed = true; break; } if ((RA - 1).isMinSignedValue()) { - Pred = ICmpInst::ICMP_EQ; - RHS = getConstant(RA - 1); + Pred = Predicate::ICMP_EQ; + RHS = getConstant(RA - 1); Changed = true; break; } @@ -7469,62 +7464,62 @@ // Check for obvious equality. if (HasSameValue(LHS, RHS)) { - if (ICmpInst::isTrueWhenEqual(Pred)) + if (Pred.isTrueWhenEqual()) goto trivially_true; - if (ICmpInst::isFalseWhenEqual(Pred)) + if (Pred.isFalseWhenEqual()) goto trivially_false; } // If possible, canonicalize GE/LE comparisons to GT/LT comparisons, by // adding or subtracting 1 from one of the operands. - switch (Pred) { - case ICmpInst::ICMP_SLE: + switch (Pred.getKind()) { + case Predicate::ICMP_SLE: if (!getSignedRange(RHS).getSignedMax().isMaxSignedValue()) { RHS = getAddExpr(getConstant(RHS->getType(), 1, true), RHS, SCEV::FlagNSW); - Pred = ICmpInst::ICMP_SLT; + Pred = Predicate::ICMP_SLT; Changed = true; } else if (!getSignedRange(LHS).getSignedMin().isMinSignedValue()) { LHS = getAddExpr(getConstant(RHS->getType(), (uint64_t)-1, true), LHS, SCEV::FlagNSW); - Pred = ICmpInst::ICMP_SLT; + Pred = Predicate::ICMP_SLT; Changed = true; } break; - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: if (!getSignedRange(RHS).getSignedMin().isMinSignedValue()) { RHS = getAddExpr(getConstant(RHS->getType(), (uint64_t)-1, true), RHS, SCEV::FlagNSW); - Pred = ICmpInst::ICMP_SGT; + Pred = Predicate::ICMP_SGT; Changed = true; } else if (!getSignedRange(LHS).getSignedMax().isMaxSignedValue()) { LHS = getAddExpr(getConstant(RHS->getType(), 1, true), LHS, SCEV::FlagNSW); - Pred = ICmpInst::ICMP_SGT; + Pred = Predicate::ICMP_SGT; Changed = true; } break; - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULE: if (!getUnsignedRange(RHS).getUnsignedMax().isMaxValue()) { RHS = getAddExpr(getConstant(RHS->getType(), 1, true), RHS, SCEV::FlagNUW); - Pred = ICmpInst::ICMP_ULT; + Pred = Predicate::ICMP_ULT; Changed = true; } else if (!getUnsignedRange(LHS).getUnsignedMin().isMinValue()) { LHS = getAddExpr(getConstant(RHS->getType(), (uint64_t)-1, true), LHS); - Pred = ICmpInst::ICMP_ULT; + Pred = Predicate::ICMP_ULT; Changed = true; } break; - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: if (!getUnsignedRange(RHS).getUnsignedMin().isMinValue()) { RHS = getAddExpr(getConstant(RHS->getType(), (uint64_t)-1, true), RHS); - Pred = ICmpInst::ICMP_UGT; + Pred = Predicate::ICMP_UGT; Changed = true; } else if (!getUnsignedRange(LHS).getUnsignedMax().isMaxValue()) { LHS = getAddExpr(getConstant(RHS->getType(), 1, true), LHS, SCEV::FlagNUW); - Pred = ICmpInst::ICMP_UGT; + Pred = Predicate::ICMP_UGT; Changed = true; } break; @@ -7544,13 +7539,13 @@ trivially_true: // Return 0 == 0. LHS = RHS = getConstant(ConstantInt::getFalse(getContext())); - Pred = ICmpInst::ICMP_EQ; + Pred = Predicate::ICMP_EQ; return true; trivially_false: // Return 0 != 0. LHS = RHS = getConstant(ConstantInt::getFalse(getContext())); - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; return true; } @@ -7574,8 +7569,8 @@ return isKnownNegative(S) || isKnownPositive(S); } -bool ScalarEvolution::isKnownPredicate(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS) { +bool ScalarEvolution::isKnownPredicate(Predicate Pred, const SCEV *LHS, + const SCEV *RHS) { // Canonicalize the inputs first. (void)SimplifyICmpOperands(Pred, LHS, RHS); @@ -7614,16 +7609,15 @@ } bool ScalarEvolution::isMonotonicPredicate(const SCEVAddRecExpr *LHS, - ICmpInst::Predicate Pred, - bool &Increasing) { + Predicate Pred, bool &Increasing) { bool Result = isMonotonicPredicateImpl(LHS, Pred, Increasing); #ifndef NDEBUG // Verify an invariant: inverting the predicate should turn a monotonically // increasing change to a monotonically decreasing one, and vice versa. bool IncreasingSwapped; - bool ResultSwapped = isMonotonicPredicateImpl( - LHS, ICmpInst::getSwappedPredicate(Pred), IncreasingSwapped); + bool ResultSwapped = + isMonotonicPredicateImpl(LHS, Pred.getSwapped(), IncreasingSwapped); assert(Result == ResultSwapped && "should be able to analyze both!"); if (ResultSwapped) @@ -7635,7 +7629,7 @@ } bool ScalarEvolution::isMonotonicPredicateImpl(const SCEVAddRecExpr *LHS, - ICmpInst::Predicate Pred, + Predicate Pred, bool &Increasing) { // A zero step value for LHS means the induction variable is essentially a @@ -7648,36 +7642,36 @@ // where SCEV can prove X >= 0 but not prove X > 0, so it is helpful to be // as general as possible. - switch (Pred) { + switch (Pred.getKind()) { default: return false; // Conservative answer - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_UGE: - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: if (!LHS->hasNoUnsignedWrap()) return false; - Increasing = Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_UGE; + Increasing = Pred == Predicate::ICMP_UGT || Pred == Predicate::ICMP_UGE; return true; - case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_SGE: - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_SLE: { + case Predicate::ICMP_SGT: + case Predicate::ICMP_SGE: + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: { if (!LHS->hasNoSignedWrap()) return false; const SCEV *Step = LHS->getStepRecurrence(*this); if (isKnownNonNegative(Step)) { - Increasing = Pred == ICmpInst::ICMP_SGT || Pred == ICmpInst::ICMP_SGE; + Increasing = Pred == Predicate::ICMP_SGT || Pred == Predicate::ICMP_SGE; return true; } if (isKnownNonPositive(Step)) { - Increasing = Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SLE; + Increasing = Pred == Predicate::ICMP_SLT || Pred == Predicate::ICMP_SLE; return true; } @@ -7689,10 +7683,11 @@ llvm_unreachable("switch has default clause!"); } -bool ScalarEvolution::isLoopInvariantPredicate( - ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, - ICmpInst::Predicate &InvariantPred, const SCEV *&InvariantLHS, - const SCEV *&InvariantRHS) { +bool ScalarEvolution::isLoopInvariantPredicate(Predicate Pred, const SCEV *LHS, + const SCEV *RHS, const Loop *L, + Predicate &InvariantPred, + const SCEV *&InvariantLHS, + const SCEV *&InvariantRHS) { // If there is a loop-invariant, force it into the RHS, otherwise bail out. if (!isLoopInvariant(RHS, L)) { @@ -7700,7 +7695,7 @@ return false; std::swap(LHS, RHS); - Pred = ICmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); } const SCEVAddRecExpr *ArLHS = dyn_cast(LHS); @@ -7729,7 +7724,7 @@ // A similar reasoning applies for a monotonically decreasing predicate, by // replacing true with false and false with true in the above two bullets. - auto P = Increasing ? Pred : ICmpInst::getInversePredicate(Pred); + auto P = Increasing ? Pred : Pred.getInverse(); if (!isLoopBackedgeGuardedByCond(L, P, LHS, RHS)) return false; @@ -7740,10 +7735,11 @@ return true; } -bool ScalarEvolution::isKnownPredicateViaConstantRanges( - ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS) { +bool ScalarEvolution::isKnownPredicateViaConstantRanges(Predicate Pred, + const SCEV *LHS, + const SCEV *RHS) { if (HasSameValue(LHS, RHS)) - return ICmpInst::isTrueWhenEqual(Pred); + return Pred.isTrueWhenEqual(); // This code is split out from isKnownPredicate because it is called from // within isLoopEntryGuardedByCond. @@ -7756,21 +7752,21 @@ // The check at the top of the function catches the case where the values are // known to be equal. - if (Pred == CmpInst::ICMP_EQ) + if (Pred == Predicate::ICMP_EQ) return false; - if (Pred == CmpInst::ICMP_NE) + if (Pred == Predicate::ICMP_NE) return CheckRanges(getSignedRange(LHS), getSignedRange(RHS)) || CheckRanges(getUnsignedRange(LHS), getUnsignedRange(RHS)) || isKnownNonZero(getMinusSCEV(LHS, RHS)); - if (CmpInst::isSigned(Pred)) + if (Pred.isSigned()) return CheckRanges(getSignedRange(LHS), getSignedRange(RHS)); return CheckRanges(getUnsignedRange(LHS), getUnsignedRange(RHS)); } -bool ScalarEvolution::isKnownPredicateViaNoOverflow(ICmpInst::Predicate Pred, +bool ScalarEvolution::isKnownPredicateViaNoOverflow(Predicate Pred, const SCEV *LHS, const SCEV *RHS) { @@ -7792,13 +7788,13 @@ APInt C; - switch (Pred) { + switch (Pred.getKind()) { default: break; - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: std::swap(LHS, RHS); - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLE: // X s<= (X + C) if C >= 0 if (MatchBinaryAddToConst(RHS, LHS, C, SCEV::FlagNSW) && C.isNonNegative()) return true; @@ -7809,9 +7805,9 @@ return true; break; - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: std::swap(LHS, RHS); - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: // X s< (X + C) if C > 0 if (MatchBinaryAddToConst(RHS, LHS, C, SCEV::FlagNSW) && C.isStrictlyPositive()) @@ -7826,10 +7822,10 @@ return false; } -bool ScalarEvolution::isKnownPredicateViaSplitting(ICmpInst::Predicate Pred, +bool ScalarEvolution::isKnownPredicateViaSplitting(Predicate Pred, const SCEV *LHS, const SCEV *RHS) { - if (Pred != ICmpInst::ICMP_ULT || ProvingSplitPredicate) + if (Pred != Predicate::ICMP_ULT || ProvingSplitPredicate) return false; // Allowing arbitrary number of activations of isKnownPredicateViaSplitting on @@ -7844,12 +7840,11 @@ // interesting cases seen in practice. We can consider "upgrading" L >= 0 to // use isKnownPredicate later if needed. return isKnownNonNegative(RHS) && - isKnownPredicate(CmpInst::ICMP_SGE, LHS, getZero(LHS->getType())) && - isKnownPredicate(CmpInst::ICMP_SLT, LHS, RHS); + isKnownPredicate(Predicate::ICMP_SGE, LHS, getZero(LHS->getType())) && + isKnownPredicate(Predicate::ICMP_SLT, LHS, RHS); } -bool ScalarEvolution::isImpliedViaGuard(BasicBlock *BB, - ICmpInst::Predicate Pred, +bool ScalarEvolution::isImpliedViaGuard(BasicBlock *BB, Predicate Pred, const SCEV *LHS, const SCEV *RHS) { // No need to even try if we know the module has no guards. if (!HasGuards) @@ -7868,10 +7863,9 @@ /// isLoopBackedgeGuardedByCond - Test whether the backedge of the loop is /// protected by a conditional between LHS and RHS. This is used to /// to eliminate casts. -bool -ScalarEvolution::isLoopBackedgeGuardedByCond(const Loop *L, - ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS) { +bool ScalarEvolution::isLoopBackedgeGuardedByCond(const Loop *L, Predicate Pred, + const SCEV *LHS, + const SCEV *RHS) { // Interpret a null as meaning no loop, where there is obviously no guard // (interprocedural conditions notwithstanding). if (!L) return true; @@ -7909,7 +7903,7 @@ auto NoWrapFlags = SCEV::NoWrapFlags(SCEV::FlagNUW | SCEV::FlagNW); const SCEV *LoopCounter = getAddRecExpr(getZero(Ty), getOne(Ty), L, NoWrapFlags); - if (isImpliedCond(Pred, LHS, RHS, ICmpInst::ICMP_ULT, LoopCounter, + if (isImpliedCond(Pred, LHS, RHS, Predicate::ICMP_ULT, LoopCounter, LatchBECount)) return true; } @@ -7974,10 +7968,9 @@ return false; } -bool -ScalarEvolution::isLoopEntryGuardedByCond(const Loop *L, - ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS) { +bool ScalarEvolution::isLoopEntryGuardedByCond(const Loop *L, Predicate Pred, + const SCEV *LHS, + const SCEV *RHS) { // Interpret a null as meaning no loop, where there is obviously no guard // (interprocedural conditions notwithstanding). if (!L) return false; @@ -8043,9 +8036,8 @@ }; } // end anonymous namespace -bool ScalarEvolution::isImpliedCond(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS, - Value *FoundCondValue, +bool ScalarEvolution::isImpliedCond(Predicate Pred, const SCEV *LHS, + const SCEV *RHS, Value *FoundCondValue, bool Inverse) { MarkPendingLoopPredicate Mark(FoundCondValue, PendingLoopPredicates); if (Mark.Pending) @@ -8069,7 +8061,7 @@ // Now that we found a conditional branch that dominates the loop or controls // the loop latch. Check to see if it is the comparison we are looking for. - ICmpInst::Predicate FoundPred; + Predicate FoundPred; if (Inverse) FoundPred = ICI->getInversePredicate(); else @@ -8081,15 +8073,14 @@ return isImpliedCond(Pred, LHS, RHS, FoundPred, FoundLHS, FoundRHS); } -bool ScalarEvolution::isImpliedCond(ICmpInst::Predicate Pred, const SCEV *LHS, - const SCEV *RHS, - ICmpInst::Predicate FoundPred, +bool ScalarEvolution::isImpliedCond(Predicate Pred, const SCEV *LHS, + const SCEV *RHS, Predicate FoundPred, const SCEV *FoundLHS, const SCEV *FoundRHS) { // Balance the types. if (getTypeSizeInBits(LHS->getType()) < getTypeSizeInBits(FoundLHS->getType())) { - if (CmpInst::isSigned(Pred)) { + if (Pred.isSigned()) { LHS = getSignExtendExpr(LHS, FoundLHS->getType()); RHS = getSignExtendExpr(RHS, FoundLHS->getType()); } else { @@ -8098,7 +8089,7 @@ } } else if (getTypeSizeInBits(LHS->getType()) > getTypeSizeInBits(FoundLHS->getType())) { - if (CmpInst::isSigned(FoundPred)) { + if (FoundPred.isSigned()) { FoundLHS = getSignExtendExpr(FoundLHS, LHS->getType()); FoundRHS = getSignExtendExpr(FoundRHS, LHS->getType()); } else { @@ -8111,19 +8102,19 @@ // canonicalized the comparison. if (SimplifyICmpOperands(Pred, LHS, RHS)) if (LHS == RHS) - return CmpInst::isTrueWhenEqual(Pred); + return Pred.isTrueWhenEqual(); if (SimplifyICmpOperands(FoundPred, FoundLHS, FoundRHS)) if (FoundLHS == FoundRHS) - return CmpInst::isFalseWhenEqual(FoundPred); + return FoundPred.isFalseWhenEqual(); // Check to see if we can make the LHS or RHS match. if (LHS == FoundRHS || RHS == FoundLHS) { if (isa(RHS)) { std::swap(FoundLHS, FoundRHS); - FoundPred = ICmpInst::getSwappedPredicate(FoundPred); + FoundPred = FoundPred.getSwapped(); } else { std::swap(LHS, RHS); - Pred = ICmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); } } @@ -8133,23 +8124,22 @@ // Check whether swapping the found predicate makes it the same as the // desired predicate. - if (ICmpInst::getSwappedPredicate(FoundPred) == Pred) { + if (FoundPred.getSwapped() == Pred) { if (isa(RHS)) return isImpliedCondOperands(Pred, LHS, RHS, FoundRHS, FoundLHS); else - return isImpliedCondOperands(ICmpInst::getSwappedPredicate(Pred), - RHS, LHS, FoundLHS, FoundRHS); + return isImpliedCondOperands(Pred.getSwapped(), RHS, LHS, FoundLHS, + FoundRHS); } // Unsigned comparison is the same as signed comparison when both the operands // are non-negative. - if (CmpInst::isUnsigned(FoundPred) && - CmpInst::getSignedPredicate(FoundPred) == Pred && + if (FoundPred.isUnsigned() && FoundPred.getSigned() == Pred && isKnownNonNegative(FoundLHS) && isKnownNonNegative(FoundRHS)) return isImpliedCondOperands(Pred, LHS, RHS, FoundLHS, FoundRHS); // Check if we can make progress by sharpening ranges. - if (FoundPred == ICmpInst::ICMP_NE && + if (FoundPred == Predicate::ICMP_NE && (isa(FoundLHS) || isa(FoundRHS))) { const SCEVConstant *C = nullptr; @@ -8168,8 +8158,8 @@ // range we consider has to correspond to same signedness as the // predicate we're interested in folding. - APInt Min = ICmpInst::isSigned(Pred) ? - getSignedRange(V).getSignedMin() : getUnsignedRange(V).getUnsignedMin(); + APInt Min = Pred.isSigned() ? getSignedRange(V).getSignedMin() + : getUnsignedRange(V).getUnsignedMin(); if (Min == C->getAPInt()) { // Given (V >= Min && V != Min) we conclude V >= (Min + 1). @@ -8178,43 +8168,42 @@ APInt SharperMin = Min + 1; - switch (Pred) { - case ICmpInst::ICMP_SGE: - case ICmpInst::ICMP_UGE: - // We know V `Pred` SharperMin. If this implies LHS `Pred` - // RHS, we're done. - if (isImpliedCondOperands(Pred, LHS, RHS, V, - getConstant(SharperMin))) - return true; + switch (Pred.getKind()) { + case Predicate::ICMP_SGE: + case Predicate::ICMP_UGE: + // We know V `Pred` SharperMin. If this implies LHS `Pred` + // RHS, we're done. + if (isImpliedCondOperands(Pred, LHS, RHS, V, getConstant(SharperMin))) + return true; - case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_UGT: - // We know from the range information that (V `Pred` Min || - // V == Min). We know from the guarding condition that !(V - // == Min). This gives us - // - // V `Pred` Min || V == Min && !(V == Min) - // => V `Pred` Min - // - // If V `Pred` Min implies LHS `Pred` RHS, we're done. + case Predicate::ICMP_SGT: + case Predicate::ICMP_UGT: + // We know from the range information that (V `Pred` Min || + // V == Min). We know from the guarding condition that !(V + // == Min). This gives us + // + // V `Pred` Min || V == Min && !(V == Min) + // => V `Pred` Min + // + // If V `Pred` Min implies LHS `Pred` RHS, we're done. - if (isImpliedCondOperands(Pred, LHS, RHS, V, getConstant(Min))) - return true; + if (isImpliedCondOperands(Pred, LHS, RHS, V, getConstant(Min))) + return true; - default: - // No change - break; + default: + // No change + break; } } } // Check whether the actual condition is beyond sufficient. - if (FoundPred == ICmpInst::ICMP_EQ) - if (ICmpInst::isTrueWhenEqual(Pred)) + if (FoundPred == Predicate::ICMP_EQ) + if (Pred.isTrueWhenEqual()) if (isImpliedCondOperands(Pred, LHS, RHS, FoundLHS, FoundRHS)) return true; - if (Pred == ICmpInst::ICMP_NE) - if (!ICmpInst::isTrueWhenEqual(FoundPred)) + if (Pred == Predicate::ICMP_NE) + if (!FoundPred.isTrueWhenEqual()) if (isImpliedCondOperands(FoundPred, LHS, RHS, FoundLHS, FoundRHS)) return true; @@ -8282,10 +8271,12 @@ return None; } -bool ScalarEvolution::isImpliedCondOperandsViaNoOverflow( - ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS, - const SCEV *FoundLHS, const SCEV *FoundRHS) { - if (Pred != CmpInst::ICMP_SLT && Pred != CmpInst::ICMP_ULT) +bool ScalarEvolution::isImpliedCondOperandsViaNoOverflow(Predicate Pred, + const SCEV *LHS, + const SCEV *RHS, + const SCEV *FoundLHS, + const SCEV *FoundRHS) { + if (Pred != Predicate::ICMP_SLT && Pred != Predicate::ICMP_ULT) return false; const auto *AddRecLHS = dyn_cast(LHS); @@ -8346,10 +8337,10 @@ APInt FoundRHSLimit; - if (Pred == CmpInst::ICMP_ULT) { + if (Pred == Predicate::ICMP_ULT) { FoundRHSLimit = -(*RDiff); } else { - assert(Pred == CmpInst::ICMP_SLT && "Checked above!"); + assert(Pred == Predicate::ICMP_SLT && "Checked above!"); FoundRHSLimit = APInt::getSignedMinValue(getTypeSizeInBits(RHS->getType())) - *RDiff; } @@ -8358,8 +8349,8 @@ getConstant(FoundRHSLimit)); } -bool ScalarEvolution::isImpliedCondOperands(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS, +bool ScalarEvolution::isImpliedCondOperands(Predicate Pred, const SCEV *LHS, + const SCEV *RHS, const SCEV *FoundLHS, const SCEV *FoundRHS) { if (isImpliedCondOperandsViaRanges(Pred, LHS, RHS, FoundLHS, FoundRHS)) @@ -8416,15 +8407,14 @@ return IsMaxConsistingOf(MaybeMaxExpr, SE.getNotSCEV(Candidate)); } -static bool IsKnownPredicateViaAddRecStart(ScalarEvolution &SE, - ICmpInst::Predicate Pred, +static bool IsKnownPredicateViaAddRecStart(ScalarEvolution &SE, Predicate Pred, const SCEV *LHS, const SCEV *RHS) { // If both sides are affine addrecs for the same loop, with equal // steps, and we know the recurrences don't wrap, then we only // need to check the predicate on the starting values. - if (!ICmpInst::isRelational(Pred)) + if (!Pred.isRelational()) return false; const SCEVAddRecExpr *LAR = dyn_cast(LHS); @@ -8441,8 +8431,7 @@ if (LAR->getStepRecurrence(SE) != RAR->getStepRecurrence(SE)) return false; - SCEV::NoWrapFlags NW = ICmpInst::isSigned(Pred) ? - SCEV::FlagNSW : SCEV::FlagNUW; + SCEV::NoWrapFlags NW = Pred.isSigned() ? SCEV::FlagNSW : SCEV::FlagNUW; if (!LAR->getNoWrapFlags(NW) || !RAR->getNoWrapFlags(NW)) return false; @@ -8451,27 +8440,26 @@ /// Is LHS `Pred` RHS true on the virtue of LHS or RHS being a Min or Max /// expression? -static bool IsKnownPredicateViaMinOrMax(ScalarEvolution &SE, - ICmpInst::Predicate Pred, +static bool IsKnownPredicateViaMinOrMax(ScalarEvolution &SE, Predicate Pred, const SCEV *LHS, const SCEV *RHS) { - switch (Pred) { + switch (Pred.getKind()) { default: return false; - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: std::swap(LHS, RHS); // fall through - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLE: return // min(A, ...) <= A IsMinConsistingOf(SE, LHS, RHS) || // A <= max(A, ...) IsMaxConsistingOf(RHS, LHS); - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: std::swap(LHS, RHS); // fall through - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULE: return // min(A, ...) <= A IsMinConsistingOf(SE, LHS, RHS) || @@ -8482,48 +8470,49 @@ llvm_unreachable("covered switch fell through?!"); } -bool -ScalarEvolution::isImpliedCondOperandsHelper(ICmpInst::Predicate Pred, - const SCEV *LHS, const SCEV *RHS, - const SCEV *FoundLHS, - const SCEV *FoundRHS) { - auto IsKnownPredicateFull = - [this](ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS) { +bool ScalarEvolution::isImpliedCondOperandsHelper(Predicate Pred, + const SCEV *LHS, + const SCEV *RHS, + const SCEV *FoundLHS, + const SCEV *FoundRHS) { + auto IsKnownPredicateFull = [this](Predicate Pred, const SCEV *LHS, + const SCEV *RHS) { return isKnownPredicateViaConstantRanges(Pred, LHS, RHS) || IsKnownPredicateViaMinOrMax(*this, Pred, LHS, RHS) || IsKnownPredicateViaAddRecStart(*this, Pred, LHS, RHS) || isKnownPredicateViaNoOverflow(Pred, LHS, RHS); }; - switch (Pred) { - default: llvm_unreachable("Unexpected ICmpInst::Predicate value!"); - case ICmpInst::ICMP_EQ: - case ICmpInst::ICMP_NE: + switch (Pred.getKind()) { + default: + llvm_unreachable("Unexpected Predicate value!"); + case Predicate::ICMP_EQ: + case Predicate::ICMP_NE: if (HasSameValue(LHS, FoundLHS) && HasSameValue(RHS, FoundRHS)) return true; break; - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_SLE: - if (IsKnownPredicateFull(ICmpInst::ICMP_SLE, LHS, FoundLHS) && - IsKnownPredicateFull(ICmpInst::ICMP_SGE, RHS, FoundRHS)) + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: + if (IsKnownPredicateFull(Predicate::ICMP_SLE, LHS, FoundLHS) && + IsKnownPredicateFull(Predicate::ICMP_SGE, RHS, FoundRHS)) return true; break; - case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_SGE: - if (IsKnownPredicateFull(ICmpInst::ICMP_SGE, LHS, FoundLHS) && - IsKnownPredicateFull(ICmpInst::ICMP_SLE, RHS, FoundRHS)) + case Predicate::ICMP_SGT: + case Predicate::ICMP_SGE: + if (IsKnownPredicateFull(Predicate::ICMP_SGE, LHS, FoundLHS) && + IsKnownPredicateFull(Predicate::ICMP_SLE, RHS, FoundRHS)) return true; break; - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_ULE: - if (IsKnownPredicateFull(ICmpInst::ICMP_ULE, LHS, FoundLHS) && - IsKnownPredicateFull(ICmpInst::ICMP_UGE, RHS, FoundRHS)) + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: + if (IsKnownPredicateFull(Predicate::ICMP_ULE, LHS, FoundLHS) && + IsKnownPredicateFull(Predicate::ICMP_UGE, RHS, FoundRHS)) return true; break; - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_UGE: - if (IsKnownPredicateFull(ICmpInst::ICMP_UGE, LHS, FoundLHS) && - IsKnownPredicateFull(ICmpInst::ICMP_ULE, RHS, FoundRHS)) + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: + if (IsKnownPredicateFull(Predicate::ICMP_UGE, LHS, FoundLHS) && + IsKnownPredicateFull(Predicate::ICMP_ULE, RHS, FoundRHS)) return true; break; } @@ -8531,7 +8520,7 @@ return false; } -bool ScalarEvolution::isImpliedCondOperandsViaRanges(ICmpInst::Predicate Pred, +bool ScalarEvolution::isImpliedCondOperandsViaRanges(Predicate Pred, const SCEV *LHS, const SCEV *RHS, const SCEV *FoundLHS, @@ -8662,8 +8651,7 @@ if (!Stride->isOne() && doesIVOverflowOnLT(RHS, Stride, IsSigned, NoWrap)) return getCouldNotCompute(); - ICmpInst::Predicate Cond = IsSigned ? ICmpInst::ICMP_SLT - : ICmpInst::ICMP_ULT; + Predicate Cond = IsSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT; const SCEV *Start = IV->getStart(); const SCEV *End = RHS; if (!isLoopEntryGuardedByCond(L, Cond, getMinusSCEV(Start, Stride), RHS)) @@ -8737,8 +8725,7 @@ if (!Stride->isOne() && doesIVOverflowOnGT(RHS, Stride, IsSigned, NoWrap)) return getCouldNotCompute(); - ICmpInst::Predicate Cond = IsSigned ? ICmpInst::ICMP_SGT - : ICmpInst::ICMP_UGT; + Predicate Cond = IsSigned ? Predicate::ICMP_SGT : Predicate::ICMP_UGT; const SCEV *Start = IV->getStart(); const SCEV *End = RHS; @@ -8858,7 +8845,7 @@ const SCEVConstant *R2 = Roots->second; // Pick the smallest positive root value. if (ConstantInt *CB = dyn_cast(ConstantExpr::getICmp( - ICmpInst::ICMP_ULT, R1->getValue(), R2->getValue()))) { + Predicate::ICMP_ULT, R1->getValue(), R2->getValue()))) { if (!CB->getZExtValue()) std::swap(R1, R2); // R1 is the minimum root now. Index: lib/Analysis/ScalarEvolutionExpander.cpp =================================================================== --- lib/Analysis/ScalarEvolutionExpander.cpp +++ lib/Analysis/ScalarEvolutionExpander.cpp @@ -1897,7 +1897,7 @@ // Look for suitable value in simple conditions at the loop exits. for (BasicBlock *BB : ExitingBlocks) { - ICmpInst::Predicate Pred; + Predicate Pred; Instruction *LHS, *RHS; BasicBlock *TrueBB, *FalseBB; @@ -2067,7 +2067,7 @@ Builder.SetInsertPoint(Loc); // Compute |Step| - Value *StepCompare = Builder.CreateICmp(ICmpInst::ICMP_SLT, StepValue, Zero); + Value *StepCompare = Builder.CreateICmp(Predicate::ICMP_SLT, StepValue, Zero); Value *AbsStep = Builder.CreateSelect(StepCompare, NegStepValue, StepValue); // Get the backedge taken count and truncate or extended to the AR type. @@ -2087,10 +2087,10 @@ Value *Sub = Builder.CreateSub(StartValue, MulV); Value *EndCompareGT = Builder.CreateICmp( - Signed ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT, Sub, StartValue); + Signed ? Predicate::ICMP_SGT : Predicate::ICMP_UGT, Sub, StartValue); Value *EndCompareLT = Builder.CreateICmp( - Signed ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, Add, StartValue); + Signed ? Predicate::ICMP_SLT : Predicate::ICMP_ULT, Add, StartValue); // Select the answer based on the sign of Step. Value *EndCheck = @@ -2102,10 +2102,10 @@ if (SE.getTypeSizeInBits(CountTy) > SE.getTypeSizeInBits(Ty)) { auto MaxVal = APInt::getMaxValue(DstBits).zext(SrcBits); auto *BackedgeCheck = - Builder.CreateICmp(ICmpInst::ICMP_UGT, TripCountVal, + Builder.CreateICmp(Predicate::ICMP_UGT, TripCountVal, ConstantInt::get(Loc->getContext(), MaxVal)); BackedgeCheck = Builder.CreateAnd( - BackedgeCheck, Builder.CreateICmp(ICmpInst::ICMP_NE, StepValue, Zero)); + BackedgeCheck, Builder.CreateICmp(Predicate::ICMP_NE, StepValue, Zero)); EndCheck = Builder.CreateOr(EndCheck, BackedgeCheck); } Index: lib/Analysis/ValueTracking.cpp =================================================================== --- lib/Analysis/ValueTracking.cpp +++ lib/Analysis/ValueTracking.cpp @@ -560,11 +560,12 @@ m_CombineOr(m_PtrToInt(m_Specific(V)), m_BitCast(m_Specific(V)))); - CmpInst::Predicate Pred; + Predicate Pred; ConstantInt *C; // assume(v = a) if (match(Arg, m_c_ICmp(Pred, m_V, m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { + Pred == Predicate::ICMP_EQ && + isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); KnownZero |= RHSKnownZero; @@ -572,7 +573,7 @@ // assume(v & b = a) } else if (match(Arg, m_c_ICmp(Pred, m_c_And(m_V, m_Value(B)), m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && + Pred == Predicate::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -586,7 +587,7 @@ // assume(~(v & b) = a) } else if (match(Arg, m_c_ICmp(Pred, m_Not(m_c_And(m_V, m_Value(B))), m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && + Pred == Predicate::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -600,7 +601,7 @@ // assume(v | b = a) } else if (match(Arg, m_c_ICmp(Pred, m_c_Or(m_V, m_Value(B)), m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && + Pred == Predicate::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -614,7 +615,7 @@ // assume(~(v | b) = a) } else if (match(Arg, m_c_ICmp(Pred, m_Not(m_c_Or(m_V, m_Value(B))), m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && + Pred == Predicate::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -628,7 +629,7 @@ // assume(v ^ b = a) } else if (match(Arg, m_c_ICmp(Pred, m_c_Xor(m_V, m_Value(B)), m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && + Pred == Predicate::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -645,7 +646,7 @@ // assume(~(v ^ b) = a) } else if (match(Arg, m_c_ICmp(Pred, m_Not(m_c_Xor(m_V, m_Value(B))), m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && + Pred == Predicate::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -662,7 +663,7 @@ // assume(v << c = a) } else if (match(Arg, m_c_ICmp(Pred, m_Shl(m_V, m_ConstantInt(C)), m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && + Pred == Predicate::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -673,7 +674,7 @@ // assume(~(v << c) = a) } else if (match(Arg, m_c_ICmp(Pred, m_Not(m_Shl(m_V, m_ConstantInt(C))), m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && + Pred == Predicate::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -686,7 +687,7 @@ m_c_ICmp(Pred, m_CombineOr(m_LShr(m_V, m_ConstantInt(C)), m_AShr(m_V, m_ConstantInt(C))), m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && + Pred == Predicate::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -699,7 +700,7 @@ m_LShr(m_V, m_ConstantInt(C)), m_AShr(m_V, m_ConstantInt(C)))), m_Value(A))) && - Pred == ICmpInst::ICMP_EQ && + Pred == Predicate::ICMP_EQ && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -709,7 +710,7 @@ KnownOne |= RHSKnownZero << C->getZExtValue(); // assume(v >=_s c) where c is non-negative } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) && - Pred == ICmpInst::ICMP_SGE && + Pred == Predicate::ICMP_SGE && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -720,7 +721,7 @@ } // assume(v >_s c) where c is at least -1. } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) && - Pred == ICmpInst::ICMP_SGT && + Pred == Predicate::ICMP_SGT && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -731,7 +732,7 @@ } // assume(v <=_s c) where c is negative } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) && - Pred == ICmpInst::ICMP_SLE && + Pred == Predicate::ICMP_SLE && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -742,7 +743,7 @@ } // assume(v <_s c) where c is non-positive } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) && - Pred == ICmpInst::ICMP_SLT && + Pred == Predicate::ICMP_SLT && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -753,7 +754,7 @@ } // assume(v <=_u c) } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) && - Pred == ICmpInst::ICMP_ULE && + Pred == Predicate::ICMP_ULE && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -763,7 +764,7 @@ APInt::getHighBitsSet(BitWidth, RHSKnownZero.countLeadingOnes()); // assume(v <_u c) } else if (match(Arg, m_ICmp(Pred, m_V, m_Value(A))) && - Pred == ICmpInst::ICMP_ULT && + Pred == Predicate::ICMP_ULT && isValidAssumeForContext(I, Q.CxtI, Q.DT)) { APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0); computeKnownBits(A, RHSKnownZero, RHSKnownOne, Depth+1, Query(Q, I)); @@ -3287,10 +3288,10 @@ break; NumUsesExplored++; // Consider only compare instructions uniquely controlling a branch - CmpInst::Predicate Pred; + Predicate Pred; if (!match(const_cast(U), m_c_ICmp(Pred, m_Specific(V), m_Zero())) || - (Pred != ICmpInst::ICMP_EQ && Pred != ICmpInst::ICMP_NE)) + (Pred != Predicate::ICMP_EQ && Pred != Predicate::ICMP_NE)) continue; for (auto *CmpU : U->users()) { @@ -3298,11 +3299,11 @@ assert(BI->isConditional() && "uses a comparison!"); BasicBlock *NonNullSuccessor = - BI->getSuccessor(Pred == ICmpInst::ICMP_EQ ? 1 : 0); + BI->getSuccessor(Pred == Predicate::ICMP_EQ ? 1 : 0); BasicBlockEdge Edge(BI->getParent(), NonNullSuccessor); if (Edge.isSingleEdge() && DT->dominates(Edge, CtxI->getParent())) return true; - } else if (Pred == ICmpInst::ICMP_NE && + } else if (Pred == Predicate::ICMP_NE && match(CmpU, m_Intrinsic()) && DT->dominates(cast(CmpU), CtxI)) { return true; @@ -3752,8 +3753,7 @@ return false; } -static SelectPatternResult matchSelectPattern(CmpInst::Predicate Pred, - FastMathFlags FMF, +static SelectPatternResult matchSelectPattern(Predicate Pred, FastMathFlags FMF, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS) { @@ -3766,10 +3766,12 @@ // minNum(0.0, -0.0) // May return -0.0 or 0.0 (IEEE 754-2008 5.3.1) // Therefore we behave conservatively and only proceed if at least one of the // operands is known to not be zero, or if we don't care about signed zeroes. - switch (Pred) { + switch (Pred.getKind()) { default: break; - case CmpInst::FCMP_OGE: case CmpInst::FCMP_OLE: - case CmpInst::FCMP_UGE: case CmpInst::FCMP_ULE: + case Predicate::FCMP_OGE: + case Predicate::FCMP_OLE: + case Predicate::FCMP_UGE: + case Predicate::FCMP_ULE: if (!FMF.noSignedZeros() && !isKnownNonZero(CmpLHS) && !isKnownNonZero(CmpRHS)) return {SPF_UNKNOWN, SPNB_NA, false}; @@ -3783,14 +3785,14 @@ // - A simple C99 (a < b ? a : b) construction will return 'b' (as the // ordered comparison fails), which could be NaN or non-NaN. // so here we discover exactly what NaN behavior is required/accepted. - if (CmpInst::isFPPredicate(Pred)) { + if (Pred.isFP()) { bool LHSSafe = isKnownNonNaN(CmpLHS, FMF); bool RHSSafe = isKnownNonNaN(CmpRHS, FMF); if (LHSSafe && RHSSafe) { // Both operands are known non-NaN. NaNBehavior = SPNB_RETURNS_ANY; - } else if (CmpInst::isOrdered(Pred)) { + } else if (Pred.isOrdered()) { // An ordered comparison will return false when given a NaN, so it // returns the RHS. Ordered = true; @@ -3819,7 +3821,7 @@ if (TrueVal == CmpRHS && FalseVal == CmpLHS) { std::swap(CmpLHS, CmpRHS); - Pred = CmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); if (NaNBehavior == SPNB_RETURNS_NAN) NaNBehavior = SPNB_RETURNS_OTHER; else if (NaNBehavior == SPNB_RETURNS_OTHER) @@ -3829,24 +3831,30 @@ // ([if]cmp X, Y) ? X : Y if (TrueVal == CmpLHS && FalseVal == CmpRHS) { - switch (Pred) { + switch (Pred.getKind()) { default: return {SPF_UNKNOWN, SPNB_NA, false}; // Equality. - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_UGE: return {SPF_UMAX, SPNB_NA, false}; - case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_SGE: return {SPF_SMAX, SPNB_NA, false}; - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_ULE: return {SPF_UMIN, SPNB_NA, false}; - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_SLE: return {SPF_SMIN, SPNB_NA, false}; - case FCmpInst::FCMP_UGT: - case FCmpInst::FCMP_UGE: - case FCmpInst::FCMP_OGT: - case FCmpInst::FCMP_OGE: return {SPF_FMAXNUM, NaNBehavior, Ordered}; - case FCmpInst::FCMP_ULT: - case FCmpInst::FCMP_ULE: - case FCmpInst::FCMP_OLT: - case FCmpInst::FCMP_OLE: return {SPF_FMINNUM, NaNBehavior, Ordered}; + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: + return {SPF_UMAX, SPNB_NA, false}; + case Predicate::ICMP_SGT: + case Predicate::ICMP_SGE: + return {SPF_SMAX, SPNB_NA, false}; + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: + return {SPF_UMIN, SPNB_NA, false}; + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: + return {SPF_SMIN, SPNB_NA, false}; + case Predicate::FCMP_UGT: + case Predicate::FCMP_UGE: + case Predicate::FCMP_OGT: + case Predicate::FCMP_OGE: + return {SPF_FMAXNUM, NaNBehavior, Ordered}; + case Predicate::FCMP_ULT: + case Predicate::FCMP_ULE: + case Predicate::FCMP_OLT: + case Predicate::FCMP_OLE: + return {SPF_FMINNUM, NaNBehavior, Ordered}; } } @@ -3856,20 +3864,20 @@ // ABS(X) ==> (X >s 0) ? X : -X and (X >s -1) ? X : -X // NABS(X) ==> (X >s 0) ? -X : X and (X >s -1) ? -X : X - if (Pred == ICmpInst::ICMP_SGT && (C1->isZero() || C1->isMinusOne())) { + if (Pred == Predicate::ICMP_SGT && (C1->isZero() || C1->isMinusOne())) { return {(CmpLHS == TrueVal) ? SPF_ABS : SPF_NABS, SPNB_NA, false}; } // ABS(X) ==> (X (X isZero() || C1->isOne())) { + if (Pred == Predicate::ICMP_SLT && (C1->isZero() || C1->isOne())) { return {(CmpLHS == FalseVal) ? SPF_ABS : SPF_NABS, SPNB_NA, false}; } } // Y >s C ? ~Y : ~C == ~Y (FalseVal)) { - if (Pred == ICmpInst::ICMP_SGT && C1->getType() == C2->getType() && + if (Pred == Predicate::ICMP_SGT && C1->getType() == C2->getType() && ~C1->getValue() == C2->getValue() && (match(TrueVal, m_Not(m_Specific(CmpLHS))) || match(CmpLHS, m_Not(m_Specific(TrueVal))))) { @@ -3953,7 +3961,7 @@ CmpInst *CmpI = dyn_cast(SI->getCondition()); if (!CmpI) return {SPF_UNKNOWN, SPNB_NA, false}; - CmpInst::Predicate Pred = CmpI->getPredicate(); + Predicate Pred = CmpI->getPredicate(); Value *CmpLHS = CmpI->getOperand(0); Value *CmpRHS = CmpI->getOperand(1); Value *TrueVal = SI->getTrueValue(); @@ -4004,19 +4012,19 @@ } /// Return true if "icmp Pred LHS RHS" is always true. -static bool isTruePredicate(CmpInst::Predicate Pred, Value *LHS, Value *RHS, +static bool isTruePredicate(Predicate Pred, Value *LHS, Value *RHS, const DataLayout &DL, unsigned Depth, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT) { assert(!LHS->getType()->isVectorTy() && "TODO: extend to handle vectors!"); - if (ICmpInst::isTrueWhenEqual(Pred) && LHS == RHS) + if (Pred.isTrueWhenEqual() && LHS == RHS) return true; - switch (Pred) { + switch (Pred.getKind()) { default: return false; - case CmpInst::ICMP_SLE: { + case Predicate::ICMP_SLE: { const APInt *C; // LHS s<= LHS +_{nsw} C if C >= 0 @@ -4025,7 +4033,7 @@ return false; } - case CmpInst::ICMP_ULE: { + case Predicate::ICMP_ULE: { const APInt *C; // LHS u<= LHS +_{nuw} C for any C @@ -4065,28 +4073,31 @@ /// Return true if "icmp Pred BLHS BRHS" is true whenever "icmp Pred /// ALHS ARHS" is true. Otherwise, return None. -static Optional -isImpliedCondOperands(CmpInst::Predicate Pred, Value *ALHS, Value *ARHS, - Value *BLHS, Value *BRHS, const DataLayout &DL, - unsigned Depth, AssumptionCache *AC, - const Instruction *CxtI, const DominatorTree *DT) { - switch (Pred) { +static Optional isImpliedCondOperands(Predicate Pred, Value *ALHS, + Value *ARHS, Value *BLHS, + Value *BRHS, const DataLayout &DL, + unsigned Depth, AssumptionCache *AC, + const Instruction *CxtI, + const DominatorTree *DT) { + switch (Pred.getKind()) { default: return None; - case CmpInst::ICMP_SLT: - case CmpInst::ICMP_SLE: - if (isTruePredicate(CmpInst::ICMP_SLE, BLHS, ALHS, DL, Depth, AC, CxtI, + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: + if (isTruePredicate(Predicate::ICMP_SLE, BLHS, ALHS, DL, Depth, AC, CxtI, DT) && - isTruePredicate(CmpInst::ICMP_SLE, ARHS, BRHS, DL, Depth, AC, CxtI, DT)) + isTruePredicate(Predicate::ICMP_SLE, ARHS, BRHS, DL, Depth, AC, CxtI, + DT)) return true; return None; - case CmpInst::ICMP_ULT: - case CmpInst::ICMP_ULE: - if (isTruePredicate(CmpInst::ICMP_ULE, BLHS, ALHS, DL, Depth, AC, CxtI, + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: + if (isTruePredicate(Predicate::ICMP_ULE, BLHS, ALHS, DL, Depth, AC, CxtI, DT) && - isTruePredicate(CmpInst::ICMP_ULE, ARHS, BRHS, DL, Depth, AC, CxtI, DT)) + isTruePredicate(Predicate::ICMP_ULE, ARHS, BRHS, DL, Depth, AC, CxtI, + DT)) return true; return None; } @@ -4105,19 +4116,19 @@ /// Return true if "icmp1 APred ALHS ARHS" implies "icmp2 BPred BLHS BRHS" is /// true. Return false if "icmp1 APred ALHS ARHS" implies "icmp2 BPred BLHS /// BRHS" is false. Otherwise, return None if we can't infer anything. -static Optional isImpliedCondMatchingOperands(CmpInst::Predicate APred, +static Optional isImpliedCondMatchingOperands(Predicate APred, Value *ALHS, Value *ARHS, - CmpInst::Predicate BPred, + Predicate BPred, Value *BLHS, Value *BRHS, bool IsSwappedOps) { // Canonicalize the operands so they're matching. if (IsSwappedOps) { std::swap(BLHS, BRHS); - BPred = ICmpInst::getSwappedPredicate(BPred); + BPred = BPred.getSwapped(); } - if (CmpInst::isImpliedTrueByMatchingCmp(APred, BPred)) + if (APred.isImpliedTrueByMatchingCmp(BPred)) return true; - if (CmpInst::isImpliedFalseByMatchingCmp(APred, BPred)) + if (APred.isImpliedFalseByMatchingCmp(BPred)) return false; return None; @@ -4127,9 +4138,9 @@ /// true. Return false if "icmp1 APred ALHS C1" implies "icmp2 BPred BLHS /// C2" is false. Otherwise, return None if we can't infer anything. static Optional -isImpliedCondMatchingImmOperands(CmpInst::Predicate APred, Value *ALHS, - ConstantInt *C1, CmpInst::Predicate BPred, - Value *BLHS, ConstantInt *C2) { +isImpliedCondMatchingImmOperands(Predicate APred, Value *ALHS, ConstantInt *C1, + Predicate BPred, Value *BLHS, + ConstantInt *C2) { assert(ALHS == BLHS && "LHS operands must match."); ConstantRange DomCR = ConstantRange::makeExactICmpRegion(APred, C1->getValue()); @@ -4165,7 +4176,7 @@ return None; assert(OpTy->isIntegerTy(1) && "implied by above"); - ICmpInst::Predicate APred, BPred; + Predicate APred, BPred; Value *ALHS, *ARHS; Value *BLHS, *BRHS; @@ -4174,7 +4185,7 @@ return None; if (InvertAPred) - APred = CmpInst::getInversePredicate(APred); + APred = APred.getInverse(); // Can we infer anything when the two compares have matching operands? bool IsSwappedOps; Index: lib/AsmParser/LLParser.cpp =================================================================== --- lib/AsmParser/LLParser.cpp +++ lib/AsmParser/LLParser.cpp @@ -3007,7 +3007,7 @@ if (Val0->getType() != Val1->getType()) return Error(ID.Loc, "compare operands must have the same type"); - CmpInst::Predicate Pred = (CmpInst::Predicate)PredVal; + Predicate Pred{PredVal}; if (Opc == Instruction::FCmp) { if (!Val0->getType()->isFPOrFPVectorTy()) @@ -5050,36 +5050,88 @@ if (Opc == Instruction::FCmp) { switch (Lex.getKind()) { default: return TokError("expected fcmp predicate (e.g. 'oeq')"); - case lltok::kw_oeq: P = CmpInst::FCMP_OEQ; break; - case lltok::kw_one: P = CmpInst::FCMP_ONE; break; - case lltok::kw_olt: P = CmpInst::FCMP_OLT; break; - case lltok::kw_ogt: P = CmpInst::FCMP_OGT; break; - case lltok::kw_ole: P = CmpInst::FCMP_OLE; break; - case lltok::kw_oge: P = CmpInst::FCMP_OGE; break; - case lltok::kw_ord: P = CmpInst::FCMP_ORD; break; - case lltok::kw_uno: P = CmpInst::FCMP_UNO; break; - case lltok::kw_ueq: P = CmpInst::FCMP_UEQ; break; - case lltok::kw_une: P = CmpInst::FCMP_UNE; break; - case lltok::kw_ult: P = CmpInst::FCMP_ULT; break; - case lltok::kw_ugt: P = CmpInst::FCMP_UGT; break; - case lltok::kw_ule: P = CmpInst::FCMP_ULE; break; - case lltok::kw_uge: P = CmpInst::FCMP_UGE; break; - case lltok::kw_true: P = CmpInst::FCMP_TRUE; break; - case lltok::kw_false: P = CmpInst::FCMP_FALSE; break; + case lltok::kw_oeq: + P = Predicate::FCMP_OEQ; + break; + case lltok::kw_one: + P = Predicate::FCMP_ONE; + break; + case lltok::kw_olt: + P = Predicate::FCMP_OLT; + break; + case lltok::kw_ogt: + P = Predicate::FCMP_OGT; + break; + case lltok::kw_ole: + P = Predicate::FCMP_OLE; + break; + case lltok::kw_oge: + P = Predicate::FCMP_OGE; + break; + case lltok::kw_ord: + P = Predicate::FCMP_ORD; + break; + case lltok::kw_uno: + P = Predicate::FCMP_UNO; + break; + case lltok::kw_ueq: + P = Predicate::FCMP_UEQ; + break; + case lltok::kw_une: + P = Predicate::FCMP_UNE; + break; + case lltok::kw_ult: + P = Predicate::FCMP_ULT; + break; + case lltok::kw_ugt: + P = Predicate::FCMP_UGT; + break; + case lltok::kw_ule: + P = Predicate::FCMP_ULE; + break; + case lltok::kw_uge: + P = Predicate::FCMP_UGE; + break; + case lltok::kw_true: + P = Predicate::FCMP_TRUE; + break; + case lltok::kw_false: + P = Predicate::FCMP_FALSE; + break; } } else { switch (Lex.getKind()) { default: return TokError("expected icmp predicate (e.g. 'eq')"); - case lltok::kw_eq: P = CmpInst::ICMP_EQ; break; - case lltok::kw_ne: P = CmpInst::ICMP_NE; break; - case lltok::kw_slt: P = CmpInst::ICMP_SLT; break; - case lltok::kw_sgt: P = CmpInst::ICMP_SGT; break; - case lltok::kw_sle: P = CmpInst::ICMP_SLE; break; - case lltok::kw_sge: P = CmpInst::ICMP_SGE; break; - case lltok::kw_ult: P = CmpInst::ICMP_ULT; break; - case lltok::kw_ugt: P = CmpInst::ICMP_UGT; break; - case lltok::kw_ule: P = CmpInst::ICMP_ULE; break; - case lltok::kw_uge: P = CmpInst::ICMP_UGE; break; + case lltok::kw_eq: + P = Predicate::ICMP_EQ; + break; + case lltok::kw_ne: + P = Predicate::ICMP_NE; + break; + case lltok::kw_slt: + P = Predicate::ICMP_SLT; + break; + case lltok::kw_sgt: + P = Predicate::ICMP_SGT; + break; + case lltok::kw_sle: + P = Predicate::ICMP_SLE; + break; + case lltok::kw_sge: + P = Predicate::ICMP_SGE; + break; + case lltok::kw_ult: + P = Predicate::ICMP_ULT; + break; + case lltok::kw_ugt: + P = Predicate::ICMP_UGT; + break; + case lltok::kw_ule: + P = Predicate::ICMP_ULE; + break; + case lltok::kw_uge: + P = Predicate::ICMP_UGE; + break; } } Lex.Lex(); @@ -5603,13 +5655,13 @@ if (Opc == Instruction::FCmp) { if (!LHS->getType()->isFPOrFPVectorTy()) return Error(Loc, "fcmp requires floating point operands"); - Inst = new FCmpInst(CmpInst::Predicate(Pred), LHS, RHS); + Inst = new FCmpInst(Predicate{Pred}, LHS, RHS); } else { assert(Opc == Instruction::ICmp && "Unknown opcode for CmpInst!"); if (!LHS->getType()->isIntOrIntVectorTy() && !LHS->getType()->getScalarType()->isPointerTy()) return Error(Loc, "icmp requires integer operands"); - Inst = new ICmpInst(CmpInst::Predicate(Pred), LHS, RHS); + Inst = new ICmpInst(Predicate{Pred}, LHS, RHS); } return false; } Index: lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- lib/Bitcode/Reader/BitcodeReader.cpp +++ lib/Bitcode/Reader/BitcodeReader.cpp @@ -3223,9 +3223,9 @@ Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy); if (OpTy->isFPOrFPVectorTy()) - V = ConstantExpr::getFCmp(Record[3], Op0, Op1); + V = ConstantExpr::getFCmp(static_cast(Record[3]), Op0, Op1); else - V = ConstantExpr::getICmp(Record[3], Op0, Op1); + V = ConstantExpr::getICmp(static_cast(Record[3]), Op0, Op1); break; } // This maintains backward compatibility, pre-asm dialect keywords. @@ -4806,7 +4806,7 @@ popValue(Record, OpNum, NextValueNo, LHS->getType(), RHS)) return error("Invalid record"); - unsigned PredVal = Record[OpNum]; + Predicate PredVal = static_cast(Record[OpNum]); bool IsFP = LHS->getType()->isFPOrFPVectorTy(); FastMathFlags FMF; if (IsFP && Record.size() > OpNum+1) @@ -4816,9 +4816,9 @@ return error("Invalid record"); if (LHS->getType()->isFPOrFPVectorTy()) - I = new FCmpInst((FCmpInst::Predicate)PredVal, LHS, RHS); + I = new FCmpInst(PredVal, LHS, RHS); else - I = new ICmpInst((ICmpInst::Predicate)PredVal, LHS, RHS); + I = new ICmpInst(PredVal, LHS, RHS); if (FMF.any()) I->setFastMathFlags(FMF); Index: lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitcodeWriter.cpp +++ lib/Bitcode/Writer/BitcodeWriter.cpp @@ -2250,7 +2250,7 @@ Record.push_back(VE.getTypeID(C->getOperand(0)->getType())); Record.push_back(VE.getValueID(C->getOperand(0))); Record.push_back(VE.getValueID(C->getOperand(1))); - Record.push_back(CE->getPredicate()); + Record.push_back(CE->getPredicate().getKind()); break; } } else if (const BlockAddress *BA = dyn_cast(C)) { @@ -2421,7 +2421,7 @@ Code = bitc::FUNC_CODE_INST_CMP2; pushValueAndType(I.getOperand(0), InstID, Vals); pushValue(I.getOperand(1), InstID, Vals); - Vals.push_back(cast(I).getPredicate()); + Vals.push_back(cast(I).getPredicate().getKind()); uint64_t Flags = getOptimizationFlags(&I); if (Flags != 0) Vals.push_back(Flags); Index: lib/CodeGen/Analysis.cpp =================================================================== --- lib/CodeGen/Analysis.cpp +++ lib/CodeGen/Analysis.cpp @@ -159,24 +159,40 @@ /// the given LLVM IR floating-point condition code. This includes /// consideration of global floating-point math flags. /// -ISD::CondCode llvm::getFCmpCondCode(FCmpInst::Predicate Pred) { - switch (Pred) { - case FCmpInst::FCMP_FALSE: return ISD::SETFALSE; - case FCmpInst::FCMP_OEQ: return ISD::SETOEQ; - case FCmpInst::FCMP_OGT: return ISD::SETOGT; - case FCmpInst::FCMP_OGE: return ISD::SETOGE; - case FCmpInst::FCMP_OLT: return ISD::SETOLT; - case FCmpInst::FCMP_OLE: return ISD::SETOLE; - case FCmpInst::FCMP_ONE: return ISD::SETONE; - case FCmpInst::FCMP_ORD: return ISD::SETO; - case FCmpInst::FCMP_UNO: return ISD::SETUO; - case FCmpInst::FCMP_UEQ: return ISD::SETUEQ; - case FCmpInst::FCMP_UGT: return ISD::SETUGT; - case FCmpInst::FCMP_UGE: return ISD::SETUGE; - case FCmpInst::FCMP_ULT: return ISD::SETULT; - case FCmpInst::FCMP_ULE: return ISD::SETULE; - case FCmpInst::FCMP_UNE: return ISD::SETUNE; - case FCmpInst::FCMP_TRUE: return ISD::SETTRUE; +ISD::CondCode llvm::getFCmpCondCode(Predicate Pred) { + switch (Pred.getKind()) { + case Predicate::FCMP_FALSE: + return ISD::SETFALSE; + case Predicate::FCMP_OEQ: + return ISD::SETOEQ; + case Predicate::FCMP_OGT: + return ISD::SETOGT; + case Predicate::FCMP_OGE: + return ISD::SETOGE; + case Predicate::FCMP_OLT: + return ISD::SETOLT; + case Predicate::FCMP_OLE: + return ISD::SETOLE; + case Predicate::FCMP_ONE: + return ISD::SETONE; + case Predicate::FCMP_ORD: + return ISD::SETO; + case Predicate::FCMP_UNO: + return ISD::SETUO; + case Predicate::FCMP_UEQ: + return ISD::SETUEQ; + case Predicate::FCMP_UGT: + return ISD::SETUGT; + case Predicate::FCMP_UGE: + return ISD::SETUGE; + case Predicate::FCMP_ULT: + return ISD::SETULT; + case Predicate::FCMP_ULE: + return ISD::SETULE; + case Predicate::FCMP_UNE: + return ISD::SETUNE; + case Predicate::FCMP_TRUE: + return ISD::SETTRUE; default: llvm_unreachable("Invalid FCmp predicate opcode!"); } } @@ -196,18 +212,28 @@ /// getICmpCondCode - Return the ISD condition code corresponding to /// the given LLVM IR integer condition code. /// -ISD::CondCode llvm::getICmpCondCode(ICmpInst::Predicate Pred) { - switch (Pred) { - case ICmpInst::ICMP_EQ: return ISD::SETEQ; - case ICmpInst::ICMP_NE: return ISD::SETNE; - case ICmpInst::ICMP_SLE: return ISD::SETLE; - case ICmpInst::ICMP_ULE: return ISD::SETULE; - case ICmpInst::ICMP_SGE: return ISD::SETGE; - case ICmpInst::ICMP_UGE: return ISD::SETUGE; - case ICmpInst::ICMP_SLT: return ISD::SETLT; - case ICmpInst::ICMP_ULT: return ISD::SETULT; - case ICmpInst::ICMP_SGT: return ISD::SETGT; - case ICmpInst::ICMP_UGT: return ISD::SETUGT; +ISD::CondCode llvm::getICmpCondCode(Predicate Pred) { + switch (Pred.getKind()) { + case Predicate::ICMP_EQ: + return ISD::SETEQ; + case Predicate::ICMP_NE: + return ISD::SETNE; + case Predicate::ICMP_SLE: + return ISD::SETLE; + case Predicate::ICMP_ULE: + return ISD::SETULE; + case Predicate::ICMP_SGE: + return ISD::SETGE; + case Predicate::ICMP_UGE: + return ISD::SETUGE; + case Predicate::ICMP_SLT: + return ISD::SETLT; + case Predicate::ICMP_ULT: + return ISD::SETULT; + case Predicate::ICMP_SGT: + return ISD::SETGT; + case Predicate::ICMP_UGT: + return ISD::SETUGT; default: llvm_unreachable("Invalid ICmp predicate opcode!"); } Index: lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- lib/CodeGen/CodeGenPrepare.cpp +++ lib/CodeGen/CodeGenPrepare.cpp @@ -1257,7 +1257,7 @@ } Value *Predicate = Builder.CreateExtractElement(Mask, Builder.getInt32(Idx)); - Value *Cmp = Builder.CreateICmp(ICmpInst::ICMP_EQ, Predicate, + Value *Cmp = Builder.CreateICmp(Predicate::ICMP_EQ, Predicate, ConstantInt::get(Predicate->getType(), 1)); // Create "cond" block @@ -1379,7 +1379,7 @@ // br i1 %to_store, label %cond.store, label %else // Value *Predicate = Builder.CreateExtractElement(Mask, Builder.getInt32(Idx)); - Value *Cmp = Builder.CreateICmp(ICmpInst::ICMP_EQ, Predicate, + Value *Cmp = Builder.CreateICmp(Predicate::ICMP_EQ, Predicate, ConstantInt::get(Predicate->getType(), 1)); // Create "cond" block @@ -1509,7 +1509,7 @@ Value *Predicate = Builder.CreateExtractElement(Mask, Builder.getInt32(Idx), "Mask" + Twine(Idx)); - Value *Cmp = Builder.CreateICmp(ICmpInst::ICMP_EQ, Predicate, + Value *Cmp = Builder.CreateICmp(Predicate::ICMP_EQ, Predicate, ConstantInt::get(Predicate->getType(), 1), "ToLoad" + Twine(Idx)); @@ -1622,10 +1622,9 @@ Value *Predicate = Builder.CreateExtractElement(Mask, Builder.getInt32(Idx), "Mask" + Twine(Idx)); - Value *Cmp = - Builder.CreateICmp(ICmpInst::ICMP_EQ, Predicate, - ConstantInt::get(Predicate->getType(), 1), - "ToStore" + Twine(Idx)); + Value *Cmp = Builder.CreateICmp(Predicate::ICMP_EQ, Predicate, + ConstantInt::get(Predicate->getType(), 1), + "ToStore" + Twine(Idx)); // Create "cond" block // Index: lib/CodeGen/SelectionDAG/FastISel.cpp =================================================================== --- lib/CodeGen/SelectionDAG/FastISel.cpp +++ lib/CodeGen/SelectionDAG/FastISel.cpp @@ -2204,42 +2204,94 @@ Alignment, AAInfo, Ranges); } -CmpInst::Predicate FastISel::optimizeCmpPredicate(const CmpInst *CI) const { +Predicate FastISel::optimizeCmpPredicate(const CmpInst *CI) const { // If both operands are the same, then try to optimize or fold the cmp. - CmpInst::Predicate Predicate = CI->getPredicate(); + Predicate Pred = CI->getPredicate(); if (CI->getOperand(0) != CI->getOperand(1)) - return Predicate; + return Pred; - switch (Predicate) { + switch (Pred.getKind()) { default: llvm_unreachable("Invalid predicate!"); - case CmpInst::FCMP_FALSE: Predicate = CmpInst::FCMP_FALSE; break; - case CmpInst::FCMP_OEQ: Predicate = CmpInst::FCMP_ORD; break; - case CmpInst::FCMP_OGT: Predicate = CmpInst::FCMP_FALSE; break; - case CmpInst::FCMP_OGE: Predicate = CmpInst::FCMP_ORD; break; - case CmpInst::FCMP_OLT: Predicate = CmpInst::FCMP_FALSE; break; - case CmpInst::FCMP_OLE: Predicate = CmpInst::FCMP_ORD; break; - case CmpInst::FCMP_ONE: Predicate = CmpInst::FCMP_FALSE; break; - case CmpInst::FCMP_ORD: Predicate = CmpInst::FCMP_ORD; break; - case CmpInst::FCMP_UNO: Predicate = CmpInst::FCMP_UNO; break; - case CmpInst::FCMP_UEQ: Predicate = CmpInst::FCMP_TRUE; break; - case CmpInst::FCMP_UGT: Predicate = CmpInst::FCMP_UNO; break; - case CmpInst::FCMP_UGE: Predicate = CmpInst::FCMP_TRUE; break; - case CmpInst::FCMP_ULT: Predicate = CmpInst::FCMP_UNO; break; - case CmpInst::FCMP_ULE: Predicate = CmpInst::FCMP_TRUE; break; - case CmpInst::FCMP_UNE: Predicate = CmpInst::FCMP_UNO; break; - case CmpInst::FCMP_TRUE: Predicate = CmpInst::FCMP_TRUE; break; - - case CmpInst::ICMP_EQ: Predicate = CmpInst::FCMP_TRUE; break; - case CmpInst::ICMP_NE: Predicate = CmpInst::FCMP_FALSE; break; - case CmpInst::ICMP_UGT: Predicate = CmpInst::FCMP_FALSE; break; - case CmpInst::ICMP_UGE: Predicate = CmpInst::FCMP_TRUE; break; - case CmpInst::ICMP_ULT: Predicate = CmpInst::FCMP_FALSE; break; - case CmpInst::ICMP_ULE: Predicate = CmpInst::FCMP_TRUE; break; - case CmpInst::ICMP_SGT: Predicate = CmpInst::FCMP_FALSE; break; - case CmpInst::ICMP_SGE: Predicate = CmpInst::FCMP_TRUE; break; - case CmpInst::ICMP_SLT: Predicate = CmpInst::FCMP_FALSE; break; - case CmpInst::ICMP_SLE: Predicate = CmpInst::FCMP_TRUE; break; + case Predicate::FCMP_FALSE: + Pred = Predicate::FCMP_FALSE; + break; + case Predicate::FCMP_OEQ: + Pred = Predicate::FCMP_ORD; + break; + case Predicate::FCMP_OGT: + Pred = Predicate::FCMP_FALSE; + break; + case Predicate::FCMP_OGE: + Pred = Predicate::FCMP_ORD; + break; + case Predicate::FCMP_OLT: + Pred = Predicate::FCMP_FALSE; + break; + case Predicate::FCMP_OLE: + Pred = Predicate::FCMP_ORD; + break; + case Predicate::FCMP_ONE: + Pred = Predicate::FCMP_FALSE; + break; + case Predicate::FCMP_ORD: + Pred = Predicate::FCMP_ORD; + break; + case Predicate::FCMP_UNO: + Pred = Predicate::FCMP_UNO; + break; + case Predicate::FCMP_UEQ: + Pred = Predicate::FCMP_TRUE; + break; + case Predicate::FCMP_UGT: + Pred = Predicate::FCMP_UNO; + break; + case Predicate::FCMP_UGE: + Pred = Predicate::FCMP_TRUE; + break; + case Predicate::FCMP_ULT: + Pred = Predicate::FCMP_UNO; + break; + case Predicate::FCMP_ULE: + Pred = Predicate::FCMP_TRUE; + break; + case Predicate::FCMP_UNE: + Pred = Predicate::FCMP_UNO; + break; + case Predicate::FCMP_TRUE: + Pred = Predicate::FCMP_TRUE; + break; + + case Predicate::ICMP_EQ: + Pred = Predicate::FCMP_TRUE; + break; + case Predicate::ICMP_NE: + Pred = Predicate::FCMP_FALSE; + break; + case Predicate::ICMP_UGT: + Pred = Predicate::FCMP_FALSE; + break; + case Predicate::ICMP_UGE: + Pred = Predicate::FCMP_TRUE; + break; + case Predicate::ICMP_ULT: + Pred = Predicate::FCMP_FALSE; + break; + case Predicate::ICMP_ULE: + Pred = Predicate::FCMP_TRUE; + break; + case Predicate::ICMP_SGT: + Pred = Predicate::FCMP_FALSE; + break; + case Predicate::ICMP_SGE: + Pred = Predicate::FCMP_TRUE; + break; + case Predicate::ICMP_SLT: + Pred = Predicate::FCMP_FALSE; + break; + case Predicate::ICMP_SLE: + Pred = Predicate::FCMP_TRUE; + break; } - return Predicate; + return Pred; } Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -2693,14 +2693,14 @@ } void SelectionDAGBuilder::visitICmp(const User &I) { - ICmpInst::Predicate predicate = ICmpInst::BAD_ICMP_PREDICATE; + Predicate Pred = Predicate::BAD_ICMP_PREDICATE; if (const ICmpInst *IC = dyn_cast(&I)) - predicate = IC->getPredicate(); + Pred = IC->getPredicate(); else if (const ConstantExpr *IC = dyn_cast(&I)) - predicate = ICmpInst::Predicate(IC->getPredicate()); + Pred = IC->getPredicate(); SDValue Op1 = getValue(I.getOperand(0)); SDValue Op2 = getValue(I.getOperand(1)); - ISD::CondCode Opcode = getICmpCondCode(predicate); + ISD::CondCode Opcode = getICmpCondCode(Pred); EVT DestVT = DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(), I.getType()); @@ -2708,14 +2708,14 @@ } void SelectionDAGBuilder::visitFCmp(const User &I) { - FCmpInst::Predicate predicate = FCmpInst::BAD_FCMP_PREDICATE; + Predicate Pred = Predicate::BAD_FCMP_PREDICATE; if (const FCmpInst *FC = dyn_cast(&I)) - predicate = FC->getPredicate(); + Pred = FC->getPredicate(); else if (const ConstantExpr *FC = dyn_cast(&I)) - predicate = FCmpInst::Predicate(FC->getPredicate()); + Pred = FC->getPredicate(); SDValue Op1 = getValue(I.getOperand(0)); SDValue Op2 = getValue(I.getOperand(1)); - ISD::CondCode Condition = getFCmpCondCode(predicate); + ISD::CondCode Condition = getFCmpCondCode(Pred); // FIXME: Fcmp instructions have fast-math-flags in IR, so we should use them. // FIXME: We should propagate the fast-math-flags to the DAG node itself for Index: lib/ExecutionEngine/Interpreter/Execution.cpp =================================================================== --- lib/ExecutionEngine/Interpreter/Execution.cpp +++ lib/ExecutionEngine/Interpreter/Execution.cpp @@ -281,18 +281,38 @@ GenericValue Src1 = getOperandValue(I.getOperand(0), SF); GenericValue Src2 = getOperandValue(I.getOperand(1), SF); GenericValue R; // Result - - switch (I.getPredicate()) { - case ICmpInst::ICMP_EQ: R = executeICMP_EQ(Src1, Src2, Ty); break; - case ICmpInst::ICMP_NE: R = executeICMP_NE(Src1, Src2, Ty); break; - case ICmpInst::ICMP_ULT: R = executeICMP_ULT(Src1, Src2, Ty); break; - case ICmpInst::ICMP_SLT: R = executeICMP_SLT(Src1, Src2, Ty); break; - case ICmpInst::ICMP_UGT: R = executeICMP_UGT(Src1, Src2, Ty); break; - case ICmpInst::ICMP_SGT: R = executeICMP_SGT(Src1, Src2, Ty); break; - case ICmpInst::ICMP_ULE: R = executeICMP_ULE(Src1, Src2, Ty); break; - case ICmpInst::ICMP_SLE: R = executeICMP_SLE(Src1, Src2, Ty); break; - case ICmpInst::ICMP_UGE: R = executeICMP_UGE(Src1, Src2, Ty); break; - case ICmpInst::ICMP_SGE: R = executeICMP_SGE(Src1, Src2, Ty); break; + + switch (I.getPredicate().getKind()) { + case Predicate::ICMP_EQ: + R = executeICMP_EQ(Src1, Src2, Ty); + break; + case Predicate::ICMP_NE: + R = executeICMP_NE(Src1, Src2, Ty); + break; + case Predicate::ICMP_ULT: + R = executeICMP_ULT(Src1, Src2, Ty); + break; + case Predicate::ICMP_SLT: + R = executeICMP_SLT(Src1, Src2, Ty); + break; + case Predicate::ICMP_UGT: + R = executeICMP_UGT(Src1, Src2, Ty); + break; + case Predicate::ICMP_SGT: + R = executeICMP_SGT(Src1, Src2, Ty); + break; + case Predicate::ICMP_ULE: + R = executeICMP_ULE(Src1, Src2, Ty); + break; + case Predicate::ICMP_SLE: + R = executeICMP_SLE(Src1, Src2, Ty); + break; + case Predicate::ICMP_UGE: + R = executeICMP_UGE(Src1, Src2, Ty); + break; + case Predicate::ICMP_SGE: + R = executeICMP_SGE(Src1, Src2, Ty); + break; default: dbgs() << "Don't know how to handle this ICmp predicate!\n-->" << I; llvm_unreachable(nullptr); @@ -613,65 +633,121 @@ GenericValue Src1 = getOperandValue(I.getOperand(0), SF); GenericValue Src2 = getOperandValue(I.getOperand(1), SF); GenericValue R; // Result - - switch (I.getPredicate()) { + + switch (I.getPredicate().getKind()) { default: dbgs() << "Don't know how to handle this FCmp predicate!\n-->" << I; llvm_unreachable(nullptr); break; - case FCmpInst::FCMP_FALSE: R = executeFCMP_BOOL(Src1, Src2, Ty, false); - break; - case FCmpInst::FCMP_TRUE: R = executeFCMP_BOOL(Src1, Src2, Ty, true); - break; - case FCmpInst::FCMP_ORD: R = executeFCMP_ORD(Src1, Src2, Ty); break; - case FCmpInst::FCMP_UNO: R = executeFCMP_UNO(Src1, Src2, Ty); break; - case FCmpInst::FCMP_UEQ: R = executeFCMP_UEQ(Src1, Src2, Ty); break; - case FCmpInst::FCMP_OEQ: R = executeFCMP_OEQ(Src1, Src2, Ty); break; - case FCmpInst::FCMP_UNE: R = executeFCMP_UNE(Src1, Src2, Ty); break; - case FCmpInst::FCMP_ONE: R = executeFCMP_ONE(Src1, Src2, Ty); break; - case FCmpInst::FCMP_ULT: R = executeFCMP_ULT(Src1, Src2, Ty); break; - case FCmpInst::FCMP_OLT: R = executeFCMP_OLT(Src1, Src2, Ty); break; - case FCmpInst::FCMP_UGT: R = executeFCMP_UGT(Src1, Src2, Ty); break; - case FCmpInst::FCMP_OGT: R = executeFCMP_OGT(Src1, Src2, Ty); break; - case FCmpInst::FCMP_ULE: R = executeFCMP_ULE(Src1, Src2, Ty); break; - case FCmpInst::FCMP_OLE: R = executeFCMP_OLE(Src1, Src2, Ty); break; - case FCmpInst::FCMP_UGE: R = executeFCMP_UGE(Src1, Src2, Ty); break; - case FCmpInst::FCMP_OGE: R = executeFCMP_OGE(Src1, Src2, Ty); break; + case Predicate::FCMP_FALSE: + R = executeFCMP_BOOL(Src1, Src2, Ty, false); + break; + case Predicate::FCMP_TRUE: + R = executeFCMP_BOOL(Src1, Src2, Ty, true); + break; + case Predicate::FCMP_ORD: + R = executeFCMP_ORD(Src1, Src2, Ty); + break; + case Predicate::FCMP_UNO: + R = executeFCMP_UNO(Src1, Src2, Ty); + break; + case Predicate::FCMP_UEQ: + R = executeFCMP_UEQ(Src1, Src2, Ty); + break; + case Predicate::FCMP_OEQ: + R = executeFCMP_OEQ(Src1, Src2, Ty); + break; + case Predicate::FCMP_UNE: + R = executeFCMP_UNE(Src1, Src2, Ty); + break; + case Predicate::FCMP_ONE: + R = executeFCMP_ONE(Src1, Src2, Ty); + break; + case Predicate::FCMP_ULT: + R = executeFCMP_ULT(Src1, Src2, Ty); + break; + case Predicate::FCMP_OLT: + R = executeFCMP_OLT(Src1, Src2, Ty); + break; + case Predicate::FCMP_UGT: + R = executeFCMP_UGT(Src1, Src2, Ty); + break; + case Predicate::FCMP_OGT: + R = executeFCMP_OGT(Src1, Src2, Ty); + break; + case Predicate::FCMP_ULE: + R = executeFCMP_ULE(Src1, Src2, Ty); + break; + case Predicate::FCMP_OLE: + R = executeFCMP_OLE(Src1, Src2, Ty); + break; + case Predicate::FCMP_UGE: + R = executeFCMP_UGE(Src1, Src2, Ty); + break; + case Predicate::FCMP_OGE: + R = executeFCMP_OGE(Src1, Src2, Ty); + break; } SetValue(&I, R, SF); } -static GenericValue executeCmpInst(unsigned predicate, GenericValue Src1, +static GenericValue executeCmpInst(Predicate predicate, GenericValue Src1, GenericValue Src2, Type *Ty) { GenericValue Result; - switch (predicate) { - case ICmpInst::ICMP_EQ: return executeICMP_EQ(Src1, Src2, Ty); - case ICmpInst::ICMP_NE: return executeICMP_NE(Src1, Src2, Ty); - case ICmpInst::ICMP_UGT: return executeICMP_UGT(Src1, Src2, Ty); - case ICmpInst::ICMP_SGT: return executeICMP_SGT(Src1, Src2, Ty); - case ICmpInst::ICMP_ULT: return executeICMP_ULT(Src1, Src2, Ty); - case ICmpInst::ICMP_SLT: return executeICMP_SLT(Src1, Src2, Ty); - case ICmpInst::ICMP_UGE: return executeICMP_UGE(Src1, Src2, Ty); - case ICmpInst::ICMP_SGE: return executeICMP_SGE(Src1, Src2, Ty); - case ICmpInst::ICMP_ULE: return executeICMP_ULE(Src1, Src2, Ty); - case ICmpInst::ICMP_SLE: return executeICMP_SLE(Src1, Src2, Ty); - case FCmpInst::FCMP_ORD: return executeFCMP_ORD(Src1, Src2, Ty); - case FCmpInst::FCMP_UNO: return executeFCMP_UNO(Src1, Src2, Ty); - case FCmpInst::FCMP_OEQ: return executeFCMP_OEQ(Src1, Src2, Ty); - case FCmpInst::FCMP_UEQ: return executeFCMP_UEQ(Src1, Src2, Ty); - case FCmpInst::FCMP_ONE: return executeFCMP_ONE(Src1, Src2, Ty); - case FCmpInst::FCMP_UNE: return executeFCMP_UNE(Src1, Src2, Ty); - case FCmpInst::FCMP_OLT: return executeFCMP_OLT(Src1, Src2, Ty); - case FCmpInst::FCMP_ULT: return executeFCMP_ULT(Src1, Src2, Ty); - case FCmpInst::FCMP_OGT: return executeFCMP_OGT(Src1, Src2, Ty); - case FCmpInst::FCMP_UGT: return executeFCMP_UGT(Src1, Src2, Ty); - case FCmpInst::FCMP_OLE: return executeFCMP_OLE(Src1, Src2, Ty); - case FCmpInst::FCMP_ULE: return executeFCMP_ULE(Src1, Src2, Ty); - case FCmpInst::FCMP_OGE: return executeFCMP_OGE(Src1, Src2, Ty); - case FCmpInst::FCMP_UGE: return executeFCMP_UGE(Src1, Src2, Ty); - case FCmpInst::FCMP_FALSE: return executeFCMP_BOOL(Src1, Src2, Ty, false); - case FCmpInst::FCMP_TRUE: return executeFCMP_BOOL(Src1, Src2, Ty, true); + switch (predicate.getKind()) { + case Predicate::ICMP_EQ: + return executeICMP_EQ(Src1, Src2, Ty); + case Predicate::ICMP_NE: + return executeICMP_NE(Src1, Src2, Ty); + case Predicate::ICMP_UGT: + return executeICMP_UGT(Src1, Src2, Ty); + case Predicate::ICMP_SGT: + return executeICMP_SGT(Src1, Src2, Ty); + case Predicate::ICMP_ULT: + return executeICMP_ULT(Src1, Src2, Ty); + case Predicate::ICMP_SLT: + return executeICMP_SLT(Src1, Src2, Ty); + case Predicate::ICMP_UGE: + return executeICMP_UGE(Src1, Src2, Ty); + case Predicate::ICMP_SGE: + return executeICMP_SGE(Src1, Src2, Ty); + case Predicate::ICMP_ULE: + return executeICMP_ULE(Src1, Src2, Ty); + case Predicate::ICMP_SLE: + return executeICMP_SLE(Src1, Src2, Ty); + case Predicate::FCMP_ORD: + return executeFCMP_ORD(Src1, Src2, Ty); + case Predicate::FCMP_UNO: + return executeFCMP_UNO(Src1, Src2, Ty); + case Predicate::FCMP_OEQ: + return executeFCMP_OEQ(Src1, Src2, Ty); + case Predicate::FCMP_UEQ: + return executeFCMP_UEQ(Src1, Src2, Ty); + case Predicate::FCMP_ONE: + return executeFCMP_ONE(Src1, Src2, Ty); + case Predicate::FCMP_UNE: + return executeFCMP_UNE(Src1, Src2, Ty); + case Predicate::FCMP_OLT: + return executeFCMP_OLT(Src1, Src2, Ty); + case Predicate::FCMP_ULT: + return executeFCMP_ULT(Src1, Src2, Ty); + case Predicate::FCMP_OGT: + return executeFCMP_OGT(Src1, Src2, Ty); + case Predicate::FCMP_UGT: + return executeFCMP_UGT(Src1, Src2, Ty); + case Predicate::FCMP_OLE: + return executeFCMP_OLE(Src1, Src2, Ty); + case Predicate::FCMP_ULE: + return executeFCMP_ULE(Src1, Src2, Ty); + case Predicate::FCMP_OGE: + return executeFCMP_OGE(Src1, Src2, Ty); + case Predicate::FCMP_UGE: + return executeFCMP_UGE(Src1, Src2, Ty); + case Predicate::FCMP_FALSE: + return executeFCMP_BOOL(Src1, Src2, Ty, false); + case Predicate::FCMP_TRUE: + return executeFCMP_BOOL(Src1, Src2, Ty, true); default: dbgs() << "Unhandled Cmp predicate\n"; llvm_unreachable(nullptr); Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -1041,39 +1041,6 @@ SlotTracker *Machine, const Module *Context, bool FromValue = false); -static const char *getPredicateText(unsigned predicate) { - const char * pred = "unknown"; - switch (predicate) { - case FCmpInst::FCMP_FALSE: pred = "false"; break; - case FCmpInst::FCMP_OEQ: pred = "oeq"; break; - case FCmpInst::FCMP_OGT: pred = "ogt"; break; - case FCmpInst::FCMP_OGE: pred = "oge"; break; - case FCmpInst::FCMP_OLT: pred = "olt"; break; - case FCmpInst::FCMP_OLE: pred = "ole"; break; - case FCmpInst::FCMP_ONE: pred = "one"; break; - case FCmpInst::FCMP_ORD: pred = "ord"; break; - case FCmpInst::FCMP_UNO: pred = "uno"; break; - case FCmpInst::FCMP_UEQ: pred = "ueq"; break; - case FCmpInst::FCMP_UGT: pred = "ugt"; break; - case FCmpInst::FCMP_UGE: pred = "uge"; break; - case FCmpInst::FCMP_ULT: pred = "ult"; break; - case FCmpInst::FCMP_ULE: pred = "ule"; break; - case FCmpInst::FCMP_UNE: pred = "une"; break; - case FCmpInst::FCMP_TRUE: pred = "true"; break; - case ICmpInst::ICMP_EQ: pred = "eq"; break; - case ICmpInst::ICMP_NE: pred = "ne"; break; - case ICmpInst::ICMP_SGT: pred = "sgt"; break; - case ICmpInst::ICMP_SGE: pred = "sge"; break; - case ICmpInst::ICMP_SLT: pred = "slt"; break; - case ICmpInst::ICMP_SLE: pred = "sle"; break; - case ICmpInst::ICMP_UGT: pred = "ugt"; break; - case ICmpInst::ICMP_UGE: pred = "uge"; break; - case ICmpInst::ICMP_ULT: pred = "ult"; break; - case ICmpInst::ICMP_ULE: pred = "ule"; break; - } - return pred; -} - static void writeAtomicRMWOperation(raw_ostream &Out, AtomicRMWInst::BinOp Op) { switch (Op) { @@ -1349,7 +1316,7 @@ Out << CE->getOpcodeName(); WriteOptimizationInfo(Out, CE); if (CE->isCompare()) - Out << ' ' << getPredicateText(CE->getPredicate()); + Out << ' ' << CE->getPredicate().getName(); Out << " ("; if (const GEPOperator *GEP = dyn_cast(CE)) { @@ -2869,7 +2836,7 @@ // Print out the compare instruction predicates if (const CmpInst *CI = dyn_cast(&I)) - Out << ' ' << getPredicateText(CI->getPredicate()); + Out << ' ' << CI->getPredicate().getName(); // Print out the atomicrmw operation if (const AtomicRMWInst *RMWI = dyn_cast(&I)) Index: lib/IR/AutoUpgrade.cpp =================================================================== --- lib/IR/AutoUpgrade.cpp +++ lib/IR/AutoUpgrade.cpp @@ -622,7 +622,7 @@ } static Value *upgradeIntMinMax(IRBuilder<> &Builder, CallInst &CI, - ICmpInst::Predicate Pred) { + Predicate Pred) { Value *Op0 = CI.getArgOperand(0); Value *Op1 = CI.getArgOperand(1); Value *Cmp = Builder.CreateICmp(Pred, Op0, Op1); @@ -630,7 +630,7 @@ } static Value *upgradeMaskedCompare(IRBuilder<> &Builder, CallInst &CI, - ICmpInst::Predicate Pred) { + Predicate Pred) { Value *Op0 = CI.getArgOperand(0); unsigned NumElts = Op0->getType()->getVectorNumElements(); Value *Cmp = Builder.CreateICmp(Pred, Op0, CI.getArgOperand(1)); @@ -688,29 +688,29 @@ "pcmpgt"); Rep = Builder.CreateSExt(Rep, CI->getType(), ""); } else if (IsX86 && Name.startswith("avx512.mask.pcmpeq.")) { - Rep = upgradeMaskedCompare(Builder, *CI, ICmpInst::ICMP_EQ); + Rep = upgradeMaskedCompare(Builder, *CI, Predicate::ICMP_EQ); } else if (IsX86 && Name.startswith("avx512.mask.pcmpgt.")) { - Rep = upgradeMaskedCompare(Builder, *CI, ICmpInst::ICMP_SGT); + Rep = upgradeMaskedCompare(Builder, *CI, Predicate::ICMP_SGT); } else if (IsX86 && (Name == "sse41.pmaxsb" || Name == "sse2.pmaxs.w" || Name == "sse41.pmaxsd" || Name.startswith("avx2.pmaxs"))) { - Rep = upgradeIntMinMax(Builder, *CI, ICmpInst::ICMP_SGT); + Rep = upgradeIntMinMax(Builder, *CI, Predicate::ICMP_SGT); } else if (IsX86 && (Name == "sse2.pmaxu.b" || Name == "sse41.pmaxuw" || Name == "sse41.pmaxud" || Name.startswith("avx2.pmaxu"))) { - Rep = upgradeIntMinMax(Builder, *CI, ICmpInst::ICMP_UGT); + Rep = upgradeIntMinMax(Builder, *CI, Predicate::ICMP_UGT); } else if (IsX86 && (Name == "sse41.pminsb" || Name == "sse2.pmins.w" || Name == "sse41.pminsd" || Name.startswith("avx2.pmins"))) { - Rep = upgradeIntMinMax(Builder, *CI, ICmpInst::ICMP_SLT); + Rep = upgradeIntMinMax(Builder, *CI, Predicate::ICMP_SLT); } else if (IsX86 && (Name == "sse2.pminu.b" || Name == "sse41.pminuw" || Name == "sse41.pminud" || Name.startswith("avx2.pminu"))) { - Rep = upgradeIntMinMax(Builder, *CI, ICmpInst::ICMP_ULT); + Rep = upgradeIntMinMax(Builder, *CI, Predicate::ICMP_ULT); } else if (IsX86 && (Name == "sse2.cvtdq2pd" || Name == "sse2.cvtps2pd" || Name == "avx.cvtdq2.pd.256" || Index: lib/IR/ConstantFold.h =================================================================== --- lib/IR/ConstantFold.h +++ lib/IR/ConstantFold.h @@ -19,6 +19,8 @@ #ifndef LLVM_LIB_IR_CONSTANTFOLD_H #define LLVM_LIB_IR_CONSTANTFOLD_H +#include "llvm/Support/Predicate.h" + namespace llvm { template class ArrayRef; class Value; @@ -44,8 +46,8 @@ ArrayRef Idxs); Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2); - Constant *ConstantFoldCompareInstruction(unsigned short predicate, - Constant *C1, Constant *C2); + Constant *ConstantFoldCompareInstruction(Predicate Pred, Constant *C1, + Constant *C2); Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool inBounds, ArrayRef Idxs); Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool inBounds, Index: lib/IR/ConstantFold.cpp =================================================================== --- lib/IR/ConstantFold.cpp +++ lib/IR/ConstantFold.cpp @@ -1096,9 +1096,9 @@ case Instruction::FCmp: // cmp pred ^ true -> cmp !pred assert(CI2->equalsInt(1)); - CmpInst::Predicate pred = (CmpInst::Predicate)CE1->getPredicate(); - pred = CmpInst::getInversePredicate(pred); - return ConstantExpr::getCompare(pred, CE1->getOperand(0), + Predicate Pred = CE1->getPredicate(); + Pred = Pred.getInverse(); + return ConstantExpr::getCompare(Pred, CE1->getOperand(0), CE1->getOperand(1)); } } @@ -1340,38 +1340,39 @@ /// To simplify this code we canonicalize the relation so that the first /// operand is always the most "complex" of the two. We consider ConstantFP /// to be the simplest, and ConstantExprs to be the most complex. -static FCmpInst::Predicate evaluateFCmpRelation(Constant *V1, Constant *V2) { +static Predicate evaluateFCmpRelation(Constant *V1, Constant *V2) { assert(V1->getType() == V2->getType() && "Cannot compare values of different types!"); // Handle degenerate case quickly - if (V1 == V2) return FCmpInst::FCMP_OEQ; + if (V1 == V2) + return Predicate::FCMP_OEQ; if (!isa(V1)) { if (!isa(V2)) { // Simple case, use the standard constant folder. ConstantInt *R = nullptr; R = dyn_cast( - ConstantExpr::getFCmp(FCmpInst::FCMP_OEQ, V1, V2)); + ConstantExpr::getFCmp(Predicate::FCMP_OEQ, V1, V2)); if (R && !R->isZero()) - return FCmpInst::FCMP_OEQ; + return Predicate::FCMP_OEQ; R = dyn_cast( - ConstantExpr::getFCmp(FCmpInst::FCMP_OLT, V1, V2)); + ConstantExpr::getFCmp(Predicate::FCMP_OLT, V1, V2)); if (R && !R->isZero()) - return FCmpInst::FCMP_OLT; + return Predicate::FCMP_OLT; R = dyn_cast( - ConstantExpr::getFCmp(FCmpInst::FCMP_OGT, V1, V2)); + ConstantExpr::getFCmp(Predicate::FCMP_OGT, V1, V2)); if (R && !R->isZero()) - return FCmpInst::FCMP_OGT; + return Predicate::FCMP_OGT; // Nothing more we can do - return FCmpInst::BAD_FCMP_PREDICATE; + return Predicate::BAD_FCMP_PREDICATE; } // If the first operand is simple and second is ConstantExpr, swap operands. - FCmpInst::Predicate SwappedRelation = evaluateFCmpRelation(V2, V1); - if (SwappedRelation != FCmpInst::BAD_FCMP_PREDICATE) - return FCmpInst::getSwappedPredicate(SwappedRelation); + Predicate SwappedRelation = evaluateFCmpRelation(V2, V1); + if (SwappedRelation != Predicate::BAD_FCMP_PREDICATE) + return SwappedRelation.getSwapped(); } else { // Ok, the LHS is known to be a constantexpr. The RHS can be any of a // constantexpr or a simple constant. @@ -1389,11 +1390,11 @@ } // There are MANY other foldings that we could perform here. They will // probably be added on demand, as they seem needed. - return FCmpInst::BAD_FCMP_PREDICATE; + return Predicate::BAD_FCMP_PREDICATE; } -static ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1, - const GlobalValue *GV2) { +static Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1, + const GlobalValue *GV2) { auto isGlobalUnsafeForEquality = [](const GlobalValue *GV) { if (GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage()) return true; @@ -1412,8 +1413,8 @@ // Don't try to decide equality of aliases. if (!isa(GV1) && !isa(GV2)) if (!isGlobalUnsafeForEquality(GV1) && !isGlobalUnsafeForEquality(GV2)) - return ICmpInst::ICMP_NE; - return ICmpInst::BAD_ICMP_PREDICATE; + return Predicate::ICMP_NE; + return Predicate::BAD_ICMP_PREDICATE; } /// This function determines if there is anything we can decide about the two @@ -1421,18 +1422,19 @@ /// comparisons, but should instead handle ConstantExprs and GlobalValues. /// If we can determine that the two constants have a particular relation to /// each other, we should return the corresponding ICmp predicate, otherwise -/// return ICmpInst::BAD_ICMP_PREDICATE. +/// return Predicate::BAD_ICMP_PREDICATE. /// /// To simplify this code we canonicalize the relation so that the first /// operand is always the most "complex" of the two. We consider simple /// constants (like ConstantInt) to be the simplest, followed by /// GlobalValues, followed by ConstantExpr's (the most complex). /// -static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2, - bool isSigned) { +static Predicate evaluateICmpRelation(Constant *V1, Constant *V2, + bool isSigned) { assert(V1->getType() == V2->getType() && "Cannot compare different types of values!"); - if (V1 == V2) return ICmpInst::ICMP_EQ; + if (V1 == V2) + return Predicate::ICMP_EQ; if (!isa(V1) && !isa(V1) && !isa(V1)) { @@ -1441,36 +1443,34 @@ // We distilled this down to a simple case, use the standard constant // folder. ConstantInt *R = nullptr; - ICmpInst::Predicate pred = ICmpInst::ICMP_EQ; + Predicate pred = Predicate::ICMP_EQ; R = dyn_cast(ConstantExpr::getICmp(pred, V1, V2)); if (R && !R->isZero()) return pred; - pred = isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; + pred = isSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT; R = dyn_cast(ConstantExpr::getICmp(pred, V1, V2)); if (R && !R->isZero()) return pred; - pred = isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; + pred = isSigned ? Predicate::ICMP_SGT : Predicate::ICMP_UGT; R = dyn_cast(ConstantExpr::getICmp(pred, V1, V2)); if (R && !R->isZero()) return pred; // If we couldn't figure it out, bail. - return ICmpInst::BAD_ICMP_PREDICATE; + return Predicate::BAD_ICMP_PREDICATE; } // If the first operand is simple, swap operands. - ICmpInst::Predicate SwappedRelation = - evaluateICmpRelation(V2, V1, isSigned); - if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE) - return ICmpInst::getSwappedPredicate(SwappedRelation); + Predicate SwappedRelation = evaluateICmpRelation(V2, V1, isSigned); + if (SwappedRelation != Predicate::BAD_ICMP_PREDICATE) + return SwappedRelation.getSwapped(); } else if (const GlobalValue *GV = dyn_cast(V1)) { if (isa(V2)) { // Swap as necessary. - ICmpInst::Predicate SwappedRelation = - evaluateICmpRelation(V2, V1, isSigned); - if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE) - return ICmpInst::getSwappedPredicate(SwappedRelation); - return ICmpInst::BAD_ICMP_PREDICATE; + Predicate SwappedRelation = evaluateICmpRelation(V2, V1, isSigned); + if (SwappedRelation != Predicate::BAD_ICMP_PREDICATE) + return SwappedRelation.getSwapped(); + return Predicate::BAD_ICMP_PREDICATE; } // Now we know that the RHS is a GlobalValue, BlockAddress or simple @@ -1479,21 +1479,20 @@ if (const GlobalValue *GV2 = dyn_cast(V2)) { return areGlobalsPotentiallyEqual(GV, GV2); } else if (isa(V2)) { - return ICmpInst::ICMP_NE; // Globals never equal labels. + return Predicate::ICMP_NE; // Globals never equal labels. } else { assert(isa(V2) && "Canonicalization guarantee!"); // GlobalVals can never be null unless they have external weak linkage. // We don't try to evaluate aliases here. if (!GV->hasExternalWeakLinkage() && !isa(GV)) - return ICmpInst::ICMP_NE; + return Predicate::ICMP_NE; } } else if (const BlockAddress *BA = dyn_cast(V1)) { if (isa(V2)) { // Swap as necessary. - ICmpInst::Predicate SwappedRelation = - evaluateICmpRelation(V2, V1, isSigned); - if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE) - return ICmpInst::getSwappedPredicate(SwappedRelation); - return ICmpInst::BAD_ICMP_PREDICATE; + Predicate SwappedRelation = evaluateICmpRelation(V2, V1, isSigned); + if (SwappedRelation != Predicate::BAD_ICMP_PREDICATE) + return SwappedRelation.getSwapped(); + return Predicate::BAD_ICMP_PREDICATE; } // Now we know that the RHS is a GlobalValue, BlockAddress or simple @@ -1504,12 +1503,12 @@ // addresses in the current function might be the same if blocks are // empty. if (BA2->getFunction() != BA->getFunction()) - return ICmpInst::ICMP_NE; + return Predicate::ICMP_NE; } else { // Block addresses aren't null, don't equal the address of globals. assert((isa(V2) || isa(V2)) && "Canonicalization guarantee!"); - return ICmpInst::ICMP_NE; + return Predicate::ICMP_NE; } } else { // Ok, the LHS is known to be a constantexpr. The RHS can be any of a @@ -1557,20 +1556,20 @@ if (GV->hasExternalWeakLinkage()) // Weak linkage GVals could be zero or not. We're comparing that // to null pointer so its greater-or-equal - return isSigned ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE; + return isSigned ? Predicate::ICMP_SGE : Predicate::ICMP_UGE; else // If its not weak linkage, the GVal must have a non-zero address // so the result is greater-than - return isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; + return isSigned ? Predicate::ICMP_SGT : Predicate::ICMP_UGT; } else if (isa(CE1Op0)) { // If we are indexing from a null pointer, check to see if we have any // non-zero indices. for (unsigned i = 1, e = CE1->getNumOperands(); i != e; ++i) if (!CE1->getOperand(i)->isNullValue()) // Offsetting from null, must not be equal. - return isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; + return isSigned ? Predicate::ICMP_SGT : Predicate::ICMP_UGT; // Only zero indexes from null, must still be zero. - return ICmpInst::ICMP_EQ; + return Predicate::ICMP_EQ; } // Otherwise, we can't really say if the first operand is null or not. } else if (const GlobalValue *GV2 = dyn_cast(V2)) { @@ -1578,11 +1577,11 @@ if (GV2->hasExternalWeakLinkage()) // Weak linkage GVals could be zero or not. We're comparing it to // a null pointer, so its less-or-equal - return isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE; + return isSigned ? Predicate::ICMP_SLE : Predicate::ICMP_ULE; else // If its not weak linkage, the GVal must have a non-zero address // so the result is less-than - return isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; + return isSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT; } else if (const GlobalValue *GV = dyn_cast(CE1Op0)) { if (GV == GV2) { // If this is a getelementptr of the same global, then it must be @@ -1592,11 +1591,11 @@ assert(CE1->getNumOperands() == 2 && !CE1->getOperand(1)->isNullValue() && "Surprising getelementptr!"); - return isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; + return isSigned ? Predicate::ICMP_SGT : Predicate::ICMP_UGT; } else { if (CE1GEP->hasAllZeroIndices()) return areGlobalsPotentiallyEqual(GV, GV2); - return ICmpInst::BAD_ICMP_PREDICATE; + return Predicate::BAD_ICMP_PREDICATE; } } } else { @@ -1617,7 +1616,7 @@ if (CE1GEP->hasAllZeroIndices() && CE2GEP->hasAllZeroIndices()) return areGlobalsPotentiallyEqual(cast(CE1Op0), cast(CE2Op0)); - return ICmpInst::BAD_ICMP_PREDICATE; + return Predicate::BAD_ICMP_PREDICATE; } // Ok, we know that both getelementptr instructions are based on the // same global. From this, we can precisely determine the relative @@ -1630,7 +1629,7 @@ // subsequent indices, so check for that case first. if (!CE1->isGEPWithNoNotionalOverIndexing() || !CE2->isGEPWithNoNotionalOverIndexing()) - return ICmpInst::BAD_ICMP_PREDICATE; // Might be equal. + return Predicate::BAD_ICMP_PREDICATE; // Might be equal. // Compare all of the operands the GEP's have in common. gep_type_iterator GTI = gep_type_begin(CE1); @@ -1638,9 +1637,12 @@ ++i, ++GTI) switch (IdxCompare(CE1->getOperand(i), CE2->getOperand(i), GTI.getIndexedType())) { - case -1: return isSigned ? ICmpInst::ICMP_SLT:ICmpInst::ICMP_ULT; - case 1: return isSigned ? ICmpInst::ICMP_SGT:ICmpInst::ICMP_UGT; - case -2: return ICmpInst::BAD_ICMP_PREDICATE; + case -1: + return isSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT; + case 1: + return isSigned ? Predicate::ICMP_SGT : Predicate::ICMP_UGT; + case -2: + return Predicate::BAD_ICMP_PREDICATE; } // Ok, we ran out of things they have in common. If any leftovers @@ -1648,19 +1650,19 @@ for (; i < CE1->getNumOperands(); ++i) if (!CE1->getOperand(i)->isNullValue()) { if (isa(CE1->getOperand(i))) - return isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; + return isSigned ? Predicate::ICMP_SGT : Predicate::ICMP_UGT; else - return ICmpInst::BAD_ICMP_PREDICATE; // Might be equal. + return Predicate::BAD_ICMP_PREDICATE; // Might be equal. } for (; i < CE2->getNumOperands(); ++i) if (!CE2->getOperand(i)->isNullValue()) { if (isa(CE2->getOperand(i))) - return isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; + return isSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT; else - return ICmpInst::BAD_ICMP_PREDICATE; // Might be equal. + return Predicate::BAD_ICMP_PREDICATE; // Might be equal. } - return ICmpInst::ICMP_EQ; + return Predicate::ICMP_EQ; } } } @@ -1670,11 +1672,11 @@ } } - return ICmpInst::BAD_ICMP_PREDICATE; + return Predicate::BAD_ICMP_PREDICATE; } -Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred, - Constant *C1, Constant *C2) { +Constant *llvm::ConstantFoldCompareInstruction(Predicate Pred, Constant *C1, + Constant *C2) { Type *ResultTy; if (VectorType *VT = dyn_cast(C1->getType())) ResultTy = VectorType::get(Type::getInt1Ty(C1->getContext()), @@ -1683,30 +1685,29 @@ ResultTy = Type::getInt1Ty(C1->getContext()); // Fold FCMP_FALSE/FCMP_TRUE unconditionally. - if (pred == FCmpInst::FCMP_FALSE) + if (Pred == Predicate::FCMP_FALSE) return Constant::getNullValue(ResultTy); - if (pred == FCmpInst::FCMP_TRUE) + if (Pred == Predicate::FCMP_TRUE) return Constant::getAllOnesValue(ResultTy); // Handle some degenerate cases first if (isa(C1) || isa(C2)) { - CmpInst::Predicate Predicate = CmpInst::Predicate(pred); - bool isIntegerPredicate = ICmpInst::isIntPredicate(Predicate); + bool isIntegerPredicate = Pred.isInt(); // For EQ and NE, we can always pick a value for the undef to make the // predicate pass or fail, so we can return undef. // Also, if both operands are undef, we can return undef for int comparison. - if (ICmpInst::isEquality(Predicate) || (isIntegerPredicate && C1 == C2)) + if (isIntegerPredicate && (Pred.isEquality() || C1 == C2)) return UndefValue::get(ResultTy); // Otherwise, for integer compare, pick the same value as the non-undef // operand, and fold it to true or false. if (isIntegerPredicate) - return ConstantInt::get(ResultTy, CmpInst::isTrueWhenEqual(Predicate)); + return ConstantInt::get(ResultTy, Pred.isTrueWhenEqual()); // Choosing NaN for the undef will always make unordered comparison succeed // and ordered comparison fails. - return ConstantInt::get(ResultTy, CmpInst::isUnordered(Predicate)); + return ConstantInt::get(ResultTy, Pred.isUnordered()); } // icmp eq/ne(null,GV) -> false/true @@ -1714,9 +1715,9 @@ if (const GlobalValue *GV = dyn_cast(C2)) // Don't try to evaluate aliases. External weak GV can be null. if (!isa(GV) && !GV->hasExternalWeakLinkage()) { - if (pred == ICmpInst::ICMP_EQ) + if (Pred == Predicate::ICMP_EQ) return ConstantInt::getFalse(C1->getContext()); - else if (pred == ICmpInst::ICMP_NE) + else if (Pred == Predicate::ICMP_NE) return ConstantInt::getTrue(C1->getContext()); } // icmp eq/ne(GV,null) -> false/true @@ -1724,21 +1725,21 @@ if (const GlobalValue *GV = dyn_cast(C1)) // Don't try to evaluate aliases. External weak GV can be null. if (!isa(GV) && !GV->hasExternalWeakLinkage()) { - if (pred == ICmpInst::ICMP_EQ) + if (Pred == Predicate::ICMP_EQ) return ConstantInt::getFalse(C1->getContext()); - else if (pred == ICmpInst::ICMP_NE) + else if (Pred == Predicate::ICMP_NE) return ConstantInt::getTrue(C1->getContext()); } } // If the comparison is a comparison between two i1's, simplify it. if (C1->getType()->isIntegerTy(1)) { - switch(pred) { - case ICmpInst::ICMP_EQ: + switch (Pred.getKind()) { + case Predicate::ICMP_EQ: if (isa(C2)) return ConstantExpr::getXor(C1, ConstantExpr::getNot(C2)); return ConstantExpr::getXor(ConstantExpr::getNot(C1), C2); - case ICmpInst::ICMP_NE: + case Predicate::ICMP_NE: return ConstantExpr::getXor(C1, C2); default: break; @@ -1748,59 +1749,71 @@ if (isa(C1) && isa(C2)) { const APInt &V1 = cast(C1)->getValue(); const APInt &V2 = cast(C2)->getValue(); - switch (pred) { + switch (Pred.getKind()) { default: llvm_unreachable("Invalid ICmp Predicate"); - case ICmpInst::ICMP_EQ: return ConstantInt::get(ResultTy, V1 == V2); - case ICmpInst::ICMP_NE: return ConstantInt::get(ResultTy, V1 != V2); - case ICmpInst::ICMP_SLT: return ConstantInt::get(ResultTy, V1.slt(V2)); - case ICmpInst::ICMP_SGT: return ConstantInt::get(ResultTy, V1.sgt(V2)); - case ICmpInst::ICMP_SLE: return ConstantInt::get(ResultTy, V1.sle(V2)); - case ICmpInst::ICMP_SGE: return ConstantInt::get(ResultTy, V1.sge(V2)); - case ICmpInst::ICMP_ULT: return ConstantInt::get(ResultTy, V1.ult(V2)); - case ICmpInst::ICMP_UGT: return ConstantInt::get(ResultTy, V1.ugt(V2)); - case ICmpInst::ICMP_ULE: return ConstantInt::get(ResultTy, V1.ule(V2)); - case ICmpInst::ICMP_UGE: return ConstantInt::get(ResultTy, V1.uge(V2)); + case Predicate::ICMP_EQ: + return ConstantInt::get(ResultTy, V1 == V2); + case Predicate::ICMP_NE: + return ConstantInt::get(ResultTy, V1 != V2); + case Predicate::ICMP_SLT: + return ConstantInt::get(ResultTy, V1.slt(V2)); + case Predicate::ICMP_SGT: + return ConstantInt::get(ResultTy, V1.sgt(V2)); + case Predicate::ICMP_SLE: + return ConstantInt::get(ResultTy, V1.sle(V2)); + case Predicate::ICMP_SGE: + return ConstantInt::get(ResultTy, V1.sge(V2)); + case Predicate::ICMP_ULT: + return ConstantInt::get(ResultTy, V1.ult(V2)); + case Predicate::ICMP_UGT: + return ConstantInt::get(ResultTy, V1.ugt(V2)); + case Predicate::ICMP_ULE: + return ConstantInt::get(ResultTy, V1.ule(V2)); + case Predicate::ICMP_UGE: + return ConstantInt::get(ResultTy, V1.uge(V2)); } } else if (isa(C1) && isa(C2)) { const APFloat &C1V = cast(C1)->getValueAPF(); const APFloat &C2V = cast(C2)->getValueAPF(); APFloat::cmpResult R = C1V.compare(C2V); - switch (pred) { + switch (Pred.getKind()) { default: llvm_unreachable("Invalid FCmp Predicate"); - case FCmpInst::FCMP_FALSE: return Constant::getNullValue(ResultTy); - case FCmpInst::FCMP_TRUE: return Constant::getAllOnesValue(ResultTy); - case FCmpInst::FCMP_UNO: + case Predicate::FCMP_FALSE: + return Constant::getNullValue(ResultTy); + case Predicate::FCMP_TRUE: + return Constant::getAllOnesValue(ResultTy); + case Predicate::FCMP_UNO: return ConstantInt::get(ResultTy, R==APFloat::cmpUnordered); - case FCmpInst::FCMP_ORD: + case Predicate::FCMP_ORD: return ConstantInt::get(ResultTy, R!=APFloat::cmpUnordered); - case FCmpInst::FCMP_UEQ: + case Predicate::FCMP_UEQ: return ConstantInt::get(ResultTy, R==APFloat::cmpUnordered || R==APFloat::cmpEqual); - case FCmpInst::FCMP_OEQ: + case Predicate::FCMP_OEQ: return ConstantInt::get(ResultTy, R==APFloat::cmpEqual); - case FCmpInst::FCMP_UNE: + case Predicate::FCMP_UNE: return ConstantInt::get(ResultTy, R!=APFloat::cmpEqual); - case FCmpInst::FCMP_ONE: + case Predicate::FCMP_ONE: return ConstantInt::get(ResultTy, R==APFloat::cmpLessThan || R==APFloat::cmpGreaterThan); - case FCmpInst::FCMP_ULT: + case Predicate::FCMP_ULT: return ConstantInt::get(ResultTy, R==APFloat::cmpUnordered || R==APFloat::cmpLessThan); - case FCmpInst::FCMP_OLT: + case Predicate::FCMP_OLT: return ConstantInt::get(ResultTy, R==APFloat::cmpLessThan); - case FCmpInst::FCMP_UGT: + case Predicate::FCMP_UGT: return ConstantInt::get(ResultTy, R==APFloat::cmpUnordered || R==APFloat::cmpGreaterThan); - case FCmpInst::FCMP_OGT: + case Predicate::FCMP_OGT: return ConstantInt::get(ResultTy, R==APFloat::cmpGreaterThan); - case FCmpInst::FCMP_ULE: + case Predicate::FCMP_ULE: return ConstantInt::get(ResultTy, R!=APFloat::cmpGreaterThan); - case FCmpInst::FCMP_OLE: + case Predicate::FCMP_OLE: return ConstantInt::get(ResultTy, R==APFloat::cmpLessThan || R==APFloat::cmpEqual); - case FCmpInst::FCMP_UGE: + case Predicate::FCMP_UGE: return ConstantInt::get(ResultTy, R!=APFloat::cmpLessThan); - case FCmpInst::FCMP_OGE: + case Predicate::FCMP_OGE: return ConstantInt::get(ResultTy, R==APFloat::cmpGreaterThan || R==APFloat::cmpEqual); } @@ -1816,7 +1829,7 @@ Constant *C2E = ConstantExpr::getExtractElement(C2, ConstantInt::get(Ty, i)); - ResElts.push_back(ConstantExpr::getCompare(pred, C1E, C2E)); + ResElts.push_back(ConstantExpr::getCompare(Pred, C1E, C2E)); } return ConstantVector::get(ResElts); @@ -1827,54 +1840,54 @@ // infinite recursive loop (isa(C1) || isa(C2))) { int Result = -1; // -1 = unknown, 0 = known false, 1 = known true. - switch (evaluateFCmpRelation(C1, C2)) { + switch (evaluateFCmpRelation(C1, C2).getKind()) { default: llvm_unreachable("Unknown relation!"); - case FCmpInst::FCMP_UNO: - case FCmpInst::FCMP_ORD: - case FCmpInst::FCMP_UEQ: - case FCmpInst::FCMP_UNE: - case FCmpInst::FCMP_ULT: - case FCmpInst::FCMP_UGT: - case FCmpInst::FCMP_ULE: - case FCmpInst::FCMP_UGE: - case FCmpInst::FCMP_TRUE: - case FCmpInst::FCMP_FALSE: - case FCmpInst::BAD_FCMP_PREDICATE: + case Predicate::FCMP_UNO: + case Predicate::FCMP_ORD: + case Predicate::FCMP_UEQ: + case Predicate::FCMP_UNE: + case Predicate::FCMP_ULT: + case Predicate::FCMP_UGT: + case Predicate::FCMP_ULE: + case Predicate::FCMP_UGE: + case Predicate::FCMP_TRUE: + case Predicate::FCMP_FALSE: + case Predicate::BAD_FCMP_PREDICATE: break; // Couldn't determine anything about these constants. - case FCmpInst::FCMP_OEQ: // We know that C1 == C2 - Result = (pred == FCmpInst::FCMP_UEQ || pred == FCmpInst::FCMP_OEQ || - pred == FCmpInst::FCMP_ULE || pred == FCmpInst::FCMP_OLE || - pred == FCmpInst::FCMP_UGE || pred == FCmpInst::FCMP_OGE); + case Predicate::FCMP_OEQ: // We know that C1 == C2 + Result = Pred.isOneOf(Predicate::FCMP_UEQ, Predicate::FCMP_OEQ, + Predicate::FCMP_ULE, Predicate::FCMP_OLE, + Predicate::FCMP_UGE, Predicate::FCMP_OGE); break; - case FCmpInst::FCMP_OLT: // We know that C1 < C2 - Result = (pred == FCmpInst::FCMP_UNE || pred == FCmpInst::FCMP_ONE || - pred == FCmpInst::FCMP_ULT || pred == FCmpInst::FCMP_OLT || - pred == FCmpInst::FCMP_ULE || pred == FCmpInst::FCMP_OLE); + case Predicate::FCMP_OLT: // We know that C1 < C2 + Result = Pred.isOneOf(Predicate::FCMP_UNE, Predicate::FCMP_ONE, + Predicate::FCMP_ULT, Predicate::FCMP_OLT, + Predicate::FCMP_ULE, Predicate::FCMP_OLE); break; - case FCmpInst::FCMP_OGT: // We know that C1 > C2 - Result = (pred == FCmpInst::FCMP_UNE || pred == FCmpInst::FCMP_ONE || - pred == FCmpInst::FCMP_UGT || pred == FCmpInst::FCMP_OGT || - pred == FCmpInst::FCMP_UGE || pred == FCmpInst::FCMP_OGE); + case Predicate::FCMP_OGT: // We know that C1 > C2 + Result = Pred.isOneOf(Predicate::FCMP_UNE, Predicate::FCMP_ONE, + Predicate::FCMP_UGT, Predicate::FCMP_OGT, + Predicate::FCMP_UGE, Predicate::FCMP_OGE); break; - case FCmpInst::FCMP_OLE: // We know that C1 <= C2 + case Predicate::FCMP_OLE: // We know that C1 <= C2 // We can only partially decide this relation. - if (pred == FCmpInst::FCMP_UGT || pred == FCmpInst::FCMP_OGT) + if (Pred.isOneOf(Predicate::FCMP_UGT, Predicate::FCMP_OGT)) Result = 0; - else if (pred == FCmpInst::FCMP_ULT || pred == FCmpInst::FCMP_OLT) + else if (Pred.isOneOf(Predicate::FCMP_ULT, Predicate::FCMP_OLT)) Result = 1; break; - case FCmpInst::FCMP_OGE: // We known that C1 >= C2 + case Predicate::FCMP_OGE: // We known that C1 >= C2 // We can only partially decide this relation. - if (pred == FCmpInst::FCMP_ULT || pred == FCmpInst::FCMP_OLT) + if (Pred.isOneOf(Predicate::FCMP_ULT, Predicate::FCMP_OLT)) Result = 0; - else if (pred == FCmpInst::FCMP_UGT || pred == FCmpInst::FCMP_OGT) + else if (Pred.isOneOf(Predicate::FCMP_UGT, Predicate::FCMP_OGT)) Result = 1; break; - case FCmpInst::FCMP_ONE: // We know that C1 != C2 + case Predicate::FCMP_ONE: // We know that C1 != C2 // We can only partially decide this relation. - if (pred == FCmpInst::FCMP_OEQ || pred == FCmpInst::FCMP_UEQ) + if (Pred.isOneOf(Predicate::FCMP_OEQ, Predicate::FCMP_UEQ)) Result = 0; - else if (pred == FCmpInst::FCMP_ONE || pred == FCmpInst::FCMP_UNE) + else if (Pred.isOneOf(Predicate::FCMP_ONE, Predicate::FCMP_UNE)) Result = 1; break; } @@ -1886,67 +1899,100 @@ } else { // Evaluate the relation between the two constants, per the predicate. int Result = -1; // -1 = unknown, 0 = known false, 1 = known true. - switch (evaluateICmpRelation(C1, C2, - CmpInst::isSigned((CmpInst::Predicate)pred))) { + switch (evaluateICmpRelation(C1, C2, Pred.isSigned()).getKind()) { default: llvm_unreachable("Unknown relational!"); - case ICmpInst::BAD_ICMP_PREDICATE: + case Predicate::BAD_ICMP_PREDICATE: break; // Couldn't determine anything about these constants. - case ICmpInst::ICMP_EQ: // We know the constants are equal! + case Predicate::ICMP_EQ: // We know the constants are equal! // If we know the constants are equal, we can decide the result of this // computation precisely. - Result = ICmpInst::isTrueWhenEqual((ICmpInst::Predicate)pred); + Result = Pred.isTrueWhenEqual(); break; - case ICmpInst::ICMP_ULT: - switch (pred) { - case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_NE: case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULT: + switch (Pred.getKind()) { + default: + llvm_unreachable("unexpected predicate kind"); + case Predicate::ICMP_ULT: + case Predicate::ICMP_NE: + case Predicate::ICMP_ULE: Result = 1; break; - case ICmpInst::ICMP_UGT: case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGT: + case Predicate::ICMP_EQ: + case Predicate::ICMP_UGE: Result = 0; break; } break; - case ICmpInst::ICMP_SLT: - switch (pred) { - case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_NE: case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLT: + switch (Pred.getKind()) { + default: + llvm_unreachable("unexpected predicate kind"); + case Predicate::ICMP_SLT: + case Predicate::ICMP_NE: + case Predicate::ICMP_SLE: Result = 1; break; - case ICmpInst::ICMP_SGT: case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGT: + case Predicate::ICMP_EQ: + case Predicate::ICMP_SGE: Result = 0; break; } break; - case ICmpInst::ICMP_UGT: - switch (pred) { - case ICmpInst::ICMP_UGT: case ICmpInst::ICMP_NE: case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGT: + switch (Pred.getKind()) { + default: + llvm_unreachable("unexpected predicate kind"); + case Predicate::ICMP_UGT: + case Predicate::ICMP_NE: + case Predicate::ICMP_UGE: Result = 1; break; - case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULT: + case Predicate::ICMP_EQ: + case Predicate::ICMP_ULE: Result = 0; break; } break; - case ICmpInst::ICMP_SGT: - switch (pred) { - case ICmpInst::ICMP_SGT: case ICmpInst::ICMP_NE: case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGT: + switch (Pred.getKind()) { + default: + llvm_unreachable("unexpected predicate kind"); + case Predicate::ICMP_SGT: + case Predicate::ICMP_NE: + case Predicate::ICMP_SGE: Result = 1; break; - case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLT: + case Predicate::ICMP_EQ: + case Predicate::ICMP_SLE: Result = 0; break; } break; - case ICmpInst::ICMP_ULE: - if (pred == ICmpInst::ICMP_UGT) Result = 0; - if (pred == ICmpInst::ICMP_ULT || pred == ICmpInst::ICMP_ULE) Result = 1; + case Predicate::ICMP_ULE: + if (Pred == Predicate::ICMP_UGT) + Result = 0; + if (Pred.isOneOf(Predicate::ICMP_ULT, Predicate::ICMP_ULE)) + Result = 1; break; - case ICmpInst::ICMP_SLE: - if (pred == ICmpInst::ICMP_SGT) Result = 0; - if (pred == ICmpInst::ICMP_SLT || pred == ICmpInst::ICMP_SLE) Result = 1; + case Predicate::ICMP_SLE: + if (Pred == Predicate::ICMP_SGT) + Result = 0; + if (Pred.isOneOf(Predicate::ICMP_SLT, Predicate::ICMP_SLE)) + Result = 1; break; - case ICmpInst::ICMP_UGE: - if (pred == ICmpInst::ICMP_ULT) Result = 0; - if (pred == ICmpInst::ICMP_UGT || pred == ICmpInst::ICMP_UGE) Result = 1; + case Predicate::ICMP_UGE: + if (Pred == Predicate::ICMP_ULT) + Result = 0; + if (Pred.isOneOf(Predicate::ICMP_UGT, Predicate::ICMP_UGE)) + Result = 1; break; - case ICmpInst::ICMP_SGE: - if (pred == ICmpInst::ICMP_SLT) Result = 0; - if (pred == ICmpInst::ICMP_SGT || pred == ICmpInst::ICMP_SGE) Result = 1; + case Predicate::ICMP_SGE: + if (Pred == Predicate::ICMP_SLT) + Result = 0; + if (Pred.isOneOf(Predicate::ICMP_SGT, Predicate::ICMP_SGE)) + Result = 1; break; - case ICmpInst::ICMP_NE: - if (pred == ICmpInst::ICMP_EQ) Result = 0; - if (pred == ICmpInst::ICMP_NE) Result = 1; + case Predicate::ICMP_NE: + if (Pred == Predicate::ICMP_EQ) + Result = 0; + if (Pred == Predicate::ICMP_NE) + Result = 1; break; } @@ -1962,16 +2008,14 @@ if (CE2->getOpcode() == Instruction::BitCast && CE2->getType()->isVectorTy() == CE2Op0->getType()->isVectorTy()) { Constant *Inverse = ConstantExpr::getBitCast(C1, CE2Op0->getType()); - return ConstantExpr::getICmp(pred, Inverse, CE2Op0); + return ConstantExpr::getICmp(Pred, Inverse, CE2Op0); } } // If the left hand side is an extension, try eliminating it. if (ConstantExpr *CE1 = dyn_cast(C1)) { - if ((CE1->getOpcode() == Instruction::SExt && - ICmpInst::isSigned((ICmpInst::Predicate)pred)) || - (CE1->getOpcode() == Instruction::ZExt && - !ICmpInst::isSigned((ICmpInst::Predicate)pred))){ + if ((CE1->getOpcode() == Instruction::SExt && Pred.isSigned()) || + (CE1->getOpcode() == Instruction::ZExt && !Pred.isSigned())) { Constant *CE1Op0 = CE1->getOperand(0); Constant *CE1Inverse = ConstantExpr::getTrunc(CE1, CE1Op0->getType()); if (CE1Inverse == CE1Op0) { @@ -1979,7 +2023,7 @@ Constant *C2Inverse = ConstantExpr::getTrunc(C2, CE1Op0->getType()); if (ConstantExpr::getCast(CE1->getOpcode(), C2Inverse, C2->getType()) == C2) - return ConstantExpr::getICmp(pred, CE1Inverse, C2Inverse); + return ConstantExpr::getICmp(Pred, CE1Inverse, C2Inverse); } } } @@ -1989,8 +2033,7 @@ // If C2 is a constant expr and C1 isn't, flip them around and fold the // other way if possible. // Also, if C1 is null and C2 isn't, flip them around. - pred = ICmpInst::getSwappedPredicate((ICmpInst::Predicate)pred); - return ConstantExpr::getICmp(pred, C2, C1); + return ConstantExpr::getICmp(Pred.getSwapped(), C2, C1); } } return nullptr; Index: lib/IR/ConstantRange.cpp =================================================================== --- lib/IR/ConstantRange.cpp +++ lib/IR/ConstantRange.cpp @@ -51,64 +51,64 @@ "Lower == Upper, but they aren't min or max value!"); } -ConstantRange ConstantRange::makeAllowedICmpRegion(CmpInst::Predicate Pred, +ConstantRange ConstantRange::makeAllowedICmpRegion(Predicate Pred, const ConstantRange &CR) { if (CR.isEmptySet()) return CR; uint32_t W = CR.getBitWidth(); - switch (Pred) { + switch (Pred.getKind()) { default: llvm_unreachable("Invalid ICmp predicate to makeAllowedICmpRegion()"); - case CmpInst::ICMP_EQ: + case Predicate::ICMP_EQ: return CR; - case CmpInst::ICMP_NE: + case Predicate::ICMP_NE: if (CR.isSingleElement()) return ConstantRange(CR.getUpper(), CR.getLower()); return ConstantRange(W); - case CmpInst::ICMP_ULT: { + case Predicate::ICMP_ULT: { APInt UMax(CR.getUnsignedMax()); if (UMax.isMinValue()) return ConstantRange(W, /* empty */ false); return ConstantRange(APInt::getMinValue(W), UMax); } - case CmpInst::ICMP_SLT: { + case Predicate::ICMP_SLT: { APInt SMax(CR.getSignedMax()); if (SMax.isMinSignedValue()) return ConstantRange(W, /* empty */ false); return ConstantRange(APInt::getSignedMinValue(W), SMax); } - case CmpInst::ICMP_ULE: { + case Predicate::ICMP_ULE: { APInt UMax(CR.getUnsignedMax()); if (UMax.isMaxValue()) return ConstantRange(W); return ConstantRange(APInt::getMinValue(W), UMax + 1); } - case CmpInst::ICMP_SLE: { + case Predicate::ICMP_SLE: { APInt SMax(CR.getSignedMax()); if (SMax.isMaxSignedValue()) return ConstantRange(W); return ConstantRange(APInt::getSignedMinValue(W), SMax + 1); } - case CmpInst::ICMP_UGT: { + case Predicate::ICMP_UGT: { APInt UMin(CR.getUnsignedMin()); if (UMin.isMaxValue()) return ConstantRange(W, /* empty */ false); return ConstantRange(UMin + 1, APInt::getNullValue(W)); } - case CmpInst::ICMP_SGT: { + case Predicate::ICMP_SGT: { APInt SMin(CR.getSignedMin()); if (SMin.isMaxSignedValue()) return ConstantRange(W, /* empty */ false); return ConstantRange(SMin + 1, APInt::getSignedMinValue(W)); } - case CmpInst::ICMP_UGE: { + case Predicate::ICMP_UGE: { APInt UMin(CR.getUnsignedMin()); if (UMin.isMinValue()) return ConstantRange(W); return ConstantRange(UMin, APInt::getNullValue(W)); } - case CmpInst::ICMP_SGE: { + case Predicate::ICMP_SGE: { APInt SMin(CR.getSignedMin()); if (SMin.isMinSignedValue()) return ConstantRange(W); @@ -117,17 +117,16 @@ } } -ConstantRange ConstantRange::makeSatisfyingICmpRegion(CmpInst::Predicate Pred, +ConstantRange ConstantRange::makeSatisfyingICmpRegion(Predicate Pred, const ConstantRange &CR) { // Follows from De-Morgan's laws: // // ~(~A union ~B) == A intersect B. // - return makeAllowedICmpRegion(CmpInst::getInversePredicate(Pred), CR) - .inverse(); + return makeAllowedICmpRegion(Pred.getInverse(), CR).inverse(); } -ConstantRange ConstantRange::makeExactICmpRegion(CmpInst::Predicate Pred, +ConstantRange ConstantRange::makeExactICmpRegion(Predicate Pred, const APInt &C) { // Computes the exact range that is equal to both the constant ranges returned // by makeAllowedICmpRegion and makeSatisfyingICmpRegion. This is always true @@ -139,22 +138,21 @@ return makeAllowedICmpRegion(Pred, C); } -bool ConstantRange::getEquivalentICmp(CmpInst::Predicate &Pred, - APInt &RHS) const { +bool ConstantRange::getEquivalentICmp(Predicate &Pred, APInt &RHS) const { bool Success = false; if (isFullSet() || isEmptySet()) { - Pred = isEmptySet() ? CmpInst::ICMP_ULT : CmpInst::ICMP_UGE; + Pred = isEmptySet() ? Predicate::ICMP_ULT : Predicate::ICMP_UGE; RHS = APInt(getBitWidth(), 0); Success = true; } else if (getLower().isMinSignedValue() || getLower().isMinValue()) { - Pred = - getLower().isMinSignedValue() ? CmpInst::ICMP_SLT : CmpInst::ICMP_ULT; + Pred = getLower().isMinSignedValue() ? Predicate::ICMP_SLT + : Predicate::ICMP_ULT; RHS = getUpper(); Success = true; } else if (getUpper().isMinSignedValue() || getUpper().isMinValue()) { - Pred = - getUpper().isMinSignedValue() ? CmpInst::ICMP_SGE : CmpInst::ICMP_UGE; + Pred = getUpper().isMinSignedValue() ? Predicate::ICMP_SGE + : Predicate::ICMP_UGE; RHS = getLower(); Success = true; } Index: lib/IR/Constants.cpp =================================================================== --- lib/IR/Constants.cpp +++ lib/IR/Constants.cpp @@ -1107,7 +1107,7 @@ return cast(this)->Indices; } -unsigned ConstantExpr::getPredicate() const { +Predicate ConstantExpr::getPredicate() const { return cast(this)->predicate; } @@ -1852,25 +1852,41 @@ Type::getInt64Ty(Ty->getContext())); } -Constant *ConstantExpr::getCompare(unsigned short Predicate, Constant *C1, - Constant *C2, bool OnlyIfReduced) { +Constant *ConstantExpr::getCompare(Predicate Pred, Constant *C1, Constant *C2, + bool OnlyIfReduced) { assert(C1->getType() == C2->getType() && "Op types should be identical!"); - switch (Predicate) { + switch (Pred.getKind()) { default: llvm_unreachable("Invalid CmpInst predicate"); - case CmpInst::FCMP_FALSE: case CmpInst::FCMP_OEQ: case CmpInst::FCMP_OGT: - case CmpInst::FCMP_OGE: case CmpInst::FCMP_OLT: case CmpInst::FCMP_OLE: - case CmpInst::FCMP_ONE: case CmpInst::FCMP_ORD: case CmpInst::FCMP_UNO: - case CmpInst::FCMP_UEQ: case CmpInst::FCMP_UGT: case CmpInst::FCMP_UGE: - case CmpInst::FCMP_ULT: case CmpInst::FCMP_ULE: case CmpInst::FCMP_UNE: - case CmpInst::FCMP_TRUE: - return getFCmp(Predicate, C1, C2, OnlyIfReduced); - - case CmpInst::ICMP_EQ: case CmpInst::ICMP_NE: case CmpInst::ICMP_UGT: - case CmpInst::ICMP_UGE: case CmpInst::ICMP_ULT: case CmpInst::ICMP_ULE: - case CmpInst::ICMP_SGT: case CmpInst::ICMP_SGE: case CmpInst::ICMP_SLT: - case CmpInst::ICMP_SLE: - return getICmp(Predicate, C1, C2, OnlyIfReduced); + case Predicate::FCMP_FALSE: + case Predicate::FCMP_OEQ: + case Predicate::FCMP_OGT: + case Predicate::FCMP_OGE: + case Predicate::FCMP_OLT: + case Predicate::FCMP_OLE: + case Predicate::FCMP_ONE: + case Predicate::FCMP_ORD: + case Predicate::FCMP_UNO: + case Predicate::FCMP_UEQ: + case Predicate::FCMP_UGT: + case Predicate::FCMP_UGE: + case Predicate::FCMP_ULT: + case Predicate::FCMP_ULE: + case Predicate::FCMP_UNE: + case Predicate::FCMP_TRUE: + return getFCmp(Pred, C1, C2, OnlyIfReduced); + + case Predicate::ICMP_EQ: + case Predicate::ICMP_NE: + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: + case Predicate::ICMP_SGT: + case Predicate::ICMP_SGE: + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: + return getICmp(Pred, C1, C2, OnlyIfReduced); } } @@ -1945,13 +1961,12 @@ return pImpl->ExprConstants.getOrCreate(ReqTy, Key); } -Constant *ConstantExpr::getICmp(unsigned short pred, Constant *LHS, - Constant *RHS, bool OnlyIfReduced) { +Constant *ConstantExpr::getICmp(Predicate Pred, Constant *LHS, Constant *RHS, + bool OnlyIfReduced) { assert(LHS->getType() == RHS->getType()); - assert(pred >= ICmpInst::FIRST_ICMP_PREDICATE && - pred <= ICmpInst::LAST_ICMP_PREDICATE && "Invalid ICmp Predicate"); + assert(Pred.isInt() && "Invalid ICmp Predicate"); - if (Constant *FC = ConstantFoldCompareInstruction(pred, LHS, RHS)) + if (Constant *FC = ConstantFoldCompareInstruction(Pred, LHS, RHS)) return FC; // Fold a few common cases... if (OnlyIfReduced) @@ -1960,7 +1975,8 @@ // Look up the constant in the table first to ensure uniqueness Constant *ArgVec[] = { LHS, RHS }; // Get the key type with both the opcode and predicate - const ConstantExprKeyType Key(Instruction::ICmp, ArgVec, pred); + const ConstantExprKeyType Key(Instruction::ICmp, ArgVec, + static_cast(Pred.getKind())); Type *ResultTy = Type::getInt1Ty(LHS->getContext()); if (VectorType *VT = dyn_cast(LHS->getType())) @@ -1970,12 +1986,12 @@ return pImpl->ExprConstants.getOrCreate(ResultTy, Key); } -Constant *ConstantExpr::getFCmp(unsigned short pred, Constant *LHS, - Constant *RHS, bool OnlyIfReduced) { +Constant *ConstantExpr::getFCmp(Predicate Pred, Constant *LHS, Constant *RHS, + bool OnlyIfReduced) { assert(LHS->getType() == RHS->getType()); - assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && "Invalid FCmp Predicate"); + assert(Pred.isFP() && "Invalid FCmp Predicate"); - if (Constant *FC = ConstantFoldCompareInstruction(pred, LHS, RHS)) + if (Constant *FC = ConstantFoldCompareInstruction(Pred, LHS, RHS)) return FC; // Fold a few common cases... if (OnlyIfReduced) @@ -1984,7 +2000,8 @@ // Look up the constant in the table first to ensure uniqueness Constant *ArgVec[] = { LHS, RHS }; // Get the key type with both the opcode and predicate - const ConstantExprKeyType Key(Instruction::FCmp, ArgVec, pred); + const ConstantExprKeyType Key(Instruction::FCmp, ArgVec, + static_cast(Pred.getKind())); Type *ResultTy = Type::getInt1Ty(LHS->getContext()); if (VectorType *VT = dyn_cast(LHS->getType())) @@ -2889,8 +2906,8 @@ } case Instruction::ICmp: case Instruction::FCmp: - return CmpInst::Create((Instruction::OtherOps)getOpcode(), - (CmpInst::Predicate)getPredicate(), Ops[0], Ops[1]); + return CmpInst::Create((Instruction::OtherOps)getOpcode(), getPredicate(), + Ops[0], Ops[1]); default: assert(getNumOperands() == 2 && "Must be binary operator?"); Index: lib/IR/ConstantsContext.h =================================================================== --- lib/IR/ConstantsContext.h +++ lib/IR/ConstantsContext.h @@ -261,7 +261,7 @@ void *operator new(size_t s) { return User::operator new(s, 2); } - unsigned short predicate; + Predicate predicate; CompareConstantExpr(Type *ty, Instruction::OtherOps opc, unsigned short pred, Constant* LHS, Constant* RHS) : ConstantExpr(ty, opc, &Op<0>(), 2), predicate(pred) { @@ -456,13 +456,18 @@ ConstantExprKeyType(ArrayRef Operands, const ConstantExpr *CE) : Opcode(CE->getOpcode()), SubclassOptionalData(CE->getRawSubclassOptionalData()), - SubclassData(CE->isCompare() ? CE->getPredicate() : 0), Ops(Operands), + SubclassData(CE->isCompare() + ? static_cast(CE->getPredicate().getKind()) + : 0), + Ops(Operands), Indexes(CE->hasIndices() ? CE->getIndices() : ArrayRef()) {} ConstantExprKeyType(const ConstantExpr *CE, SmallVectorImpl &Storage) : Opcode(CE->getOpcode()), SubclassOptionalData(CE->getRawSubclassOptionalData()), - SubclassData(CE->isCompare() ? CE->getPredicate() : 0), + SubclassData(CE->isCompare() + ? static_cast(CE->getPredicate().getKind()) + : 0), Indexes(CE->hasIndices() ? CE->getIndices() : ArrayRef()) { assert(Storage.empty() && "Expected empty storage"); for (unsigned I = 0, E = CE->getNumOperands(); I != E; ++I) @@ -483,7 +488,8 @@ return false; if (Ops.size() != CE->getNumOperands()) return false; - if (SubclassData != (CE->isCompare() ? CE->getPredicate() : 0)) + if (SubclassData != + (CE->isCompare() ? static_cast(CE->getPredicate().getKind()) : 0)) return false; for (unsigned I = 0, E = Ops.size(); I != E; ++I) if (Ops[I] != CE->getOperand(I)) Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -1224,16 +1224,16 @@ unwrap(RHSConstant))); } -LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, - LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getICmp(Predicate, +LLVMValueRef LLVMConstICmp(LLVMIntPredicate Pred, LLVMValueRef LHSConstant, + LLVMValueRef RHSConstant) { + return wrap(ConstantExpr::getICmp(static_cast(Pred), unwrap(LHSConstant), unwrap(RHSConstant))); } -LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, - LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getFCmp(Predicate, +LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Pred, LLVMValueRef LHSConstant, + LLVMValueRef RHSConstant) { + return wrap(ConstantExpr::getFCmp(static_cast(Pred), unwrap(LHSConstant), unwrap(RHSConstant))); } @@ -2150,19 +2150,19 @@ LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) { if (ICmpInst *I = dyn_cast(unwrap(Inst))) - return (LLVMIntPredicate)I->getPredicate(); + return (LLVMIntPredicate)I->getPredicate().getKind(); if (ConstantExpr *CE = dyn_cast(unwrap(Inst))) if (CE->getOpcode() == Instruction::ICmp) - return (LLVMIntPredicate)CE->getPredicate(); + return (LLVMIntPredicate)CE->getPredicate().getKind(); return (LLVMIntPredicate)0; } LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst) { if (FCmpInst *I = dyn_cast(unwrap(Inst))) - return (LLVMRealPredicate)I->getPredicate(); + return (LLVMRealPredicate)I->getPredicate().getKind(); if (ConstantExpr *CE = dyn_cast(unwrap(Inst))) if (CE->getOpcode() == Instruction::FCmp) - return (LLVMRealPredicate)CE->getPredicate(); + return (LLVMRealPredicate)CE->getPredicate().getKind(); return (LLVMRealPredicate)0; } @@ -2977,15 +2977,15 @@ LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name) { - return wrap(unwrap(B)->CreateICmp(static_cast(Op), - unwrap(LHS), unwrap(RHS), Name)); + return wrap(unwrap(B)->CreateICmp(static_cast(Op), unwrap(LHS), + unwrap(RHS), Name)); } LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name) { - return wrap(unwrap(B)->CreateFCmp(static_cast(Op), - unwrap(LHS), unwrap(RHS), Name)); + return wrap(unwrap(B)->CreateFCmp(static_cast(Op), unwrap(LHS), + unwrap(RHS), Name)); } /*--.. Miscellaneous instructions ..........................................--*/ Index: lib/IR/Instructions.cpp =================================================================== --- lib/IR/Instructions.cpp +++ lib/IR/Instructions.cpp @@ -3357,59 +3357,47 @@ void CmpInst::anchor() {} -CmpInst::CmpInst(Type *ty, OtherOps op, Predicate predicate, Value *LHS, - Value *RHS, const Twine &Name, Instruction *InsertBefore) - : Instruction(ty, op, - OperandTraits::op_begin(this), - OperandTraits::operands(this), - InsertBefore) { - Op<0>() = LHS; - Op<1>() = RHS; - setPredicate((Predicate)predicate); +CmpInst::CmpInst(Type *ty, OtherOps op, Predicate Pred, Value *LHS, Value *RHS, + const Twine &Name, Instruction *InsertBefore) + : Instruction(ty, op, OperandTraits::op_begin(this), + OperandTraits::operands(this), InsertBefore) { + Op<0>() = LHS; + Op<1>() = RHS; + setPredicate(Pred); setName(Name); } -CmpInst::CmpInst(Type *ty, OtherOps op, Predicate predicate, Value *LHS, - Value *RHS, const Twine &Name, BasicBlock *InsertAtEnd) - : Instruction(ty, op, - OperandTraits::op_begin(this), - OperandTraits::operands(this), - InsertAtEnd) { +CmpInst::CmpInst(Type *ty, OtherOps op, Predicate Pred, Value *LHS, Value *RHS, + const Twine &Name, BasicBlock *InsertAtEnd) + : Instruction(ty, op, OperandTraits::op_begin(this), + OperandTraits::operands(this), InsertAtEnd) { Op<0>() = LHS; Op<1>() = RHS; - setPredicate((Predicate)predicate); + setPredicate(Pred); setName(Name); } -CmpInst * -CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, - const Twine &Name, Instruction *InsertBefore) { +CmpInst *CmpInst::Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2, + const Twine &Name, Instruction *InsertBefore) { if (Op == Instruction::ICmp) { if (InsertBefore) - return new ICmpInst(InsertBefore, CmpInst::Predicate(predicate), - S1, S2, Name); + return new ICmpInst(InsertBefore, Pred, S1, S2, Name); else - return new ICmpInst(CmpInst::Predicate(predicate), - S1, S2, Name); + return new ICmpInst(Pred, S1, S2, Name); } if (InsertBefore) - return new FCmpInst(InsertBefore, CmpInst::Predicate(predicate), - S1, S2, Name); + return new FCmpInst(InsertBefore, Pred, S1, S2, Name); else - return new FCmpInst(CmpInst::Predicate(predicate), - S1, S2, Name); + return new FCmpInst(Pred, S1, S2, Name); } -CmpInst * -CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, - const Twine &Name, BasicBlock *InsertAtEnd) { +CmpInst *CmpInst::Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2, + const Twine &Name, BasicBlock *InsertAtEnd) { if (Op == Instruction::ICmp) { - return new ICmpInst(*InsertAtEnd, CmpInst::Predicate(predicate), - S1, S2, Name); + return new ICmpInst(*InsertAtEnd, Pred, S1, S2, Name); } - return new FCmpInst(*InsertAtEnd, CmpInst::Predicate(predicate), - S1, S2, Name); + return new FCmpInst(*InsertAtEnd, Pred, S1, S2, Name); } void CmpInst::swapOperands() { @@ -3419,134 +3407,66 @@ cast(this)->swapOperands(); } -bool CmpInst::isCommutative() const { - if (const ICmpInst *IC = dyn_cast(this)) - return IC->isCommutative(); - return cast(this)->isCommutative(); -} - -bool CmpInst::isEquality() const { - if (const ICmpInst *IC = dyn_cast(this)) - return IC->isEquality(); - return cast(this)->isEquality(); -} - - -CmpInst::Predicate CmpInst::getInversePredicate(Predicate pred) { - switch (pred) { - default: llvm_unreachable("Unknown cmp predicate!"); - case ICMP_EQ: return ICMP_NE; - case ICMP_NE: return ICMP_EQ; - case ICMP_UGT: return ICMP_ULE; - case ICMP_ULT: return ICMP_UGE; - case ICMP_UGE: return ICMP_ULT; - case ICMP_ULE: return ICMP_UGT; - case ICMP_SGT: return ICMP_SLE; - case ICMP_SLT: return ICMP_SGE; - case ICMP_SGE: return ICMP_SLT; - case ICMP_SLE: return ICMP_SGT; - - case FCMP_OEQ: return FCMP_UNE; - case FCMP_ONE: return FCMP_UEQ; - case FCMP_OGT: return FCMP_ULE; - case FCMP_OLT: return FCMP_UGE; - case FCMP_OGE: return FCMP_ULT; - case FCMP_OLE: return FCMP_UGT; - case FCMP_UEQ: return FCMP_ONE; - case FCMP_UNE: return FCMP_OEQ; - case FCMP_UGT: return FCMP_OLE; - case FCMP_ULT: return FCMP_OGE; - case FCMP_UGE: return FCMP_OLT; - case FCMP_ULE: return FCMP_OGT; - case FCMP_ORD: return FCMP_UNO; - case FCMP_UNO: return FCMP_ORD; - case FCMP_TRUE: return FCMP_FALSE; - case FCMP_FALSE: return FCMP_TRUE; - } -} - void ICmpInst::anchor() {} -ICmpInst::Predicate ICmpInst::getSignedPredicate(Predicate pred) { - switch (pred) { - default: llvm_unreachable("Unknown icmp predicate!"); - case ICMP_EQ: case ICMP_NE: - case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE: - return pred; - case ICMP_UGT: return ICMP_SGT; - case ICMP_ULT: return ICMP_SLT; - case ICMP_UGE: return ICMP_SGE; - case ICMP_ULE: return ICMP_SLE; - } -} - -ICmpInst::Predicate ICmpInst::getUnsignedPredicate(Predicate pred) { - switch (pred) { - default: llvm_unreachable("Unknown icmp predicate!"); - case ICMP_EQ: case ICMP_NE: - case ICMP_UGT: case ICMP_ULT: case ICMP_UGE: case ICMP_ULE: - return pred; - case ICMP_SGT: return ICMP_UGT; - case ICMP_SLT: return ICMP_ULT; - case ICMP_SGE: return ICMP_UGE; - case ICMP_SLE: return ICMP_ULE; - } -} /// Initialize a set of values that all satisfy the condition with C. /// -ConstantRange -ICmpInst::makeConstantRange(Predicate pred, const APInt &C) { +ConstantRange ICmpInst::makeConstantRange(Predicate Pred, const APInt &C) { APInt Lower(C); APInt Upper(C); uint32_t BitWidth = C.getBitWidth(); - switch (pred) { + switch (Pred.getKind()) { default: llvm_unreachable("Invalid ICmp opcode to ConstantRange ctor!"); - case ICmpInst::ICMP_EQ: ++Upper; break; - case ICmpInst::ICMP_NE: ++Lower; break; - case ICmpInst::ICMP_ULT: + case Predicate::ICMP_EQ: + ++Upper; + break; + case Predicate::ICMP_NE: + ++Lower; + break; + case Predicate::ICMP_ULT: Lower = APInt::getMinValue(BitWidth); // Check for an empty-set condition. if (Lower == Upper) return ConstantRange(BitWidth, /*isFullSet=*/false); break; - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: Lower = APInt::getSignedMinValue(BitWidth); // Check for an empty-set condition. if (Lower == Upper) return ConstantRange(BitWidth, /*isFullSet=*/false); break; - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_UGT: ++Lower; Upper = APInt::getMinValue(BitWidth); // Min = Next(Max) // Check for an empty-set condition. if (Lower == Upper) return ConstantRange(BitWidth, /*isFullSet=*/false); break; - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: ++Lower; Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max) // Check for an empty-set condition. if (Lower == Upper) return ConstantRange(BitWidth, /*isFullSet=*/false); break; - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULE: Lower = APInt::getMinValue(BitWidth); ++Upper; // Check for a full-set condition. if (Lower == Upper) return ConstantRange(BitWidth, /*isFullSet=*/true); break; - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLE: Lower = APInt::getSignedMinValue(BitWidth); ++Upper; // Check for a full-set condition. if (Lower == Upper) return ConstantRange(BitWidth, /*isFullSet=*/true); break; - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: Upper = APInt::getMinValue(BitWidth); // Min = Next(Max) // Check for a full-set condition. if (Lower == Upper) return ConstantRange(BitWidth, /*isFullSet=*/true); break; - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max) // Check for a full-set condition. if (Lower == Upper) @@ -3556,132 +3476,6 @@ return ConstantRange(Lower, Upper); } -CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) { - switch (pred) { - default: llvm_unreachable("Unknown cmp predicate!"); - case ICMP_EQ: case ICMP_NE: - return pred; - case ICMP_SGT: return ICMP_SLT; - case ICMP_SLT: return ICMP_SGT; - case ICMP_SGE: return ICMP_SLE; - case ICMP_SLE: return ICMP_SGE; - case ICMP_UGT: return ICMP_ULT; - case ICMP_ULT: return ICMP_UGT; - case ICMP_UGE: return ICMP_ULE; - case ICMP_ULE: return ICMP_UGE; - - case FCMP_FALSE: case FCMP_TRUE: - case FCMP_OEQ: case FCMP_ONE: - case FCMP_UEQ: case FCMP_UNE: - case FCMP_ORD: case FCMP_UNO: - return pred; - case FCMP_OGT: return FCMP_OLT; - case FCMP_OLT: return FCMP_OGT; - case FCMP_OGE: return FCMP_OLE; - case FCMP_OLE: return FCMP_OGE; - case FCMP_UGT: return FCMP_ULT; - case FCMP_ULT: return FCMP_UGT; - case FCMP_UGE: return FCMP_ULE; - case FCMP_ULE: return FCMP_UGE; - } -} - -CmpInst::Predicate CmpInst::getSignedPredicate(Predicate pred) { - assert(CmpInst::isUnsigned(pred) && "Call only with signed predicates!"); - - switch (pred) { - default: - llvm_unreachable("Unknown predicate!"); - case CmpInst::ICMP_ULT: - return CmpInst::ICMP_SLT; - case CmpInst::ICMP_ULE: - return CmpInst::ICMP_SLE; - case CmpInst::ICMP_UGT: - return CmpInst::ICMP_SGT; - case CmpInst::ICMP_UGE: - return CmpInst::ICMP_SGE; - } -} - -bool CmpInst::isUnsigned(Predicate predicate) { - switch (predicate) { - default: return false; - case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_ULE: case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_UGE: return true; - } -} - -bool CmpInst::isSigned(Predicate predicate) { - switch (predicate) { - default: return false; - case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_SLE: case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_SGE: return true; - } -} - -bool CmpInst::isOrdered(Predicate predicate) { - switch (predicate) { - default: return false; - case FCmpInst::FCMP_OEQ: case FCmpInst::FCMP_ONE: case FCmpInst::FCMP_OGT: - case FCmpInst::FCMP_OLT: case FCmpInst::FCMP_OGE: case FCmpInst::FCMP_OLE: - case FCmpInst::FCMP_ORD: return true; - } -} - -bool CmpInst::isUnordered(Predicate predicate) { - switch (predicate) { - default: return false; - case FCmpInst::FCMP_UEQ: case FCmpInst::FCMP_UNE: case FCmpInst::FCMP_UGT: - case FCmpInst::FCMP_ULT: case FCmpInst::FCMP_UGE: case FCmpInst::FCMP_ULE: - case FCmpInst::FCMP_UNO: return true; - } -} - -bool CmpInst::isTrueWhenEqual(Predicate predicate) { - switch(predicate) { - default: return false; - case ICMP_EQ: case ICMP_UGE: case ICMP_ULE: case ICMP_SGE: case ICMP_SLE: - case FCMP_TRUE: case FCMP_UEQ: case FCMP_UGE: case FCMP_ULE: return true; - } -} - -bool CmpInst::isFalseWhenEqual(Predicate predicate) { - switch(predicate) { - case ICMP_NE: case ICMP_UGT: case ICMP_ULT: case ICMP_SGT: case ICMP_SLT: - case FCMP_FALSE: case FCMP_ONE: case FCMP_OGT: case FCMP_OLT: return true; - default: return false; - } -} - -bool CmpInst::isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2) { - // If the predicates match, then we know the first condition implies the - // second is true. - if (Pred1 == Pred2) - return true; - - switch (Pred1) { - default: - break; - case ICMP_EQ: - // A == B implies A >=u B, A <=u B, A >=s B, and A <=s B are true. - return Pred2 == ICMP_UGE || Pred2 == ICMP_ULE || Pred2 == ICMP_SGE || - Pred2 == ICMP_SLE; - case ICMP_UGT: // A >u B implies A != B and A >=u B are true. - return Pred2 == ICMP_NE || Pred2 == ICMP_UGE; - case ICMP_ULT: // A s B implies A != B and A >=s B are true. - return Pred2 == ICMP_NE || Pred2 == ICMP_SGE; - case ICMP_SLT: // A isIntOrIntVectorTy() || Op0Ty->getScalarType()->isPointerTy(), "Invalid operand types for ICmp instruction", &IC); // Check that the predicate is valid. - Assert(IC.getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE && - IC.getPredicate() <= CmpInst::LAST_ICMP_PREDICATE, - "Invalid predicate in ICmp instruction!", &IC); + Assert(IC.getPredicate().isInt(), "Invalid predicate in ICmp instruction!", + &IC); visitInstruction(IC); } @@ -2861,9 +2860,8 @@ Assert(Op0Ty->isFPOrFPVectorTy(), "Invalid operand types for FCmp instruction", &FC); // Check that the predicate is valid. - Assert(FC.getPredicate() >= CmpInst::FIRST_FCMP_PREDICATE && - FC.getPredicate() <= CmpInst::LAST_FCMP_PREDICATE, - "Invalid predicate in FCmp instruction!", &FC); + Assert(FC.getPredicate().isFP(), "Invalid predicate in FCmp instruction!", + &FC); visitInstruction(FC); } Index: lib/Support/CMakeLists.txt =================================================================== --- lib/Support/CMakeLists.txt +++ lib/Support/CMakeLists.txt @@ -72,6 +72,7 @@ MD5.cpp Options.cpp PluginLoader.cpp + Predicate.cpp PrettyStackTrace.cpp RandomNumberGenerator.cpp Regex.cpp Index: lib/Support/Predicate.cpp =================================================================== --- /dev/null +++ lib/Support/Predicate.cpp @@ -0,0 +1,375 @@ +#include "llvm/Support/Predicate.h" + +using namespace llvm; + +Predicate Predicate::getInverse() const { + switch (Pred) { + default: + llvm_unreachable("Unknown cmp predicate!"); + case ICMP_EQ: + return ICMP_NE; + case ICMP_NE: + return ICMP_EQ; + case ICMP_UGT: + return ICMP_ULE; + case ICMP_ULT: + return ICMP_UGE; + case ICMP_UGE: + return ICMP_ULT; + case ICMP_ULE: + return ICMP_UGT; + case ICMP_SGT: + return ICMP_SLE; + case ICMP_SLT: + return ICMP_SGE; + case ICMP_SGE: + return ICMP_SLT; + case ICMP_SLE: + return ICMP_SGT; + + case FCMP_OEQ: + return FCMP_UNE; + case FCMP_ONE: + return FCMP_UEQ; + case FCMP_OGT: + return FCMP_ULE; + case FCMP_OLT: + return FCMP_UGE; + case FCMP_OGE: + return FCMP_ULT; + case FCMP_OLE: + return FCMP_UGT; + case FCMP_UEQ: + return FCMP_ONE; + case FCMP_UNE: + return FCMP_OEQ; + case FCMP_UGT: + return FCMP_OLE; + case FCMP_ULT: + return FCMP_OGE; + case FCMP_UGE: + return FCMP_OLT; + case FCMP_ULE: + return FCMP_OGT; + case FCMP_ORD: + return FCMP_UNO; + case FCMP_UNO: + return FCMP_ORD; + case FCMP_TRUE: + return FCMP_FALSE; + case FCMP_FALSE: + return FCMP_TRUE; + } +} + +Predicate Predicate::getSigned() const { + switch (Pred) { + default: + llvm_unreachable("Unknown icmp predicate!"); + case ICMP_EQ: + case ICMP_NE: + case ICMP_SGT: + case ICMP_SLT: + case ICMP_SGE: + case ICMP_SLE: + return Pred; + case ICMP_UGT: + return ICMP_SGT; + case ICMP_ULT: + return ICMP_SLT; + case ICMP_UGE: + return ICMP_SGE; + case ICMP_ULE: + return ICMP_SLE; + } +} + +Predicate Predicate::getUnsigned() const { + switch (Pred) { + default: + llvm_unreachable("Unknown icmp predicate!"); + case ICMP_EQ: + case ICMP_NE: + case ICMP_UGT: + case ICMP_ULT: + case ICMP_UGE: + case ICMP_ULE: + return Pred; + case ICMP_SGT: + return ICMP_UGT; + case ICMP_SLT: + return ICMP_ULT; + case ICMP_SGE: + return ICMP_UGE; + case ICMP_SLE: + return ICMP_ULE; + } +} + +Predicate Predicate::getSwapped() const { + switch (Pred) { + default: + llvm_unreachable("Unknown cmp predicate!"); + case ICMP_EQ: + case ICMP_NE: + return Pred; + case ICMP_SGT: + return ICMP_SLT; + case ICMP_SLT: + return ICMP_SGT; + case ICMP_SGE: + return ICMP_SLE; + case ICMP_SLE: + return ICMP_SGE; + case ICMP_UGT: + return ICMP_ULT; + case ICMP_ULT: + return ICMP_UGT; + case ICMP_UGE: + return ICMP_ULE; + case ICMP_ULE: + return ICMP_UGE; + + case FCMP_FALSE: + case FCMP_TRUE: + case FCMP_OEQ: + case FCMP_ONE: + case FCMP_UEQ: + case FCMP_UNE: + case FCMP_ORD: + case FCMP_UNO: + return Pred; + case FCMP_OGT: + return FCMP_OLT; + case FCMP_OLT: + return FCMP_OGT; + case FCMP_OGE: + return FCMP_OLE; + case FCMP_OLE: + return FCMP_OGE; + case FCMP_UGT: + return FCMP_ULT; + case FCMP_ULT: + return FCMP_UGT; + case FCMP_UGE: + return FCMP_ULE; + case FCMP_ULE: + return FCMP_UGE; + } +} + +bool Predicate::isUnsigned() const { + switch (Pred) { + default: + return false; + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: + return true; + } +} + +bool Predicate::isSigned() const { + switch (Pred) { + default: + return false; + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: + case Predicate::ICMP_SGT: + case Predicate::ICMP_SGE: + return true; + } +} + +bool Predicate::isOrdered() const { + switch (Pred) { + default: + return false; + case Predicate::FCMP_OEQ: + case Predicate::FCMP_ONE: + case Predicate::FCMP_OGT: + case Predicate::FCMP_OLT: + case Predicate::FCMP_OGE: + case Predicate::FCMP_OLE: + case Predicate::FCMP_ORD: + return true; + } +} + +bool Predicate::isUnordered() const { + switch (Pred) { + default: + return false; + case Predicate::FCMP_UEQ: + case Predicate::FCMP_UNE: + case Predicate::FCMP_UGT: + case Predicate::FCMP_ULT: + case Predicate::FCMP_UGE: + case Predicate::FCMP_ULE: + case Predicate::FCMP_UNO: + return true; + } +} + +bool Predicate::isTrueWhenEqual() const { + switch (Pred) { + default: + return false; + case ICMP_EQ: + case ICMP_UGE: + case ICMP_ULE: + case ICMP_SGE: + case ICMP_SLE: + case FCMP_TRUE: + case FCMP_UEQ: + case FCMP_UGE: + case FCMP_ULE: + return true; + } +} + +bool Predicate::isFalseWhenEqual() const { + switch (Pred) { + case ICMP_NE: + case ICMP_UGT: + case ICMP_ULT: + case ICMP_SGT: + case ICMP_SLT: + case FCMP_FALSE: + case FCMP_ONE: + case FCMP_OGT: + case FCMP_OLT: + return true; + default: + return false; + } +} + +bool Predicate::isEquality() const { + return Pred == ICMP_EQ || Pred == ICMP_NE || Pred == FCMP_OEQ || + Pred == FCMP_ONE || Pred == FCMP_UEQ || Pred == FCMP_UNE; +} + +bool Predicate::isCommutative() const { + return isEquality() || Pred == FCMP_TRUE || Pred == FCMP_FALSE || + Pred == FCMP_ORD || Pred == FCMP_UNO; +} + +bool Predicate::isRelational() const { return !isCommutative(); } + +bool Predicate::isImpliedTrueByMatchingCmp(Predicate Pred2) const { + // If the predicates match, then we know the first condition implies the + // second is true. + if (Pred == Pred2.Pred) + return true; + + switch (Pred) { + default: + break; + case ICMP_EQ: + // A == B implies A >=u B, A <=u B, A >=s B, and A <=s B are true. + return Pred2.Pred == ICMP_UGE || Pred2.Pred == ICMP_ULE || + Pred2.Pred == ICMP_SGE || Pred2.Pred == ICMP_SLE; + case ICMP_UGT: // A >u B implies A != B and A >=u B are true. + return Pred2.Pred == ICMP_NE || Pred2.Pred == ICMP_UGE; + case ICMP_ULT: // A s B implies A != B and A >=s B are true. + return Pred2.Pred == ICMP_NE || Pred2.Pred == ICMP_SGE; + case ICMP_SLT: // A (BI->getCondition()) && "Expected cmp instruction"); const CmpInst *CI = cast(BI->getCondition()); - CmpInst::Predicate Predicate = optimizeCmpPredicate(CI); + Predicate Pred = optimizeCmpPredicate(CI); const Value *LHS = CI->getOperand(0); const Value *RHS = CI->getOperand(1); @@ -2226,16 +2226,16 @@ // Try to take advantage of fallthrough opportunities. if (FuncInfo.MBB->isLayoutSuccessor(TBB)) { std::swap(TBB, FBB); - Predicate = CmpInst::getInversePredicate(Predicate); + Pred = Pred.getInverse(); } int TestBit = -1; bool IsCmpNE; - switch (Predicate) { + switch (Pred.getKind()) { default: return false; - case CmpInst::ICMP_EQ: - case CmpInst::ICMP_NE: + case Predicate::ICMP_EQ: + case Predicate::ICMP_NE: if (isa(LHS) && cast(LHS)->isNullValue()) std::swap(LHS, RHS); @@ -2261,18 +2261,18 @@ if (VT == MVT::i1) TestBit = 0; - IsCmpNE = Predicate == CmpInst::ICMP_NE; + IsCmpNE = Pred == Predicate::ICMP_NE; break; - case CmpInst::ICMP_SLT: - case CmpInst::ICMP_SGE: + case Predicate::ICMP_SLT: + case Predicate::ICMP_SGE: if (!isa(RHS) || !cast(RHS)->isNullValue()) return false; TestBit = BW - 1; - IsCmpNE = Predicate == CmpInst::ICMP_SLT; + IsCmpNE = Pred == Predicate::ICMP_SLT; break; - case CmpInst::ICMP_SGT: - case CmpInst::ICMP_SLE: + case Predicate::ICMP_SGT: + case Predicate::ICMP_SLE: if (!isa(RHS)) return false; @@ -2280,7 +2280,7 @@ return false; TestBit = BW - 1; - IsCmpNE = Predicate == CmpInst::ICMP_SLE; + IsCmpNE = Pred == Predicate::ICMP_SLE; break; } // end switch @@ -2338,14 +2338,14 @@ if (const CmpInst *CI = dyn_cast(BI->getCondition())) { if (CI->hasOneUse() && isValueAvailable(CI)) { // Try to optimize or fold the cmp. - CmpInst::Predicate Predicate = optimizeCmpPredicate(CI); - switch (Predicate) { + Predicate Pred = optimizeCmpPredicate(CI); + switch (Pred.getKind()) { default: break; - case CmpInst::FCMP_FALSE: + case Predicate::FCMP_FALSE: fastEmitBranch(FBB, DbgLoc); return true; - case CmpInst::FCMP_TRUE: + case Predicate::FCMP_TRUE: fastEmitBranch(TBB, DbgLoc); return true; } @@ -2357,7 +2357,7 @@ // Try to take advantage of fallthrough opportunities. if (FuncInfo.MBB->isLayoutSuccessor(TBB)) { std::swap(TBB, FBB); - Predicate = CmpInst::getInversePredicate(Predicate); + Pred = Pred.getInverse(); } // Emit the cmp. @@ -2366,16 +2366,16 @@ // FCMP_UEQ and FCMP_ONE cannot be checked with a single branch // instruction. - AArch64CC::CondCode CC = getCompareCC(Predicate); + AArch64CC::CondCode CC = getCompareCC(Pred); AArch64CC::CondCode ExtraCC = AArch64CC::AL; - switch (Predicate) { + switch (Pred.getKind()) { default: break; - case CmpInst::FCMP_UEQ: + case Predicate::FCMP_UEQ: ExtraCC = AArch64CC::EQ; CC = AArch64CC::VS; break; - case CmpInst::FCMP_ONE: + case Predicate::FCMP_ONE: ExtraCC = AArch64CC::MI; CC = AArch64CC::GT; break; @@ -2480,18 +2480,18 @@ return false; // Try to optimize or fold the cmp. - CmpInst::Predicate Predicate = optimizeCmpPredicate(CI); + Predicate Pred = optimizeCmpPredicate(CI); unsigned ResultReg = 0; - switch (Predicate) { + switch (Pred.getKind()) { default: break; - case CmpInst::FCMP_FALSE: + case Predicate::FCMP_FALSE: ResultReg = createResultReg(&AArch64::GPR32RegClass); BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TargetOpcode::COPY), ResultReg) .addReg(AArch64::WZR, getKillRegState(true)); break; - case CmpInst::FCMP_TRUE: + case Predicate::FCMP_TRUE: ResultReg = fastEmit_i(MVT::i32, MVT::i32, ISD::Constant, 1); break; } @@ -2514,13 +2514,13 @@ { AArch64CC::PL, AArch64CC::LE } }; unsigned *CondCodes = nullptr; - switch (Predicate) { + switch (Pred.getKind()) { default: break; - case CmpInst::FCMP_UEQ: + case Predicate::FCMP_UEQ: CondCodes = &CondCodeTable[0][0]; break; - case CmpInst::FCMP_ONE: + case Predicate::FCMP_ONE: CondCodes = &CondCodeTable[1][0]; break; } @@ -2543,7 +2543,7 @@ } // Now set a register based on the comparison. - AArch64CC::CondCode CC = getCompareCC(Predicate); + AArch64CC::CondCode CC = getCompareCC(Pred); assert((CC != AArch64CC::AL) && "Unexpected condition code."); AArch64CC::CondCode invertedCC = getInvertedCondCode(CC); BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(AArch64::CSINCWr), @@ -2663,15 +2663,15 @@ isValueAvailable(Cond)) { const auto *Cmp = cast(Cond); // Try to optimize or fold the cmp. - CmpInst::Predicate Predicate = optimizeCmpPredicate(Cmp); + Predicate Pred = optimizeCmpPredicate(Cmp); const Value *FoldSelect = nullptr; - switch (Predicate) { + switch (Pred.getKind()) { default: break; - case CmpInst::FCMP_FALSE: + case Predicate::FCMP_FALSE: FoldSelect = SI->getFalseValue(); break; - case CmpInst::FCMP_TRUE: + case Predicate::FCMP_TRUE: FoldSelect = SI->getTrueValue(); break; } @@ -2693,15 +2693,15 @@ return false; // FCMP_UEQ and FCMP_ONE cannot be checked with a single select instruction. - CC = getCompareCC(Predicate); - switch (Predicate) { + CC = getCompareCC(Pred); + switch (Pred.getKind()) { default: break; - case CmpInst::FCMP_UEQ: + case Predicate::FCMP_UEQ: ExtraCC = AArch64CC::EQ; CC = AArch64CC::VS; break; - case CmpInst::FCMP_ONE: + case Predicate::FCMP_ONE: ExtraCC = AArch64CC::MI; CC = AArch64CC::GT; break; Index: lib/Target/AMDGPU/SIISelLowering.cpp =================================================================== --- lib/Target/AMDGPU/SIISelLowering.cpp +++ lib/Target/AMDGPU/SIISelLowering.cpp @@ -2220,28 +2220,22 @@ } case Intrinsic::amdgcn_icmp: { const auto *CD = dyn_cast(Op.getOperand(3)); - int CondCode = CD->getSExtValue(); + Predicate IcInput(CD->getSExtValue()); - if (CondCode < ICmpInst::Predicate::FIRST_ICMP_PREDICATE || - CondCode >= ICmpInst::Predicate::BAD_ICMP_PREDICATE) + if (!IcInput.isInt()) return DAG.getUNDEF(VT); - ICmpInst::Predicate IcInput = - static_cast(CondCode); ISD::CondCode CCOpcode = getICmpCondCode(IcInput); return DAG.getNode(AMDGPUISD::SETCC, DL, VT, Op.getOperand(1), Op.getOperand(2), DAG.getCondCode(CCOpcode)); } case Intrinsic::amdgcn_fcmp: { const auto *CD = dyn_cast(Op.getOperand(3)); - int CondCode = CD->getSExtValue(); + Predicate IcInput(CD->getSExtValue()); - if (CondCode <= FCmpInst::Predicate::FCMP_FALSE || - CondCode >= FCmpInst::Predicate::FCMP_TRUE) + if (!IcInput.isFP()) return DAG.getUNDEF(VT); - FCmpInst::Predicate IcInput = - static_cast(CondCode); ISD::CondCode CCOpcode = getFCmpCondCode(IcInput); return DAG.getNode(AMDGPUISD::SETCC, DL, VT, Op.getOperand(1), Op.getOperand(2), DAG.getCondCode(CCOpcode)); Index: lib/Target/ARM/ARMFastISel.cpp =================================================================== --- lib/Target/ARM/ARMFastISel.cpp +++ lib/Target/ARM/ARMFastISel.cpp @@ -1192,50 +1192,50 @@ return true; } -static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) { - switch (Pred) { - // Needs two compares... - case CmpInst::FCMP_ONE: - case CmpInst::FCMP_UEQ: - default: - // AL is our "false" for now. The other two need more compares. - return ARMCC::AL; - case CmpInst::ICMP_EQ: - case CmpInst::FCMP_OEQ: - return ARMCC::EQ; - case CmpInst::ICMP_SGT: - case CmpInst::FCMP_OGT: - return ARMCC::GT; - case CmpInst::ICMP_SGE: - case CmpInst::FCMP_OGE: - return ARMCC::GE; - case CmpInst::ICMP_UGT: - case CmpInst::FCMP_UGT: - return ARMCC::HI; - case CmpInst::FCMP_OLT: - return ARMCC::MI; - case CmpInst::ICMP_ULE: - case CmpInst::FCMP_OLE: - return ARMCC::LS; - case CmpInst::FCMP_ORD: - return ARMCC::VC; - case CmpInst::FCMP_UNO: - return ARMCC::VS; - case CmpInst::FCMP_UGE: - return ARMCC::PL; - case CmpInst::ICMP_SLT: - case CmpInst::FCMP_ULT: - return ARMCC::LT; - case CmpInst::ICMP_SLE: - case CmpInst::FCMP_ULE: - return ARMCC::LE; - case CmpInst::FCMP_UNE: - case CmpInst::ICMP_NE: - return ARMCC::NE; - case CmpInst::ICMP_UGE: - return ARMCC::HS; - case CmpInst::ICMP_ULT: - return ARMCC::LO; +static ARMCC::CondCodes getComparePred(Predicate Pred) { + switch (Pred.getKind()) { + // Needs two compares... + case Predicate::FCMP_ONE: + case Predicate::FCMP_UEQ: + default: + // AL is our "false" for now. The other two need more compares. + return ARMCC::AL; + case Predicate::ICMP_EQ: + case Predicate::FCMP_OEQ: + return ARMCC::EQ; + case Predicate::ICMP_SGT: + case Predicate::FCMP_OGT: + return ARMCC::GT; + case Predicate::ICMP_SGE: + case Predicate::FCMP_OGE: + return ARMCC::GE; + case Predicate::ICMP_UGT: + case Predicate::FCMP_UGT: + return ARMCC::HI; + case Predicate::FCMP_OLT: + return ARMCC::MI; + case Predicate::ICMP_ULE: + case Predicate::FCMP_OLE: + return ARMCC::LS; + case Predicate::FCMP_ORD: + return ARMCC::VC; + case Predicate::FCMP_UNO: + return ARMCC::VS; + case Predicate::FCMP_UGE: + return ARMCC::PL; + case Predicate::ICMP_SLT: + case Predicate::FCMP_ULT: + return ARMCC::LT; + case Predicate::ICMP_SLE: + case Predicate::FCMP_ULE: + return ARMCC::LE; + case Predicate::FCMP_UNE: + case Predicate::ICMP_NE: + return ARMCC::NE; + case Predicate::ICMP_UGE: + return ARMCC::HS; + case Predicate::ICMP_ULT: + return ARMCC::LO; } } @@ -1253,13 +1253,13 @@ // Get the compare predicate. // Try to take advantage of fallthrough opportunities. - CmpInst::Predicate Predicate = CI->getPredicate(); + Predicate Pred = CI->getPredicate(); if (FuncInfo.MBB->isLayoutSuccessor(TBB)) { std::swap(TBB, FBB); - Predicate = CmpInst::getInversePredicate(Predicate); + Pred = Pred.getInverse(); } - ARMCC::CondCodes ARMPred = getComparePred(Predicate); + ARMCC::CondCodes ARMPred = getComparePred(Pred); // We may not handle every CC for now. if (ARMPred == ARMCC::AL) return false; Index: lib/Target/Mips/MipsFastISel.cpp =================================================================== --- lib/Target/Mips/MipsFastISel.cpp +++ lib/Target/Mips/MipsFastISel.cpp @@ -607,69 +607,69 @@ unsigned RightReg = getRegEnsuringSimpleIntegerWidening(Right, IsUnsigned); if (RightReg == 0) return false; - CmpInst::Predicate P = CI->getPredicate(); + Predicate P = CI->getPredicate(); - switch (P) { + switch (P.getKind()) { default: return false; - case CmpInst::ICMP_EQ: { + case Predicate::ICMP_EQ: { unsigned TempReg = createResultReg(&Mips::GPR32RegClass); emitInst(Mips::XOR, TempReg).addReg(LeftReg).addReg(RightReg); emitInst(Mips::SLTiu, ResultReg).addReg(TempReg).addImm(1); break; } - case CmpInst::ICMP_NE: { + case Predicate::ICMP_NE: { unsigned TempReg = createResultReg(&Mips::GPR32RegClass); emitInst(Mips::XOR, TempReg).addReg(LeftReg).addReg(RightReg); emitInst(Mips::SLTu, ResultReg).addReg(Mips::ZERO).addReg(TempReg); break; } - case CmpInst::ICMP_UGT: { + case Predicate::ICMP_UGT: { emitInst(Mips::SLTu, ResultReg).addReg(RightReg).addReg(LeftReg); break; } - case CmpInst::ICMP_ULT: { + case Predicate::ICMP_ULT: { emitInst(Mips::SLTu, ResultReg).addReg(LeftReg).addReg(RightReg); break; } - case CmpInst::ICMP_UGE: { + case Predicate::ICMP_UGE: { unsigned TempReg = createResultReg(&Mips::GPR32RegClass); emitInst(Mips::SLTu, TempReg).addReg(LeftReg).addReg(RightReg); emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1); break; } - case CmpInst::ICMP_ULE: { + case Predicate::ICMP_ULE: { unsigned TempReg = createResultReg(&Mips::GPR32RegClass); emitInst(Mips::SLTu, TempReg).addReg(RightReg).addReg(LeftReg); emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1); break; } - case CmpInst::ICMP_SGT: { + case Predicate::ICMP_SGT: { emitInst(Mips::SLT, ResultReg).addReg(RightReg).addReg(LeftReg); break; } - case CmpInst::ICMP_SLT: { + case Predicate::ICMP_SLT: { emitInst(Mips::SLT, ResultReg).addReg(LeftReg).addReg(RightReg); break; } - case CmpInst::ICMP_SGE: { + case Predicate::ICMP_SGE: { unsigned TempReg = createResultReg(&Mips::GPR32RegClass); emitInst(Mips::SLT, TempReg).addReg(LeftReg).addReg(RightReg); emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1); break; } - case CmpInst::ICMP_SLE: { + case Predicate::ICMP_SLE: { unsigned TempReg = createResultReg(&Mips::GPR32RegClass); emitInst(Mips::SLT, TempReg).addReg(RightReg).addReg(LeftReg); emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1); break; } - case CmpInst::FCMP_OEQ: - case CmpInst::FCMP_UNE: - case CmpInst::FCMP_OLT: - case CmpInst::FCMP_OLE: - case CmpInst::FCMP_OGT: - case CmpInst::FCMP_OGE: { + case Predicate::FCMP_OEQ: + case Predicate::FCMP_UNE: + case Predicate::FCMP_OLT: + case Predicate::FCMP_OLE: + case Predicate::FCMP_OGT: + case Predicate::FCMP_OGE: { if (UnsupportedFPMode) return false; bool IsFloat = Left->getType()->isFloatTy(); @@ -677,28 +677,28 @@ if (!IsFloat && !IsDouble) return false; unsigned Opc, CondMovOpc; - switch (P) { - case CmpInst::FCMP_OEQ: + switch (P.getKind()) { + case Predicate::FCMP_OEQ: Opc = IsFloat ? Mips::C_EQ_S : Mips::C_EQ_D32; CondMovOpc = Mips::MOVT_I; break; - case CmpInst::FCMP_UNE: + case Predicate::FCMP_UNE: Opc = IsFloat ? Mips::C_EQ_S : Mips::C_EQ_D32; CondMovOpc = Mips::MOVF_I; break; - case CmpInst::FCMP_OLT: + case Predicate::FCMP_OLT: Opc = IsFloat ? Mips::C_OLT_S : Mips::C_OLT_D32; CondMovOpc = Mips::MOVT_I; break; - case CmpInst::FCMP_OLE: + case Predicate::FCMP_OLE: Opc = IsFloat ? Mips::C_OLE_S : Mips::C_OLE_D32; CondMovOpc = Mips::MOVT_I; break; - case CmpInst::FCMP_OGT: + case Predicate::FCMP_OGT: Opc = IsFloat ? Mips::C_ULE_S : Mips::C_ULE_D32; CondMovOpc = Mips::MOVF_I; break; - case CmpInst::FCMP_OGE: + case Predicate::FCMP_OGE: Opc = IsFloat ? Mips::C_ULT_S : Mips::C_ULT_D32; CondMovOpc = Mips::MOVF_I; break; Index: lib/Target/NVPTX/NVPTXGenericToNVVM.cpp =================================================================== --- lib/Target/NVPTX/NVPTXGenericToNVVM.cpp +++ lib/Target/NVPTX/NVPTXGenericToNVVM.cpp @@ -301,8 +301,8 @@ switch (Opcode) { case Instruction::ICmp: // CompareConstantExpr (icmp) - return Builder.CreateICmp(CmpInst::Predicate(C->getPredicate()), - NewOperands[0], NewOperands[1]); + return Builder.CreateICmp(Predicate(C->getPredicate()), NewOperands[0], + NewOperands[1]); case Instruction::FCmp: // CompareConstantExpr (fcmp) llvm_unreachable("Address space conversion should have no effect " Index: lib/Target/NVPTX/NVPTXLowerAggrCopies.cpp =================================================================== --- lib/Target/NVPTX/NVPTXLowerAggrCopies.cpp +++ lib/Target/NVPTX/NVPTXLowerAggrCopies.cpp @@ -141,7 +141,7 @@ // SplitBlockAndInsertIfThenElse conveniently creates the basic if-then-else // structure. Its block terminators (unconditional branches) are replaced by // the appropriate conditional branches when the loop is built. - ICmpInst *PtrCompare = new ICmpInst(ConvertedInst, ICmpInst::ICMP_ULT, + ICmpInst *PtrCompare = new ICmpInst(ConvertedInst, Predicate::ICMP_ULT, SrcAddr, DstAddr, "compare_src_dst"); TerminatorInst *ThenTerm, *ElseTerm; SplitBlockAndInsertIfThenElse(PtrCompare, ConvertedInst, &ThenTerm, @@ -162,7 +162,7 @@ // Initial comparison of n == 0 that lets us skip the loops altogether. Shared // between both backwards and forward copy clauses. ICmpInst *CompareN = - new ICmpInst(OrigBB->getTerminator(), ICmpInst::ICMP_EQ, CopyLen, + new ICmpInst(OrigBB->getTerminator(), Predicate::ICMP_EQ, CopyLen, ConstantInt::get(TypeOfCopyLen, 0), "compare_n_to_0"); // Copying backwards. Index: lib/Target/PowerPC/PPCFastISel.cpp =================================================================== --- lib/Target/PowerPC/PPCFastISel.cpp +++ lib/Target/PowerPC/PPCFastISel.cpp @@ -210,69 +210,69 @@ return RetCC_PPC; } -static Optional getComparePred(CmpInst::Predicate Pred) { - switch (Pred) { - // These are not representable with any single compare. - case CmpInst::FCMP_FALSE: - case CmpInst::FCMP_TRUE: - // Major concern about the following 6 cases is NaN result. The comparison - // result consists of 4 bits, indicating lt, eq, gt and un (unordered), - // only one of which will be set. The result is generated by fcmpu - // instruction. However, bc instruction only inspects one of the first 3 - // bits, so when un is set, bc instruction may jump to to an undesired - // place. - // - // More specifically, if we expect an unordered comparison and un is set, we - // expect to always go to true branch; in such case UEQ, UGT and ULT still - // give false, which are undesired; but UNE, UGE, ULE happen to give true, - // since they are tested by inspecting !eq, !lt, !gt, respectively. - // - // Similarly, for ordered comparison, when un is set, we always expect the - // result to be false. In such case OGT, OLT and OEQ is good, since they are - // actually testing GT, LT, and EQ respectively, which are false. OGE, OLE - // and ONE are tested through !lt, !gt and !eq, and these are true. - case CmpInst::FCMP_UEQ: - case CmpInst::FCMP_UGT: - case CmpInst::FCMP_ULT: - case CmpInst::FCMP_OGE: - case CmpInst::FCMP_OLE: - case CmpInst::FCMP_ONE: - default: - return Optional(); - - case CmpInst::FCMP_OEQ: - case CmpInst::ICMP_EQ: - return PPC::PRED_EQ; - - case CmpInst::FCMP_OGT: - case CmpInst::ICMP_UGT: - case CmpInst::ICMP_SGT: - return PPC::PRED_GT; - - case CmpInst::FCMP_UGE: - case CmpInst::ICMP_UGE: - case CmpInst::ICMP_SGE: - return PPC::PRED_GE; - - case CmpInst::FCMP_OLT: - case CmpInst::ICMP_ULT: - case CmpInst::ICMP_SLT: - return PPC::PRED_LT; - - case CmpInst::FCMP_ULE: - case CmpInst::ICMP_ULE: - case CmpInst::ICMP_SLE: - return PPC::PRED_LE; - - case CmpInst::FCMP_UNE: - case CmpInst::ICMP_NE: - return PPC::PRED_NE; - - case CmpInst::FCMP_ORD: - return PPC::PRED_NU; - - case CmpInst::FCMP_UNO: - return PPC::PRED_UN; +static Optional getComparePred(Predicate Pred) { + switch (Pred.getKind()) { + // These are not representable with any single compare. + case Predicate::FCMP_FALSE: + case Predicate::FCMP_TRUE: + // Major concern about the following 6 cases is NaN result. The comparison + // result consists of 4 bits, indicating lt, eq, gt and un (unordered), + // only one of which will be set. The result is generated by fcmpu + // instruction. However, bc instruction only inspects one of the first 3 + // bits, so when un is set, bc instruction may jump to to an undesired + // place. + // + // More specifically, if we expect an unordered comparison and un is set, we + // expect to always go to true branch; in such case UEQ, UGT and ULT still + // give false, which are undesired; but UNE, UGE, ULE happen to give true, + // since they are tested by inspecting !eq, !lt, !gt, respectively. + // + // Similarly, for ordered comparison, when un is set, we always expect the + // result to be false. In such case OGT, OLT and OEQ is good, since they are + // actually testing GT, LT, and EQ respectively, which are false. OGE, OLE + // and ONE are tested through !lt, !gt and !eq, and these are true. + case Predicate::FCMP_UEQ: + case Predicate::FCMP_UGT: + case Predicate::FCMP_ULT: + case Predicate::FCMP_OGE: + case Predicate::FCMP_OLE: + case Predicate::FCMP_ONE: + default: + return Optional(); + + case Predicate::FCMP_OEQ: + case Predicate::ICMP_EQ: + return PPC::PRED_EQ; + + case Predicate::FCMP_OGT: + case Predicate::ICMP_UGT: + case Predicate::ICMP_SGT: + return PPC::PRED_GT; + + case Predicate::FCMP_UGE: + case Predicate::ICMP_UGE: + case Predicate::ICMP_SGE: + return PPC::PRED_GE; + + case Predicate::FCMP_OLT: + case Predicate::ICMP_ULT: + case Predicate::ICMP_SLT: + return PPC::PRED_LT; + + case Predicate::FCMP_ULE: + case Predicate::ICMP_ULE: + case Predicate::ICMP_SLE: + return PPC::PRED_LE; + + case Predicate::FCMP_UNE: + case Predicate::ICMP_NE: + return PPC::PRED_NE; + + case Predicate::FCMP_ORD: + return PPC::PRED_NU; + + case Predicate::FCMP_UNO: + return PPC::PRED_UN; } } Index: lib/Target/SystemZ/SystemZTDC.cpp =================================================================== --- lib/Target/SystemZ/SystemZTDC.cpp +++ lib/Target/SystemZ/SystemZTDC.cpp @@ -141,14 +141,14 @@ WhichConst = Const->isNegative() ? 2 : 1; } else if (Const->isExactlyValue(Smallest)) { // For Smallest, we cannot do EQ separately from GT. - if ((Pred & CmpInst::FCMP_OGE) != CmpInst::FCMP_OGE && - (Pred & CmpInst::FCMP_OGE) != 0) + if ((Pred.getKind() & Predicate::FCMP_OGE) != Predicate::FCMP_OGE && + (Pred.getKind() & Predicate::FCMP_OGE) != 0) return; WhichConst = 3; } else if (Const->isExactlyValue(NegSmallest)) { // Likewise for NegSmallest, we cannot do EQ separately from LT. - if ((Pred & CmpInst::FCMP_OLE) != CmpInst::FCMP_OLE && - (Pred & CmpInst::FCMP_OLE) != 0) + if ((Pred.getKind() & Predicate::FCMP_OLE) != Predicate::FCMP_OLE && + (Pred.getKind() & Predicate::FCMP_OLE) != 0) return; WhichConst = 4; } else { @@ -202,13 +202,13 @@ }; // Construct the mask as a combination of the partial masks. int Mask = 0; - if (Pred & CmpInst::FCMP_OEQ) + if (Pred.getKind() & Predicate::FCMP_OEQ) Mask |= Masks[WhichConst][0]; - if (Pred & CmpInst::FCMP_OGT) + if (Pred.getKind() & Predicate::FCMP_OGT) Mask |= Masks[WhichConst][1]; - if (Pred & CmpInst::FCMP_OLT) + if (Pred.getKind() & Predicate::FCMP_OLT) Mask |= Masks[WhichConst][2]; - if (Pred & CmpInst::FCMP_UNO) + if (Pred.getKind() & Predicate::FCMP_UNO) Mask |= Masks[WhichConst][3]; // A lone fcmp is unworthy of tdc conversion on its own, but may become // worthy if combined with fabs. @@ -244,10 +244,10 @@ return; Value *V = Cast->getOperand(0); int Mask; - if (Pred == CmpInst::ICMP_SLT && Const->isZero()) { + if (Pred == Predicate::ICMP_SLT && Const->isZero()) { // icmp slt (bitcast X), 0 - set if sign bit true Mask = SystemZ::TDCMASK_MINUS; - } else if (Pred == CmpInst::ICMP_SGT && Const->isMinusOne()) { + } else if (Pred == Predicate::ICMP_SGT && Const->isMinusOne()) { // icmp sgt (bitcast X), -1 - set if sign bit false Mask = SystemZ::TDCMASK_PLUS; } else { @@ -270,9 +270,9 @@ return; int Mask = MaskC->getZExtValue(); Mask &= SystemZ::TDCMASK_ALL; - if (Pred == CmpInst::ICMP_NE) { + if (Pred == Predicate::ICMP_NE) { // icmp ne (call llvm.s390.tdc(...)), 0 -> simple TDC - } else if (Pred == CmpInst::ICMP_EQ) { + } else if (Pred == Predicate::ICMP_EQ) { // icmp eq (call llvm.s390.tdc(...)), 0 -> TDC with inverted mask Mask ^= SystemZ::TDCMASK_ALL; } else { @@ -361,7 +361,7 @@ IRBuilder<> IRB(I); Value *MaskVal = ConstantInt::get(Type::getInt64Ty(Ctx), Mask); Instruction *TDC = IRB.CreateCall(TDCFunc, {V, MaskVal}); - Value *ICmp = IRB.CreateICmp(CmpInst::ICMP_NE, TDC, Zero32); + Value *ICmp = IRB.CreateICmp(Predicate::ICMP_NE, TDC, Zero32); I->replaceAllUsesWith(ICmp); } // If unused, or used and converted, remove it. Index: lib/Target/X86/X86FastISel.cpp =================================================================== --- lib/Target/X86/X86FastISel.cpp +++ lib/Target/X86/X86FastISel.cpp @@ -174,46 +174,86 @@ } // end anonymous namespace. -static std::pair -getX86ConditionCode(CmpInst::Predicate Predicate) { +static std::pair getX86ConditionCode(Predicate Predicate) { X86::CondCode CC = X86::COND_INVALID; bool NeedSwap = false; - switch (Predicate) { + switch (Predicate.getKind()) { default: break; // Floating-point Predicates - case CmpInst::FCMP_UEQ: CC = X86::COND_E; break; - case CmpInst::FCMP_OLT: NeedSwap = true; // fall-through - case CmpInst::FCMP_OGT: CC = X86::COND_A; break; - case CmpInst::FCMP_OLE: NeedSwap = true; // fall-through - case CmpInst::FCMP_OGE: CC = X86::COND_AE; break; - case CmpInst::FCMP_UGT: NeedSwap = true; // fall-through - case CmpInst::FCMP_ULT: CC = X86::COND_B; break; - case CmpInst::FCMP_UGE: NeedSwap = true; // fall-through - case CmpInst::FCMP_ULE: CC = X86::COND_BE; break; - case CmpInst::FCMP_ONE: CC = X86::COND_NE; break; - case CmpInst::FCMP_UNO: CC = X86::COND_P; break; - case CmpInst::FCMP_ORD: CC = X86::COND_NP; break; - case CmpInst::FCMP_OEQ: // fall-through - case CmpInst::FCMP_UNE: CC = X86::COND_INVALID; break; + case Predicate::FCMP_UEQ: + CC = X86::COND_E; + break; + case Predicate::FCMP_OLT: + NeedSwap = true; // fall-through + case Predicate::FCMP_OGT: + CC = X86::COND_A; + break; + case Predicate::FCMP_OLE: + NeedSwap = true; // fall-through + case Predicate::FCMP_OGE: + CC = X86::COND_AE; + break; + case Predicate::FCMP_UGT: + NeedSwap = true; // fall-through + case Predicate::FCMP_ULT: + CC = X86::COND_B; + break; + case Predicate::FCMP_UGE: + NeedSwap = true; // fall-through + case Predicate::FCMP_ULE: + CC = X86::COND_BE; + break; + case Predicate::FCMP_ONE: + CC = X86::COND_NE; + break; + case Predicate::FCMP_UNO: + CC = X86::COND_P; + break; + case Predicate::FCMP_ORD: + CC = X86::COND_NP; + break; + case Predicate::FCMP_OEQ: // fall-through + case Predicate::FCMP_UNE: + CC = X86::COND_INVALID; + break; // Integer Predicates - case CmpInst::ICMP_EQ: CC = X86::COND_E; break; - case CmpInst::ICMP_NE: CC = X86::COND_NE; break; - case CmpInst::ICMP_UGT: CC = X86::COND_A; break; - case CmpInst::ICMP_UGE: CC = X86::COND_AE; break; - case CmpInst::ICMP_ULT: CC = X86::COND_B; break; - case CmpInst::ICMP_ULE: CC = X86::COND_BE; break; - case CmpInst::ICMP_SGT: CC = X86::COND_G; break; - case CmpInst::ICMP_SGE: CC = X86::COND_GE; break; - case CmpInst::ICMP_SLT: CC = X86::COND_L; break; - case CmpInst::ICMP_SLE: CC = X86::COND_LE; break; + case Predicate::ICMP_EQ: + CC = X86::COND_E; + break; + case Predicate::ICMP_NE: + CC = X86::COND_NE; + break; + case Predicate::ICMP_UGT: + CC = X86::COND_A; + break; + case Predicate::ICMP_UGE: + CC = X86::COND_AE; + break; + case Predicate::ICMP_ULT: + CC = X86::COND_B; + break; + case Predicate::ICMP_ULE: + CC = X86::COND_BE; + break; + case Predicate::ICMP_SGT: + CC = X86::COND_G; + break; + case Predicate::ICMP_SGE: + CC = X86::COND_GE; + break; + case Predicate::ICMP_SLT: + CC = X86::COND_L; + break; + case Predicate::ICMP_SLE: + CC = X86::COND_LE; + break; } return std::make_pair(CC, NeedSwap); } -static std::pair -getX86SSEConditionCode(CmpInst::Predicate Predicate) { +static std::pair getX86SSEConditionCode(Predicate Predicate) { unsigned CC; bool NeedSwap = false; @@ -226,22 +266,44 @@ // 5 - NLT // 6 - NLE // 7 - ORD - switch (Predicate) { + switch (Predicate.getKind()) { default: llvm_unreachable("Unexpected predicate"); - case CmpInst::FCMP_OEQ: CC = 0; break; - case CmpInst::FCMP_OGT: NeedSwap = true; // fall-through - case CmpInst::FCMP_OLT: CC = 1; break; - case CmpInst::FCMP_OGE: NeedSwap = true; // fall-through - case CmpInst::FCMP_OLE: CC = 2; break; - case CmpInst::FCMP_UNO: CC = 3; break; - case CmpInst::FCMP_UNE: CC = 4; break; - case CmpInst::FCMP_ULE: NeedSwap = true; // fall-through - case CmpInst::FCMP_UGE: CC = 5; break; - case CmpInst::FCMP_ULT: NeedSwap = true; // fall-through - case CmpInst::FCMP_UGT: CC = 6; break; - case CmpInst::FCMP_ORD: CC = 7; break; - case CmpInst::FCMP_UEQ: - case CmpInst::FCMP_ONE: CC = 8; break; + case Predicate::FCMP_OEQ: + CC = 0; + break; + case Predicate::FCMP_OGT: + NeedSwap = true; // fall-through + case Predicate::FCMP_OLT: + CC = 1; + break; + case Predicate::FCMP_OGE: + NeedSwap = true; // fall-through + case Predicate::FCMP_OLE: + CC = 2; + break; + case Predicate::FCMP_UNO: + CC = 3; + break; + case Predicate::FCMP_UNE: + CC = 4; + break; + case Predicate::FCMP_ULE: + NeedSwap = true; // fall-through + case Predicate::FCMP_UGE: + CC = 5; + break; + case Predicate::FCMP_ULT: + NeedSwap = true; // fall-through + case Predicate::FCMP_UGT: + CC = 6; + break; + case Predicate::FCMP_ORD: + CC = 7; + break; + case Predicate::FCMP_UEQ: + case Predicate::FCMP_ONE: + CC = 8; + break; } return std::make_pair(CC, NeedSwap); @@ -1414,11 +1476,11 @@ return false; // Try to optimize or fold the cmp. - CmpInst::Predicate Predicate = optimizeCmpPredicate(CI); + Predicate Predicate = optimizeCmpPredicate(CI); unsigned ResultReg = 0; - switch (Predicate) { + switch (Predicate.getKind()) { default: break; - case CmpInst::FCMP_FALSE: { + case Predicate::FCMP_FALSE: { ResultReg = createResultReg(&X86::GR32RegClass); BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(X86::MOV32r0), ResultReg); @@ -1428,7 +1490,7 @@ return false; break; } - case CmpInst::FCMP_TRUE: { + case Predicate::FCMP_TRUE: { ResultReg = createResultReg(&X86::GR8RegClass); BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(X86::MOV8ri), ResultReg).addImm(1); @@ -1447,7 +1509,7 @@ // The optimizer might have replaced fcmp oeq %x, %x with fcmp ord %x, 0.0. // We don't have to materialize a zero constant for this case and can just use // %x again on the RHS. - if (Predicate == CmpInst::FCMP_ORD || Predicate == CmpInst::FCMP_UNO) { + if (Predicate == Predicate::FCMP_ORD || Predicate == Predicate::FCMP_UNO) { const auto *RHSC = dyn_cast(RHS); if (RHSC && RHSC->isNullValue()) RHS = LHS; @@ -1459,10 +1521,14 @@ { X86::SETNEr, X86::SETPr, X86::OR8rr } }; unsigned *SETFOpc = nullptr; - switch (Predicate) { + switch (Predicate.getKind()) { default: break; - case CmpInst::FCMP_OEQ: SETFOpc = &SETFOpcTable[0][0]; break; - case CmpInst::FCMP_UNE: SETFOpc = &SETFOpcTable[1][0]; break; + case Predicate::FCMP_OEQ: + SETFOpc = &SETFOpcTable[0][0]; + break; + case Predicate::FCMP_UNE: + SETFOpc = &SETFOpcTable[1][0]; + break; } ResultReg = createResultReg(&X86::GR8RegClass); @@ -1566,11 +1632,15 @@ EVT VT = TLI.getValueType(DL, CI->getOperand(0)->getType()); // Try to optimize or fold the cmp. - CmpInst::Predicate Predicate = optimizeCmpPredicate(CI); - switch (Predicate) { + Predicate Predicate = optimizeCmpPredicate(CI); + switch (Predicate.getKind()) { default: break; - case CmpInst::FCMP_FALSE: fastEmitBranch(FalseMBB, DbgLoc); return true; - case CmpInst::FCMP_TRUE: fastEmitBranch(TrueMBB, DbgLoc); return true; + case Predicate::FCMP_FALSE: + fastEmitBranch(FalseMBB, DbgLoc); + return true; + case Predicate::FCMP_TRUE: + fastEmitBranch(TrueMBB, DbgLoc); + return true; } const Value *CmpLHS = CI->getOperand(0); @@ -1580,7 +1650,8 @@ // 0.0. // We don't have to materialize a zero constant for this case and can just // use %x again on the RHS. - if (Predicate == CmpInst::FCMP_ORD || Predicate == CmpInst::FCMP_UNO) { + if (Predicate == Predicate::FCMP_ORD || + Predicate == Predicate::FCMP_UNO) { const auto *CmpRHSC = dyn_cast(CmpRHS); if (CmpRHSC && CmpRHSC->isNullValue()) CmpRHS = CmpLHS; @@ -1589,7 +1660,7 @@ // Try to take advantage of fallthrough opportunities. if (FuncInfo.MBB->isLayoutSuccessor(TrueMBB)) { std::swap(TrueMBB, FalseMBB); - Predicate = CmpInst::getInversePredicate(Predicate); + Predicate = Predicate.getInverse(); } // FCMP_OEQ and FCMP_UNE cannot be expressed with a single flag/condition @@ -1598,13 +1669,13 @@ // which will be the first branch. Later one we will emit the second // branch. bool NeedExtraBranch = false; - switch (Predicate) { + switch (Predicate.getKind()) { default: break; - case CmpInst::FCMP_OEQ: + case Predicate::FCMP_OEQ: std::swap(TrueMBB, FalseMBB); // fall-through - case CmpInst::FCMP_UNE: + case Predicate::FCMP_UNE: NeedExtraBranch = true; - Predicate = CmpInst::FCMP_ONE; + Predicate = Predicate::FCMP_ONE; break; } @@ -1950,7 +2021,7 @@ // initialized registers). const auto *CI = dyn_cast(Cond); if (CI && (CI->getParent() == I->getParent())) { - CmpInst::Predicate Predicate = optimizeCmpPredicate(CI); + Predicate Predicate = optimizeCmpPredicate(CI); // FCMP_OEQ and FCMP_UNE cannot be checked with a single instruction. static unsigned SETFOpcTable[2][3] = { @@ -1958,15 +2029,15 @@ { X86::SETPr, X86::SETNEr, X86::OR8rr } }; unsigned *SETFOpc = nullptr; - switch (Predicate) { + switch (Predicate.getKind()) { default: break; - case CmpInst::FCMP_OEQ: + case Predicate::FCMP_OEQ: SETFOpc = &SETFOpcTable[0][0]; - Predicate = CmpInst::ICMP_NE; + Predicate = Predicate::ICMP_NE; break; - case CmpInst::FCMP_UNE: + case Predicate::FCMP_UNE: SETFOpc = &SETFOpcTable[1][0]; - Predicate = CmpInst::ICMP_NE; + Predicate = Predicate::ICMP_NE; break; } @@ -2066,12 +2137,12 @@ const Value *CmpLHS = CI->getOperand(0); const Value *CmpRHS = CI->getOperand(1); - CmpInst::Predicate Predicate = optimizeCmpPredicate(CI); + Predicate Predicate = optimizeCmpPredicate(CI); // The optimizer might have replaced fcmp oeq %x, %x with fcmp ord %x, 0.0. // We don't have to materialize a zero constant for this case and can just use // %x again on the RHS. - if (Predicate == CmpInst::FCMP_ORD || Predicate == CmpInst::FCMP_UNO) { + if (Predicate == Predicate::FCMP_ORD || Predicate == Predicate::FCMP_UNO) { const auto *CmpRHSC = dyn_cast(CmpRHS); if (CmpRHSC && CmpRHSC->isNullValue()) CmpRHS = CmpLHS; @@ -2226,12 +2297,16 @@ // Check if we can fold the select. if (const auto *CI = dyn_cast(I->getOperand(0))) { - CmpInst::Predicate Predicate = optimizeCmpPredicate(CI); + Predicate Predicate = optimizeCmpPredicate(CI); const Value *Opnd = nullptr; - switch (Predicate) { + switch (Predicate.getKind()) { default: break; - case CmpInst::FCMP_FALSE: Opnd = I->getOperand(2); break; - case CmpInst::FCMP_TRUE: Opnd = I->getOperand(1); break; + case Predicate::FCMP_FALSE: + Opnd = I->getOperand(2); + break; + case Predicate::FCMP_TRUE: + Opnd = I->getOperand(1); + break; } // No need for a select anymore - this is an unconditional move. if (Opnd) { Index: lib/Transforms/IPO/GlobalOpt.cpp =================================================================== --- lib/Transforms/IPO/GlobalOpt.cpp +++ lib/Transforms/IPO/GlobalOpt.cpp @@ -868,22 +868,22 @@ LI->getOrdering(), LI->getSynchScope(), LI->isUnordered() ? (Instruction*)ICI : LI); InitBoolUsed = true; - switch (ICI->getPredicate()) { + switch (ICI->getPredicate().getKind()) { default: llvm_unreachable("Unknown ICmp Predicate!"); - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_SLT: // X < null -> always false + case Predicate::ICMP_ULT: + case Predicate::ICMP_SLT: // X < null -> always false LV = ConstantInt::getFalse(GV->getContext()); break; - case ICmpInst::ICMP_ULE: - case ICmpInst::ICMP_SLE: - case ICmpInst::ICMP_EQ: + case Predicate::ICMP_ULE: + case Predicate::ICMP_SLE: + case Predicate::ICMP_EQ: LV = BinaryOperator::CreateNot(LV, "notinit", ICI); break; - case ICmpInst::ICMP_NE: - case ICmpInst::ICMP_UGE: - case ICmpInst::ICMP_SGE: - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_NE: + case Predicate::ICMP_UGE: + case Predicate::ICMP_SGE: + case Predicate::ICMP_UGT: + case Predicate::ICMP_SGT: break; // no change. } ICI->replaceAllUsesWith(LV); @@ -1287,12 +1287,12 @@ // } // The malloc can also fail if its argument is too large. Constant *ConstantZero = ConstantInt::get(CI->getArgOperand(0)->getType(), 0); - Value *RunningOr = new ICmpInst(CI, ICmpInst::ICMP_SLT, CI->getArgOperand(0), + Value *RunningOr = new ICmpInst(CI, Predicate::ICMP_SLT, CI->getArgOperand(0), ConstantZero, "isneg"); for (unsigned i = 0, e = FieldMallocs.size(); i != e; ++i) { - Value *Cond = new ICmpInst(CI, ICmpInst::ICMP_EQ, FieldMallocs[i], - Constant::getNullValue(FieldMallocs[i]->getType()), - "isnull"); + Value *Cond = new ICmpInst( + CI, Predicate::ICMP_EQ, FieldMallocs[i], + Constant::getNullValue(FieldMallocs[i]->getType()), "isnull"); RunningOr = BinaryOperator::CreateOr(RunningOr, Cond, "tmp", CI); } @@ -1316,7 +1316,7 @@ // pointer, because some may be null while others are not. for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) { Value *GVVal = new LoadInst(FieldGlobals[i], "tmp", NullPtrBlock); - Value *Cmp = new ICmpInst(*NullPtrBlock, ICmpInst::ICMP_NE, GVVal, + Value *Cmp = new ICmpInst(*NullPtrBlock, Predicate::ICMP_NE, GVVal, Constant::getNullValue(GVVal->getType())); BasicBlock *FreeBlock = BasicBlock::Create(Cmp->getContext(), "free_it", OrigBB->getParent()); Index: lib/Transforms/IPO/MergeFunctions.cpp =================================================================== --- lib/Transforms/IPO/MergeFunctions.cpp +++ lib/Transforms/IPO/MergeFunctions.cpp @@ -965,7 +965,8 @@ return cmpNumbers(SI->getSynchScope(), cast(R)->getSynchScope()); } if (const CmpInst *CI = dyn_cast(L)) - return cmpNumbers(CI->getPredicate(), cast(R)->getPredicate()); + return cmpNumbers(CI->getPredicate().getKind(), + cast(R)->getPredicate().getKind()); if (const CallInst *CI = dyn_cast(L)) { if (int Res = cmpNumbers(CI->getCallingConv(), cast(R)->getCallingConv())) Index: lib/Transforms/IPO/WholeProgramDevirt.cpp =================================================================== --- lib/Transforms/IPO/WholeProgramDevirt.cpp +++ lib/Transforms/IPO/WholeProgramDevirt.cpp @@ -480,7 +480,7 @@ IRBuilder<> B(Call.CS.getInstruction()); Value *OneAddr = B.CreateBitCast(UniqueMember->Bits->GV, Int8PtrTy); OneAddr = B.CreateConstGEP1_64(OneAddr, UniqueMember->Offset); - Value *Cmp = B.CreateICmp(IsOne ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_NE, + Value *Cmp = B.CreateICmp(IsOne ? Predicate::ICMP_EQ : Predicate::ICMP_NE, Call.VTable, OneAddr); Call.replaceAndErase(Cmp); } Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -40,28 +40,27 @@ /// Similar to getICmpCode but for FCmpInst. This encodes a fcmp predicate into /// a four bit mask. -static unsigned getFCmpCode(FCmpInst::Predicate CC) { - assert(FCmpInst::FCMP_FALSE <= CC && CC <= FCmpInst::FCMP_TRUE && - "Unexpected FCmp predicate!"); - // Take advantage of the bit pattern of FCmpInst::Predicate here. +static unsigned getFCmpCode(Predicate CC) { + assert(CC.isFP() && "Unexpected FCmp predicate!"); + // Take advantage of the bit pattern of Predicate here. // U L G E - static_assert(FCmpInst::FCMP_FALSE == 0, ""); // 0 0 0 0 - static_assert(FCmpInst::FCMP_OEQ == 1, ""); // 0 0 0 1 - static_assert(FCmpInst::FCMP_OGT == 2, ""); // 0 0 1 0 - static_assert(FCmpInst::FCMP_OGE == 3, ""); // 0 0 1 1 - static_assert(FCmpInst::FCMP_OLT == 4, ""); // 0 1 0 0 - static_assert(FCmpInst::FCMP_OLE == 5, ""); // 0 1 0 1 - static_assert(FCmpInst::FCMP_ONE == 6, ""); // 0 1 1 0 - static_assert(FCmpInst::FCMP_ORD == 7, ""); // 0 1 1 1 - static_assert(FCmpInst::FCMP_UNO == 8, ""); // 1 0 0 0 - static_assert(FCmpInst::FCMP_UEQ == 9, ""); // 1 0 0 1 - static_assert(FCmpInst::FCMP_UGT == 10, ""); // 1 0 1 0 - static_assert(FCmpInst::FCMP_UGE == 11, ""); // 1 0 1 1 - static_assert(FCmpInst::FCMP_ULT == 12, ""); // 1 1 0 0 - static_assert(FCmpInst::FCMP_ULE == 13, ""); // 1 1 0 1 - static_assert(FCmpInst::FCMP_UNE == 14, ""); // 1 1 1 0 - static_assert(FCmpInst::FCMP_TRUE == 15, ""); // 1 1 1 1 - return CC; + static_assert(Predicate::FCMP_FALSE == 0, ""); // 0 0 0 0 + static_assert(Predicate::FCMP_OEQ == 1, ""); // 0 0 0 1 + static_assert(Predicate::FCMP_OGT == 2, ""); // 0 0 1 0 + static_assert(Predicate::FCMP_OGE == 3, ""); // 0 0 1 1 + static_assert(Predicate::FCMP_OLT == 4, ""); // 0 1 0 0 + static_assert(Predicate::FCMP_OLE == 5, ""); // 0 1 0 1 + static_assert(Predicate::FCMP_ONE == 6, ""); // 0 1 1 0 + static_assert(Predicate::FCMP_ORD == 7, ""); // 0 1 1 1 + static_assert(Predicate::FCMP_UNO == 8, ""); // 1 0 0 0 + static_assert(Predicate::FCMP_UEQ == 9, ""); // 1 0 0 1 + static_assert(Predicate::FCMP_UGT == 10, ""); // 1 0 1 0 + static_assert(Predicate::FCMP_UGE == 11, ""); // 1 0 1 1 + static_assert(Predicate::FCMP_ULT == 12, ""); // 1 1 0 0 + static_assert(Predicate::FCMP_ULE == 13, ""); // 1 1 0 1 + static_assert(Predicate::FCMP_UNE == 14, ""); // 1 1 1 0 + static_assert(Predicate::FCMP_TRUE == 15, ""); // 1 1 1 1 + return static_cast(CC.getKind()); } /// This is the complement of getICmpCode, which turns an opcode and two @@ -70,7 +69,7 @@ /// use in the new icmp instruction. static Value *getNewICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, InstCombiner::BuilderTy *Builder) { - ICmpInst::Predicate NewPred; + Predicate NewPred; if (Value *NewConstant = getICmpValue(Sign, Code, LHS, RHS, NewPred)) return NewConstant; return Builder->CreateICmp(NewPred, LHS, RHS); @@ -80,12 +79,11 @@ /// operands into either a FCmp instruction, or a true/false constant. static Value *getFCmpValue(unsigned Code, Value *LHS, Value *RHS, InstCombiner::BuilderTy *Builder) { - const auto Pred = static_cast(Code); - assert(FCmpInst::FCMP_FALSE <= Pred && Pred <= FCmpInst::FCMP_TRUE && - "Unexpected FCmp predicate!"); - if (Pred == FCmpInst::FCMP_FALSE) + const auto Pred = static_cast(Code); + assert(Pred.isFP() && "Unexpected FCmp predicate!"); + if (Pred == Predicate::FCMP_FALSE) return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0); - if (Pred == FCmpInst::FCMP_TRUE) + if (Pred == Predicate::FCMP_TRUE) return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 1); return Builder->CreateFCmp(Pred, LHS, RHS); } @@ -289,9 +287,12 @@ /// insert new instructions. Value *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi, bool isSigned, bool Inside) { - assert(cast(ConstantExpr::getICmp((isSigned ? - ICmpInst::ICMP_SLE:ICmpInst::ICMP_ULE), Lo, Hi))->getZExtValue() && - "Lo is not <= Hi in range emission code!"); + assert( + cast( + ConstantExpr::getICmp( + (isSigned ? Predicate::ICMP_SLE : Predicate::ICMP_ULE), Lo, Hi)) + ->getZExtValue() && + "Lo is not <= Hi in range emission code!"); if (Inside) { if (Lo == Hi) // Trivially false. @@ -299,8 +300,7 @@ // V >= Min && V < Hi --> V < Hi if (cast(Lo)->isMinValue(isSigned)) { - ICmpInst::Predicate pred = (isSigned ? - ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT); + Predicate pred = (isSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT); return Builder->CreateICmp(pred, V, Hi); } @@ -317,8 +317,7 @@ // V < Min || V >= Hi -> V > Hi-1 Hi = SubOne(cast(Hi)); if (cast(Lo)->isMinValue(isSigned)) { - ICmpInst::Predicate pred = (isSigned ? - ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT); + Predicate pred = (isSigned ? Predicate::ICMP_SGT : Predicate::ICMP_UGT); return Builder->CreateICmp(pred, V, Hi); } @@ -439,13 +438,12 @@ /// Return the set of pattern classes (from MaskedICmpType) /// that (icmp SCC (A & B), C) satisfies. -static unsigned getTypeOfMaskedICmp(Value* A, Value* B, Value* C, - ICmpInst::Predicate SCC) -{ +static unsigned getTypeOfMaskedICmp(Value *A, Value *B, Value *C, + Predicate SCC) { ConstantInt *ACst = dyn_cast(A); ConstantInt *BCst = dyn_cast(B); ConstantInt *CCst = dyn_cast(C); - bool icmp_eq = (SCC == ICmpInst::ICMP_EQ); + bool icmp_eq = (SCC == Predicate::ICMP_EQ); bool icmp_abit = (ACst && !ACst->isZero() && ACst->getValue().isPowerOf2()); bool icmp_bbit = (BCst && !BCst->isZero() && @@ -527,12 +525,11 @@ /// Handle (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) /// Return the set of pattern classes (from MaskedICmpType) /// that both LHS and RHS satisfy. -static unsigned foldLogOpOfMaskedICmpsHelper(Value*& A, - Value*& B, Value*& C, - Value*& D, Value*& E, +static unsigned foldLogOpOfMaskedICmpsHelper(Value *&A, Value *&B, Value *&C, + Value *&D, Value *&E, ICmpInst *LHS, ICmpInst *RHS, - ICmpInst::Predicate &LHSCC, - ICmpInst::Predicate &RHSCC) { + Predicate &LHSCC, + Predicate &RHSCC) { if (LHS->getOperand(0)->getType() != RHS->getOperand(0)->getType()) return 0; // vectors are not (yet?) supported if (LHS->getOperand(0)->getType()->isVectorTy()) return 0; @@ -571,7 +568,7 @@ } // Bail if LHS was a icmp that can't be decomposed into an equality. - if (!ICmpInst::isEquality(LHSCC)) + if (!LHSCC.isEquality()) return 0; Value *R1 = RHS->getOperand(0); @@ -603,7 +600,7 @@ } // Bail if RHS was a icmp that can't be decomposed into an equality. - if (!ICmpInst::isEquality(RHSCC)) + if (!RHSCC.isEquality()) return 0; // Look for ANDs on the right side of the RHS icmp. @@ -644,11 +641,11 @@ static Value *foldLogOpOfMaskedICmps(ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, llvm::InstCombiner::BuilderTy *Builder) { Value *A = nullptr, *B = nullptr, *C = nullptr, *D = nullptr, *E = nullptr; - ICmpInst::Predicate LHSCC = LHS->getPredicate(), RHSCC = RHS->getPredicate(); + Predicate LHSCC = LHS->getPredicate(), RHSCC = RHS->getPredicate(); unsigned Mask = foldLogOpOfMaskedICmpsHelper(A, B, C, D, E, LHS, RHS, LHSCC, RHSCC); if (Mask == 0) return nullptr; - assert(ICmpInst::isEquality(LHSCC) && ICmpInst::isEquality(RHSCC) && + assert(LHSCC.isEquality() && RHSCC.isEquality() && "foldLogOpOfMaskedICmpsHelper must return an equality predicate."); // In full generality: @@ -663,7 +660,7 @@ // input and output). // In most cases we're going to produce an EQ for the "&&" case. - ICmpInst::Predicate NewCC = IsAnd ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_NE; + Predicate NewCC = IsAnd ? Predicate::ICMP_EQ : Predicate::ICMP_NE; if (!IsAnd) { // Convert the masking analysis into its equivalent with negated // comparisons. @@ -773,16 +770,16 @@ if (!RangeStart) return nullptr; - ICmpInst::Predicate Pred0 = (Inverted ? Cmp0->getInversePredicate() : - Cmp0->getPredicate()); + Predicate Pred0 = + (Inverted ? Cmp0->getInversePredicate() : Cmp0->getPredicate()); // Accept x > -1 or x >= 0 (after potentially inverting the predicate). - if (!((Pred0 == ICmpInst::ICMP_SGT && RangeStart->isMinusOne()) || - (Pred0 == ICmpInst::ICMP_SGE && RangeStart->isZero()))) + if (!((Pred0 == Predicate::ICMP_SGT && RangeStart->isMinusOne()) || + (Pred0 == Predicate::ICMP_SGE && RangeStart->isZero()))) return nullptr; - ICmpInst::Predicate Pred1 = (Inverted ? Cmp1->getInversePredicate() : - Cmp1->getPredicate()); + Predicate Pred1 = + (Inverted ? Cmp1->getInversePredicate() : Cmp1->getPredicate()); Value *Input = Cmp0->getOperand(0); Value *RangeEnd; @@ -792,17 +789,22 @@ } else if (Cmp1->getOperand(1) == Input) { // For the upper range compare we have: icmp n, x RangeEnd = Cmp1->getOperand(0); - Pred1 = ICmpInst::getSwappedPredicate(Pred1); + Pred1 = Pred1.getSwapped(); } else { return nullptr; } // Check the upper range comparison, e.g. x < n - ICmpInst::Predicate NewPred; - switch (Pred1) { - case ICmpInst::ICMP_SLT: NewPred = ICmpInst::ICMP_ULT; break; - case ICmpInst::ICMP_SLE: NewPred = ICmpInst::ICMP_ULE; break; - default: return nullptr; + Predicate NewPred; + switch (Pred1.getKind()) { + case Predicate::ICMP_SLT: + NewPred = Predicate::ICMP_ULT; + break; + case Predicate::ICMP_SLE: + NewPred = Predicate::ICMP_ULE; + break; + default: + return nullptr; } // This simplification is only valid if the upper range is not negative. @@ -812,14 +814,14 @@ return nullptr; if (Inverted) - NewPred = ICmpInst::getInversePredicate(NewPred); + NewPred = NewPred.getInverse(); return Builder->CreateICmp(NewPred, Input, RangeEnd); } /// Fold (icmp)&(icmp) if possible. Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) { - ICmpInst::Predicate LHSCC = LHS->getPredicate(), RHSCC = RHS->getPredicate(); + Predicate LHSCC = LHS->getPredicate(), RHSCC = RHS->getPredicate(); // (icmp1 A, B) & (icmp2 A, B) --> (icmp3 A, B) if (PredicatesFoldable(LHSCC, RHSCC)) { @@ -857,8 +859,8 @@ // (icmp ult A, C) & (icmp ult B, C) --> (icmp ult (A|B), C) // where C is a power of 2 or // (icmp eq A, 0) & (icmp eq B, 0) --> (icmp eq (A|B), 0) - if ((LHSCC == ICmpInst::ICMP_ULT && LHSCst->getValue().isPowerOf2()) || - (LHSCC == ICmpInst::ICMP_EQ && LHSCst->isZero())) { + if ((LHSCC == Predicate::ICMP_ULT && LHSCst->getValue().isPowerOf2()) || + (LHSCC == Predicate::ICMP_EQ && LHSCst->isZero())) { Value *NewOr = Builder->CreateOr(Val, Val2); return Builder->CreateICmp(LHSCC, NewOr, LHSCst); } @@ -867,8 +869,8 @@ // (trunc x) == C1 & (and x, CA) == C2 -> (and x, CA|CMAX) == C1|C2 // where CMAX is the all ones value for the truncated type, // iff the lower bits of C2 and CA are zero. - if (LHSCC == ICmpInst::ICMP_EQ && LHSCC == RHSCC && - LHS->hasOneUse() && RHS->hasOneUse()) { + if (LHSCC == Predicate::ICMP_EQ && LHSCC == RHSCC && LHS->hasOneUse() && + RHS->hasOneUse()) { Value *V; ConstantInt *AndCst, *SmallCst = nullptr, *BigCst = nullptr; @@ -904,10 +906,10 @@ if (Val != Val2) return nullptr; // ICMP_[US][GL]E X, CST is folded to ICMP_[US][GL]T elsewhere. - if (LHSCC == ICmpInst::ICMP_UGE || LHSCC == ICmpInst::ICMP_ULE || - RHSCC == ICmpInst::ICMP_UGE || RHSCC == ICmpInst::ICMP_ULE || - LHSCC == ICmpInst::ICMP_SGE || LHSCC == ICmpInst::ICMP_SLE || - RHSCC == ICmpInst::ICMP_SGE || RHSCC == ICmpInst::ICMP_SLE) + if (LHSCC.isOneOf(Predicate::ICMP_UGE, Predicate::ICMP_ULE, + Predicate::ICMP_SGE, Predicate::ICMP_SLE) || + RHSCC.isOneOf(Predicate::ICMP_UGE, Predicate::ICMP_ULE, + Predicate::ICMP_SGE, Predicate::ICMP_SLE)) return nullptr; // We can't fold (ugt x, C) & (sgt x, C2). @@ -916,9 +918,7 @@ // Ensure that the larger constant is on the RHS. bool ShouldSwap; - if (CmpInst::isSigned(LHSCC) || - (ICmpInst::isEquality(LHSCC) && - CmpInst::isSigned(RHSCC))) + if (LHSCC.isSigned() || (LHSCC.isEquality() && RHSCC.isSigned())) ShouldSwap = LHSCst->getValue().sgt(RHSCst->getValue()); else ShouldSwap = LHSCst->getValue().ugt(RHSCst->getValue()); @@ -937,34 +937,34 @@ // are not equal and that the larger constant is on the RHS assert(LHSCst != RHSCst && "Compares not folded above?"); - switch (LHSCC) { + switch (LHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: - switch (RHSCC) { + case Predicate::ICMP_EQ: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_NE: // (X == 13 & X != 15) -> X == 13 - case ICmpInst::ICMP_ULT: // (X == 13 & X < 15) -> X == 13 - case ICmpInst::ICMP_SLT: // (X == 13 & X < 15) -> X == 13 + case Predicate::ICMP_NE: // (X == 13 & X != 15) -> X == 13 + case Predicate::ICMP_ULT: // (X == 13 & X < 15) -> X == 13 + case Predicate::ICMP_SLT: // (X == 13 & X < 15) -> X == 13 return LHS; } - case ICmpInst::ICMP_NE: - switch (RHSCC) { + case Predicate::ICMP_NE: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_ULT: + case Predicate::ICMP_ULT: if (LHSCst == SubOne(RHSCst)) // (X != 13 & X u< 14) -> X < 13 return Builder->CreateICmpULT(Val, LHSCst); if (LHSCst->isNullValue()) // (X != 0 & X u< 14) -> X-1 u< 13 return InsertRangeTest(Val, AddOne(LHSCst), RHSCst, false, true); break; // (X != 13 & X u< 15) -> no change - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: if (LHSCst == SubOne(RHSCst)) // (X != 13 & X s< 14) -> X < 13 return Builder->CreateICmpSLT(Val, LHSCst); break; // (X != 13 & X s< 15) -> no change - case ICmpInst::ICMP_EQ: // (X != 13 & X == 15) -> X == 15 - case ICmpInst::ICMP_UGT: // (X != 13 & X u> 15) -> X u> 15 - case ICmpInst::ICMP_SGT: // (X != 13 & X s> 15) -> X s> 15 + case Predicate::ICMP_EQ: // (X != 13 & X == 15) -> X == 15 + case Predicate::ICMP_UGT: // (X != 13 & X u> 15) -> X u> 15 + case Predicate::ICMP_SGT: // (X != 13 & X s> 15) -> X s> 15 return RHS; - case ICmpInst::ICMP_NE: + case Predicate::ICMP_NE: // Special case to get the ordering right when the values wrap around // zero. if (LHSCst->getValue() == 0 && RHSCst->getValue().isAllOnesValue()) @@ -978,66 +978,66 @@ break; // (X != 13 & X != 15) -> no change } break; - case ICmpInst::ICMP_ULT: - switch (RHSCC) { + case Predicate::ICMP_ULT: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: // (X u< 13 & X == 15) -> false - case ICmpInst::ICMP_UGT: // (X u< 13 & X u> 15) -> false + case Predicate::ICMP_EQ: // (X u< 13 & X == 15) -> false + case Predicate::ICMP_UGT: // (X u< 13 & X u> 15) -> false return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0); - case ICmpInst::ICMP_SGT: // (X u< 13 & X s> 15) -> no change + case Predicate::ICMP_SGT: // (X u< 13 & X s> 15) -> no change break; - case ICmpInst::ICMP_NE: // (X u< 13 & X != 15) -> X u< 13 - case ICmpInst::ICMP_ULT: // (X u< 13 & X u< 15) -> X u< 13 + case Predicate::ICMP_NE: // (X u< 13 & X != 15) -> X u< 13 + case Predicate::ICMP_ULT: // (X u< 13 & X u< 15) -> X u< 13 return LHS; - case ICmpInst::ICMP_SLT: // (X u< 13 & X s< 15) -> no change + case Predicate::ICMP_SLT: // (X u< 13 & X s< 15) -> no change break; } break; - case ICmpInst::ICMP_SLT: - switch (RHSCC) { + case Predicate::ICMP_SLT: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_UGT: // (X s< 13 & X u> 15) -> no change + case Predicate::ICMP_UGT: // (X s< 13 & X u> 15) -> no change break; - case ICmpInst::ICMP_NE: // (X s< 13 & X != 15) -> X < 13 - case ICmpInst::ICMP_SLT: // (X s< 13 & X s< 15) -> X < 13 + case Predicate::ICMP_NE: // (X s< 13 & X != 15) -> X < 13 + case Predicate::ICMP_SLT: // (X s< 13 & X s< 15) -> X < 13 return LHS; - case ICmpInst::ICMP_ULT: // (X s< 13 & X u< 15) -> no change + case Predicate::ICMP_ULT: // (X s< 13 & X u< 15) -> no change break; } break; - case ICmpInst::ICMP_UGT: - switch (RHSCC) { + case Predicate::ICMP_UGT: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: // (X u> 13 & X == 15) -> X == 15 - case ICmpInst::ICMP_UGT: // (X u> 13 & X u> 15) -> X u> 15 + case Predicate::ICMP_EQ: // (X u> 13 & X == 15) -> X == 15 + case Predicate::ICMP_UGT: // (X u> 13 & X u> 15) -> X u> 15 return RHS; - case ICmpInst::ICMP_SGT: // (X u> 13 & X s> 15) -> no change + case Predicate::ICMP_SGT: // (X u> 13 & X s> 15) -> no change break; - case ICmpInst::ICMP_NE: + case Predicate::ICMP_NE: if (RHSCst == AddOne(LHSCst)) // (X u> 13 & X != 14) -> X u> 14 return Builder->CreateICmp(LHSCC, Val, RHSCst); break; // (X u> 13 & X != 15) -> no change - case ICmpInst::ICMP_ULT: // (X u> 13 & X u< 15) -> (X-14) 13 & X u< 15) -> (X-14) 13 & X s< 15) -> no change + case Predicate::ICMP_SLT: // (X u> 13 & X s< 15) -> no change break; } break; - case ICmpInst::ICMP_SGT: - switch (RHSCC) { + case Predicate::ICMP_SGT: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: // (X s> 13 & X == 15) -> X == 15 - case ICmpInst::ICMP_SGT: // (X s> 13 & X s> 15) -> X s> 15 + case Predicate::ICMP_EQ: // (X s> 13 & X == 15) -> X == 15 + case Predicate::ICMP_SGT: // (X s> 13 & X s> 15) -> X s> 15 return RHS; - case ICmpInst::ICMP_UGT: // (X s> 13 & X u> 15) -> no change + case Predicate::ICMP_UGT: // (X s> 13 & X u> 15) -> no change break; - case ICmpInst::ICMP_NE: + case Predicate::ICMP_NE: if (RHSCst == AddOne(LHSCst)) // (X s> 13 & X != 14) -> X s> 14 return Builder->CreateICmp(LHSCC, Val, RHSCst); break; // (X s> 13 & X != 15) -> no change - case ICmpInst::ICMP_SLT: // (X s> 13 & X s< 15) -> (X-14) s< 1 + case Predicate::ICMP_SLT: // (X s> 13 & X s< 15) -> (X-14) s< 1 return InsertRangeTest(Val, AddOne(LHSCst), RHSCst, true, true); - case ICmpInst::ICMP_ULT: // (X s> 13 & X u< 15) -> no change + case Predicate::ICMP_ULT: // (X s> 13 & X u< 15) -> no change break; } break; @@ -1051,11 +1051,11 @@ Value *InstCombiner::FoldAndOfFCmps(FCmpInst *LHS, FCmpInst *RHS) { Value *Op0LHS = LHS->getOperand(0), *Op0RHS = LHS->getOperand(1); Value *Op1LHS = RHS->getOperand(0), *Op1RHS = RHS->getOperand(1); - FCmpInst::Predicate Op0CC = LHS->getPredicate(), Op1CC = RHS->getPredicate(); + Predicate Op0CC = LHS->getPredicate(), Op1CC = RHS->getPredicate(); if (Op0LHS == Op1RHS && Op0RHS == Op1LHS) { // Swap RHS operands to match LHS. - Op1CC = FCmpInst::getSwappedPredicate(Op1CC); + Op1CC = Op1CC.getSwapped(); std::swap(Op1LHS, Op1RHS); } @@ -1072,8 +1072,8 @@ return getFCmpValue(getFCmpCode(Op0CC) & getFCmpCode(Op1CC), Op0LHS, Op0RHS, Builder); - if (LHS->getPredicate() == FCmpInst::FCMP_ORD && - RHS->getPredicate() == FCmpInst::FCMP_ORD) { + if (LHS->getPredicate() == Predicate::FCMP_ORD && + RHS->getPredicate() == Predicate::FCMP_ORD) { if (LHS->getOperand(0)->getType() != RHS->getOperand(0)->getType()) return nullptr; @@ -1645,15 +1645,15 @@ /// Fold (icmp)|(icmp) if possible. Value *InstCombiner::FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, Instruction *CxtI) { - ICmpInst::Predicate LHSCC = LHS->getPredicate(), RHSCC = RHS->getPredicate(); + Predicate LHSCC = LHS->getPredicate(), RHSCC = RHS->getPredicate(); // Fold (iszero(A & K1) | iszero(A & K2)) -> (A & (K1 | K2)) != (K1 | K2) // if K1 and K2 are a one-bit mask. ConstantInt *LHSCst = dyn_cast(LHS->getOperand(1)); ConstantInt *RHSCst = dyn_cast(RHS->getOperand(1)); - if (LHS->getPredicate() == ICmpInst::ICMP_EQ && LHSCst && LHSCst->isZero() && - RHS->getPredicate() == ICmpInst::ICMP_EQ && RHSCst && RHSCst->isZero()) { + if (LHS->getPredicate() == Predicate::ICMP_EQ && LHSCst && LHSCst->isZero() && + RHS->getPredicate() == Predicate::ICMP_EQ && RHSCst && RHSCst->isZero()) { BinaryOperator *LAnd = dyn_cast(LHS->getOperand(0)); BinaryOperator *RAnd = dyn_cast(RHS->getOperand(0)); @@ -1680,7 +1680,7 @@ } if (Masked) - return Builder->CreateICmp(ICmpInst::ICMP_NE, Masked, Mask); + return Builder->CreateICmp(Predicate::ICMP_NE, Masked, Mask); } } @@ -1695,7 +1695,7 @@ // 4) LowRange1 ^ LowRange2 and HighRange1 ^ HighRange2 are one-bit mask. // This implies all values in the two ranges differ by exactly one bit. - if ((LHSCC == ICmpInst::ICMP_ULT || LHSCC == ICmpInst::ICMP_ULE) && + if ((LHSCC == Predicate::ICMP_ULT || LHSCC == Predicate::ICMP_ULE) && LHSCC == RHSCC && LHSCst && RHSCst && LHS->hasOneUse() && RHS->hasOneUse() && LHSCst->getType() == RHSCst->getType() && LHSCst->getValue() == (RHSCst->getValue())) { @@ -1763,25 +1763,25 @@ // (icmp eq B, 0) | (icmp ult A, B) -> (icmp ule A, B-1) // (icmp eq B, 0) | (icmp ugt B, A) -> (icmp ule A, B-1) Value *A = nullptr, *B = nullptr; - if (LHSCC == ICmpInst::ICMP_EQ && LHSCst && LHSCst->isZero()) { + if (LHSCC == Predicate::ICMP_EQ && LHSCst && LHSCst->isZero()) { B = Val; - if (RHSCC == ICmpInst::ICMP_ULT && Val == RHS->getOperand(1)) + if (RHSCC == Predicate::ICMP_ULT && Val == RHS->getOperand(1)) A = Val2; - else if (RHSCC == ICmpInst::ICMP_UGT && Val == Val2) + else if (RHSCC == Predicate::ICMP_UGT && Val == Val2) A = RHS->getOperand(1); } // (icmp ult A, B) | (icmp eq B, 0) -> (icmp ule A, B-1) // (icmp ugt B, A) | (icmp eq B, 0) -> (icmp ule A, B-1) - else if (RHSCC == ICmpInst::ICMP_EQ && RHSCst && RHSCst->isZero()) { + else if (RHSCC == Predicate::ICMP_EQ && RHSCst && RHSCst->isZero()) { B = Val2; - if (LHSCC == ICmpInst::ICMP_ULT && Val2 == LHS->getOperand(1)) + if (LHSCC == Predicate::ICMP_ULT && Val2 == LHS->getOperand(1)) A = Val; - else if (LHSCC == ICmpInst::ICMP_UGT && Val2 == Val) + else if (LHSCC == Predicate::ICMP_UGT && Val2 == Val) A = LHS->getOperand(1); } if (A && B) return Builder->CreateICmp( - ICmpInst::ICMP_UGE, + Predicate::ICMP_UGE, Builder->CreateAdd(B, ConstantInt::getSigned(B->getType(), -1)), A); } @@ -1798,7 +1798,7 @@ if (LHSCst == RHSCst && LHSCC == RHSCC) { // (icmp ne A, 0) | (icmp ne B, 0) --> (icmp ne (A|B), 0) - if (LHSCC == ICmpInst::ICMP_NE && LHSCst->isZero()) { + if (LHSCC == Predicate::ICMP_NE && LHSCst->isZero()) { Value *NewOr = Builder->CreateOr(Val, Val2); return Builder->CreateICmp(LHSCC, NewOr, LHSCst); } @@ -1806,7 +1806,7 @@ // (icmp ult (X + CA), C1) | (icmp eq X, C2) -> (icmp ule (X + CA), C1) // iff C2 + CA == C1. - if (LHSCC == ICmpInst::ICMP_ULT && RHSCC == ICmpInst::ICMP_EQ) { + if (LHSCC == Predicate::ICMP_ULT && RHSCC == Predicate::ICMP_EQ) { ConstantInt *AddCst; if (match(Val, m_Add(m_Specific(Val2), m_ConstantInt(AddCst)))) if (RHSCst->getValue() + AddCst->getValue() == LHSCst->getValue()) @@ -1818,10 +1818,10 @@ if (Val != Val2) return nullptr; // ICMP_[US][GL]E X, CST is folded to ICMP_[US][GL]T elsewhere. - if (LHSCC == ICmpInst::ICMP_UGE || LHSCC == ICmpInst::ICMP_ULE || - RHSCC == ICmpInst::ICMP_UGE || RHSCC == ICmpInst::ICMP_ULE || - LHSCC == ICmpInst::ICMP_SGE || LHSCC == ICmpInst::ICMP_SLE || - RHSCC == ICmpInst::ICMP_SGE || RHSCC == ICmpInst::ICMP_SLE) + if (LHSCC.isOneOf(Predicate::ICMP_UGE, Predicate::ICMP_ULE, + Predicate::ICMP_SGE, Predicate::ICMP_SLE) || + RHSCC.isOneOf(Predicate::ICMP_UGE, Predicate::ICMP_ULE, + Predicate::ICMP_SGE, Predicate::ICMP_SLE)) return nullptr; // We can't fold (ugt x, C) | (sgt x, C2). @@ -1830,9 +1830,7 @@ // Ensure that the larger constant is on the RHS. bool ShouldSwap; - if (CmpInst::isSigned(LHSCC) || - (ICmpInst::isEquality(LHSCC) && - CmpInst::isSigned(RHSCC))) + if (LHSCC.isSigned() || (LHSCC.isEquality() && RHSCC.isSigned())) ShouldSwap = LHSCst->getValue().sgt(RHSCst->getValue()); else ShouldSwap = LHSCst->getValue().ugt(RHSCst->getValue()); @@ -1851,12 +1849,12 @@ // equal. assert(LHSCst != RHSCst && "Compares not folded above?"); - switch (LHSCC) { + switch (LHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: - switch (RHSCC) { + case Predicate::ICMP_EQ: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: + case Predicate::ICMP_EQ: if (LHS->getOperand(0) == RHS->getOperand(0)) { // if LHSCst and RHSCst differ only by one bit: // (A == C1 || A == C2) -> (A | (C1 ^ C2)) == C2 @@ -1866,7 +1864,7 @@ if (Xor.isPowerOf2()) { Value *Cst = Builder->getInt(Xor); Value *Or = Builder->CreateOr(LHS->getOperand(0), Cst); - return Builder->CreateICmp(ICmpInst::ICMP_EQ, Or, RHSCst); + return Builder->CreateICmp(Predicate::ICMP_EQ, Or, RHSCst); } } @@ -1879,94 +1877,94 @@ } break; // (X == 13 | X == 15) -> no change - case ICmpInst::ICMP_UGT: // (X == 13 | X u> 14) -> no change - case ICmpInst::ICMP_SGT: // (X == 13 | X s> 14) -> no change + case Predicate::ICMP_UGT: // (X == 13 | X u> 14) -> no change + case Predicate::ICMP_SGT: // (X == 13 | X s> 14) -> no change break; - case ICmpInst::ICMP_NE: // (X == 13 | X != 15) -> X != 15 - case ICmpInst::ICMP_ULT: // (X == 13 | X u< 15) -> X u< 15 - case ICmpInst::ICMP_SLT: // (X == 13 | X s< 15) -> X s< 15 + case Predicate::ICMP_NE: // (X == 13 | X != 15) -> X != 15 + case Predicate::ICMP_ULT: // (X == 13 | X u< 15) -> X u< 15 + case Predicate::ICMP_SLT: // (X == 13 | X s< 15) -> X s< 15 return RHS; } break; - case ICmpInst::ICMP_NE: - switch (RHSCC) { + case Predicate::ICMP_NE: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: // (X != 13 | X == 15) -> X != 13 - case ICmpInst::ICMP_UGT: // (X != 13 | X u> 15) -> X != 13 - case ICmpInst::ICMP_SGT: // (X != 13 | X s> 15) -> X != 13 + case Predicate::ICMP_EQ: // (X != 13 | X == 15) -> X != 13 + case Predicate::ICMP_UGT: // (X != 13 | X u> 15) -> X != 13 + case Predicate::ICMP_SGT: // (X != 13 | X s> 15) -> X != 13 return LHS; - case ICmpInst::ICMP_NE: // (X != 13 | X != 15) -> true - case ICmpInst::ICMP_ULT: // (X != 13 | X u< 15) -> true - case ICmpInst::ICMP_SLT: // (X != 13 | X s< 15) -> true + case Predicate::ICMP_NE: // (X != 13 | X != 15) -> true + case Predicate::ICMP_ULT: // (X != 13 | X u< 15) -> true + case Predicate::ICMP_SLT: // (X != 13 | X s< 15) -> true return Builder->getTrue(); } - case ICmpInst::ICMP_ULT: - switch (RHSCC) { + case Predicate::ICMP_ULT: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: // (X u< 13 | X == 14) -> no change + case Predicate::ICMP_EQ: // (X u< 13 | X == 14) -> no change break; - case ICmpInst::ICMP_UGT: // (X u< 13 | X u> 15) -> (X-13) u> 2 + case Predicate::ICMP_UGT: // (X u< 13 | X u> 15) -> (X-13) u> 2 // If RHSCst is [us]MAXINT, it is always false. Not handling // this can cause overflow. if (RHSCst->isMaxValue(false)) return LHS; return InsertRangeTest(Val, LHSCst, AddOne(RHSCst), false, false); - case ICmpInst::ICMP_SGT: // (X u< 13 | X s> 15) -> no change + case Predicate::ICMP_SGT: // (X u< 13 | X s> 15) -> no change break; - case ICmpInst::ICMP_NE: // (X u< 13 | X != 15) -> X != 15 - case ICmpInst::ICMP_ULT: // (X u< 13 | X u< 15) -> X u< 15 + case Predicate::ICMP_NE: // (X u< 13 | X != 15) -> X != 15 + case Predicate::ICMP_ULT: // (X u< 13 | X u< 15) -> X u< 15 return RHS; - case ICmpInst::ICMP_SLT: // (X u< 13 | X s< 15) -> no change + case Predicate::ICMP_SLT: // (X u< 13 | X s< 15) -> no change break; } break; - case ICmpInst::ICMP_SLT: - switch (RHSCC) { + case Predicate::ICMP_SLT: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: // (X s< 13 | X == 14) -> no change + case Predicate::ICMP_EQ: // (X s< 13 | X == 14) -> no change break; - case ICmpInst::ICMP_SGT: // (X s< 13 | X s> 15) -> (X-13) s> 2 + case Predicate::ICMP_SGT: // (X s< 13 | X s> 15) -> (X-13) s> 2 // If RHSCst is [us]MAXINT, it is always false. Not handling // this can cause overflow. if (RHSCst->isMaxValue(true)) return LHS; return InsertRangeTest(Val, LHSCst, AddOne(RHSCst), true, false); - case ICmpInst::ICMP_UGT: // (X s< 13 | X u> 15) -> no change + case Predicate::ICMP_UGT: // (X s< 13 | X u> 15) -> no change break; - case ICmpInst::ICMP_NE: // (X s< 13 | X != 15) -> X != 15 - case ICmpInst::ICMP_SLT: // (X s< 13 | X s< 15) -> X s< 15 + case Predicate::ICMP_NE: // (X s< 13 | X != 15) -> X != 15 + case Predicate::ICMP_SLT: // (X s< 13 | X s< 15) -> X s< 15 return RHS; - case ICmpInst::ICMP_ULT: // (X s< 13 | X u< 15) -> no change + case Predicate::ICMP_ULT: // (X s< 13 | X u< 15) -> no change break; } break; - case ICmpInst::ICMP_UGT: - switch (RHSCC) { + case Predicate::ICMP_UGT: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: // (X u> 13 | X == 15) -> X u> 13 - case ICmpInst::ICMP_UGT: // (X u> 13 | X u> 15) -> X u> 13 + case Predicate::ICMP_EQ: // (X u> 13 | X == 15) -> X u> 13 + case Predicate::ICMP_UGT: // (X u> 13 | X u> 15) -> X u> 13 return LHS; - case ICmpInst::ICMP_SGT: // (X u> 13 | X s> 15) -> no change + case Predicate::ICMP_SGT: // (X u> 13 | X s> 15) -> no change break; - case ICmpInst::ICMP_NE: // (X u> 13 | X != 15) -> true - case ICmpInst::ICMP_ULT: // (X u> 13 | X u< 15) -> true + case Predicate::ICMP_NE: // (X u> 13 | X != 15) -> true + case Predicate::ICMP_ULT: // (X u> 13 | X u< 15) -> true return Builder->getTrue(); - case ICmpInst::ICMP_SLT: // (X u> 13 | X s< 15) -> no change + case Predicate::ICMP_SLT: // (X u> 13 | X s< 15) -> no change break; } break; - case ICmpInst::ICMP_SGT: - switch (RHSCC) { + case Predicate::ICMP_SGT: + switch (RHSCC.getKind()) { default: llvm_unreachable("Unknown integer condition code!"); - case ICmpInst::ICMP_EQ: // (X s> 13 | X == 15) -> X > 13 - case ICmpInst::ICMP_SGT: // (X s> 13 | X s> 15) -> X > 13 + case Predicate::ICMP_EQ: // (X s> 13 | X == 15) -> X > 13 + case Predicate::ICMP_SGT: // (X s> 13 | X s> 15) -> X > 13 return LHS; - case ICmpInst::ICMP_UGT: // (X s> 13 | X u> 15) -> no change + case Predicate::ICMP_UGT: // (X s> 13 | X u> 15) -> no change break; - case ICmpInst::ICMP_NE: // (X s> 13 | X != 15) -> true - case ICmpInst::ICMP_SLT: // (X s> 13 | X s< 15) -> true + case Predicate::ICMP_NE: // (X s> 13 | X != 15) -> true + case Predicate::ICMP_SLT: // (X s> 13 | X s< 15) -> true return Builder->getTrue(); - case ICmpInst::ICMP_ULT: // (X s> 13 | X u< 15) -> no change + case Predicate::ICMP_ULT: // (X s> 13 | X u< 15) -> no change break; } break; @@ -1979,11 +1977,11 @@ Value *InstCombiner::FoldOrOfFCmps(FCmpInst *LHS, FCmpInst *RHS) { Value *Op0LHS = LHS->getOperand(0), *Op0RHS = LHS->getOperand(1); Value *Op1LHS = RHS->getOperand(0), *Op1RHS = RHS->getOperand(1); - FCmpInst::Predicate Op0CC = LHS->getPredicate(), Op1CC = RHS->getPredicate(); + Predicate Op0CC = LHS->getPredicate(), Op1CC = RHS->getPredicate(); if (Op0LHS == Op1RHS && Op0RHS == Op1LHS) { // Swap RHS operands to match LHS. - Op1CC = FCmpInst::getSwappedPredicate(Op1CC); + Op1CC = Op1CC.getSwapped(); std::swap(Op1LHS, Op1RHS); } @@ -1998,8 +1996,8 @@ return getFCmpValue(getFCmpCode(Op0CC) | getFCmpCode(Op1CC), Op0LHS, Op0RHS, Builder); - if (LHS->getPredicate() == FCmpInst::FCMP_UNO && - RHS->getPredicate() == FCmpInst::FCMP_UNO && + if (LHS->getPredicate() == Predicate::FCMP_UNO && + RHS->getPredicate() == Predicate::FCMP_UNO && LHS->getOperand(0)->getType() == RHS->getOperand(0)->getType()) { if (ConstantFP *LHSC = dyn_cast(LHS->getOperand(1))) if (ConstantFP *RHSC = dyn_cast(RHS->getOperand(1))) { Index: lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCalls.cpp +++ lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -930,25 +930,27 @@ if (auto *CInt = dyn_cast(II.getArgOperand(2))) { uint64_t Imm = CInt->getZExtValue() & 0x7; VectorType *VecTy = cast(II.getType()); - CmpInst::Predicate Pred = ICmpInst::BAD_ICMP_PREDICATE; + Predicate Pred = Predicate::BAD_ICMP_PREDICATE; switch (Imm) { case 0x0: - Pred = IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; + Pred = IsSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT; break; case 0x1: - Pred = IsSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE; + Pred = IsSigned ? Predicate::ICMP_SLE : Predicate::ICMP_ULE; break; case 0x2: - Pred = IsSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; + Pred = IsSigned ? Predicate::ICMP_SGT : Predicate::ICMP_UGT; break; case 0x3: - Pred = IsSigned ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE; + Pred = IsSigned ? Predicate::ICMP_SGE : Predicate::ICMP_UGE; break; case 0x4: - Pred = ICmpInst::ICMP_EQ; break; + Pred = Predicate::ICMP_EQ; + break; case 0x5: - Pred = ICmpInst::ICMP_NE; break; + Pred = Predicate::ICMP_NE; + break; case 0x6: return ConstantInt::getSigned(VecTy, 0); // FALSE case 0x7: @@ -2282,11 +2284,9 @@ if (ICmpInst* ICmp = dyn_cast(IIOperand)) { Value *LHS = ICmp->getOperand(0); Value *RHS = ICmp->getOperand(1); - if (ICmpInst::ICMP_NE == ICmp->getPredicate() && - isa(LHS) && - isa(RHS) && - RHS->getType()->isPointerTy() && - cast(RHS)->isNullValue()) { + if (Predicate::ICMP_NE == ICmp->getPredicate().getKind() && + isa(LHS) && isa(RHS) && + RHS->getType()->isPointerTy() && cast(RHS)->isNullValue()) { LoadInst* LI = cast(LHS); if (isValidAssumeForContext(II, LI, &DT)) { MDNode *MD = MDNode::get(II->getContext(), None); Index: lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCasts.cpp +++ lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -486,7 +486,7 @@ Constant *One = ConstantInt::get(SrcTy, 1); Src = Builder->CreateAnd(Src, One); Value *Zero = Constant::getNullValue(Src->getType()); - return new ICmpInst(ICmpInst::ICMP_NE, Src, Zero); + return new ICmpInst(Predicate::ICMP_NE, Src, Zero); } // Transform trunc(lshr (zext A), Cst) to eliminate one type conversion. @@ -558,8 +558,9 @@ // zext (x x>>u31 true if signbit set. // zext (x >s -1) to i32 --> (x>>u31)^1 true if signbit clear. - if ((ICI->getPredicate() == ICmpInst::ICMP_SLT && Op1CV == 0) || - (ICI->getPredicate() == ICmpInst::ICMP_SGT && Op1CV.isAllOnesValue())) { + if ((ICI->getPredicate() == Predicate::ICMP_SLT && Op1CV == 0) || + (ICI->getPredicate() == Predicate::ICMP_SGT && + Op1CV.isAllOnesValue())) { if (!DoTransform) return ICI; Value *In = ICI->getOperand(0); @@ -569,7 +570,7 @@ if (In->getType() != CI.getType()) In = Builder->CreateIntCast(In, CI.getType(), false/*ZExt*/); - if (ICI->getPredicate() == ICmpInst::ICMP_SGT) { + if (ICI->getPredicate() == Predicate::ICMP_SGT) { Constant *One = ConstantInt::get(In->getType(), 1); In = Builder->CreateXor(In, One, In->getName() + ".not"); } @@ -597,7 +598,7 @@ if (KnownZeroMask.isPowerOf2()) { // Exactly 1 possible 1? if (!DoTransform) return ICI; - bool isNE = ICI->getPredicate() == ICmpInst::ICMP_NE; + bool isNE = ICI->getPredicate() == Predicate::ICMP_NE; if (Op1CV != 0 && (Op1CV != KnownZeroMask)) { // (X&4) == 2 --> false // (X&4) != 2 --> true @@ -661,7 +662,7 @@ Result = Builder->CreateLShr( Result, ConstantInt::get(ITy, UnknownBit.countTrailingZeros())); - if (ICI->getPredicate() == ICmpInst::ICMP_EQ) + if (ICI->getPredicate() == Predicate::ICMP_EQ) Result = Builder->CreateXor(Result, ConstantInt::get(ITy, 1)); Result->takeName(ICI); return replaceInstUsesWith(CI, Result); @@ -938,7 +939,7 @@ /// Transform (sext icmp) to bitwise / integer operations to eliminate the icmp. Instruction *InstCombiner::transformSExtICmp(ICmpInst *ICI, Instruction &CI) { Value *Op0 = ICI->getOperand(0), *Op1 = ICI->getOperand(1); - ICmpInst::Predicate Pred = ICI->getPredicate(); + Predicate Pred = ICI->getPredicate(); // Don't bother if Op1 isn't of vector or integer type. if (!Op1->getType()->isIntOrIntVectorTy()) @@ -947,8 +948,8 @@ if (Constant *Op1C = dyn_cast(Op1)) { // (x ashr x, 31 -> all ones if negative // (x >s -1) ? -1 : 0 -> not (ashr x, 31) -> all ones if positive - if ((Pred == ICmpInst::ICMP_SLT && Op1C->isNullValue()) || - (Pred == ICmpInst::ICMP_SGT && Op1C->isAllOnesValue())) { + if ((Pred == Predicate::ICMP_SLT && Op1C->isNullValue()) || + (Pred == Predicate::ICMP_SGT && Op1C->isAllOnesValue())) { Value *Sh = ConstantInt::get(Op0->getType(), Op0->getType()->getScalarSizeInBits()-1); @@ -956,7 +957,7 @@ if (In->getType() != CI.getType()) In = Builder->CreateIntCast(In, CI.getType(), true/*SExt*/); - if (Pred == ICmpInst::ICMP_SGT) + if (Pred == Predicate::ICMP_SGT) In = Builder->CreateNot(In, In->getName()+".not"); return replaceInstUsesWith(CI, In); } @@ -978,13 +979,13 @@ // If the icmp tests for a known zero bit we can constant fold it. if (!Op1C->isZero() && Op1C->getValue() != KnownZeroMask) { - Value *V = Pred == ICmpInst::ICMP_NE ? - ConstantInt::getAllOnesValue(CI.getType()) : - ConstantInt::getNullValue(CI.getType()); + Value *V = Pred == Predicate::ICMP_NE + ? ConstantInt::getAllOnesValue(CI.getType()) + : ConstantInt::getNullValue(CI.getType()); return replaceInstUsesWith(CI, V); } - if (!Op1C->isZero() == (Pred == ICmpInst::ICMP_NE)) { + if (!Op1C->isZero() == (Pred == Predicate::ICMP_NE)) { // sext ((x & 2^n) == 0) -> (x >> n) - 1 // sext ((x & 2^n) != 2^n) -> (x >> n) - 1 unsigned ShiftAmt = KnownZeroMask.countTrailingZeros(); Index: lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCompares.cpp +++ lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -126,23 +126,23 @@ /// Given an exploded icmp instruction, return true if the comparison only /// checks the sign bit. If it only checks the sign bit, set TrueIfSigned if the /// result of the comparison is true when the input value is signed. -static bool isSignBitCheck(ICmpInst::Predicate Pred, ConstantInt *RHS, +static bool isSignBitCheck(Predicate Pred, ConstantInt *RHS, bool &TrueIfSigned) { - switch (Pred) { - case ICmpInst::ICMP_SLT: // True if LHS s< 0 + switch (Pred.getKind()) { + case Predicate::ICMP_SLT: // True if LHS s< 0 TrueIfSigned = true; return RHS->isZero(); - case ICmpInst::ICMP_SLE: // True if LHS s<= RHS and RHS == -1 + case Predicate::ICMP_SLE: // True if LHS s<= RHS and RHS == -1 TrueIfSigned = true; return RHS->isAllOnesValue(); - case ICmpInst::ICMP_SGT: // True if LHS s> -1 + case Predicate::ICMP_SGT: // True if LHS s> -1 TrueIfSigned = false; return RHS->isAllOnesValue(); - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_UGT: // True if LHS u> RHS and RHS == high-bit-mask - 1 TrueIfSigned = true; return RHS->isMaxValue(true); - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: // True if LHS u>= RHS and RHS == high-bit-mask (2^7, 2^15, 2^31, etc) TrueIfSigned = true; return RHS->getValue().isSignBit(); @@ -154,21 +154,21 @@ /// Returns true if the exploded icmp can be expressed as a signed comparison /// to zero and updates the predicate accordingly. /// The signedness of the comparison is preserved. -static bool isSignTest(ICmpInst::Predicate &Pred, const ConstantInt *RHS) { - if (!ICmpInst::isSigned(Pred)) +static bool isSignTest(Predicate &Pred, const ConstantInt *RHS) { + if (!Pred.isSigned()) return false; if (RHS->isZero()) - return ICmpInst::isRelational(Pred); + return Pred.isRelational(); if (RHS->isOne()) { - if (Pred == ICmpInst::ICMP_SLT) { - Pred = ICmpInst::ICMP_SLE; + if (Pred == Predicate::ICMP_SLT) { + Pred = Predicate::ICMP_SLE; return true; } } else if (RHS->isAllOnesValue()) { - if (Pred == ICmpInst::ICMP_SGT) { - Pred = ICmpInst::ICMP_SGE; + if (Pred == Predicate::ICMP_SGT) { + Pred = Predicate::ICMP_SGE; return true; } } @@ -409,7 +409,7 @@ // True for one element -> 'i == 47'. if (SecondTrueElement == Undefined) - return new ICmpInst(ICmpInst::ICMP_EQ, Idx, FirstTrueIdx); + return new ICmpInst(Predicate::ICMP_EQ, Idx, FirstTrueIdx); // True for two elements -> 'i == 47 | i == 72'. Value *C1 = Builder->CreateICmpEQ(Idx, FirstTrueIdx); @@ -429,7 +429,7 @@ // False for one element -> 'i != 47'. if (SecondFalseElement == Undefined) - return new ICmpInst(ICmpInst::ICMP_NE, Idx, FirstFalseIdx); + return new ICmpInst(Predicate::ICMP_NE, Idx, FirstFalseIdx); // False for two elements -> 'i != 47 & i != 72'. Value *C1 = Builder->CreateICmpNE(Idx, FirstFalseIdx); @@ -451,7 +451,7 @@ Value *End = ConstantInt::get(Idx->getType(), TrueRangeEnd-FirstTrueElement+1); - return new ICmpInst(ICmpInst::ICMP_ULT, Idx, End); + return new ICmpInst(Predicate::ICMP_ULT, Idx, End); } // False range check. @@ -465,7 +465,7 @@ Value *End = ConstantInt::get(Idx->getType(), FalseRangeEnd-FirstFalseElement); - return new ICmpInst(ICmpInst::ICMP_UGT, Idx, End); + return new ICmpInst(Predicate::ICMP_UGT, Idx, End); } // If a magic bitvector captures the entire comparison state @@ -487,7 +487,7 @@ Value *V = Builder->CreateIntCast(Idx, Ty, false); V = Builder->CreateLShr(ConstantInt::get(Ty, MagicBitvector), V); V = Builder->CreateAnd(ConstantInt::get(Ty, 1), V); - return new ICmpInst(ICmpInst::ICMP_NE, V, ConstantInt::get(Ty, 0)); + return new ICmpInst(Predicate::ICMP_NE, V, ConstantInt::get(Ty, 0)); } } @@ -883,7 +883,7 @@ /// We can look through PHIs, GEPs and casts in order to determine a common base /// between GEPLHS and RHS. static Instruction *transformToIndexedCompare(GEPOperator *GEPLHS, Value *RHS, - ICmpInst::Predicate Cond, + Predicate Cond, const DataLayout &DL) { if (!GEPLHS->hasAllConstantIndices()) return nullptr; @@ -909,20 +909,19 @@ // GEP having PtrBase as the pointer base, and has returned in NewRHS the // offset. Since Index is the offset of LHS to the base pointer, we will now // compare the offsets instead of comparing the pointers. - return new ICmpInst(ICmpInst::getSignedPredicate(Cond), Index, NewRHS); + return new ICmpInst(Cond.getSigned(), Index, NewRHS); } /// Fold comparisons between a GEP instruction and something else. At this point /// we know that the GEP is on the LHS of the comparison. Instruction *InstCombiner::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, - ICmpInst::Predicate Cond, - Instruction &I) { + Predicate Cond, Instruction &I) { // Don't transform signed compares of GEPs into index compares. Even if the // GEP is inbounds, the final add of the base pointer can have signed overflow // and would change the result of the icmp. // e.g. "&foo[0] getType())); } else if (GEPOperator *GEPRHS = dyn_cast(RHS)) { // If the base pointers are different, but the indices are the same, just @@ -985,8 +984,7 @@ LOffset = Builder->CreateTrunc(LOffset, RHSIndexTy); } - Value *Cmp = Builder->CreateICmp(ICmpInst::getSignedPredicate(Cond), - LOffset, ROffset); + Value *Cmp = Builder->CreateICmp(Cond.getSigned(), LOffset, ROffset); return replaceInstUsesWith(I, Cmp); } @@ -998,8 +996,7 @@ // If one of the GEPs has all zero indices, recurse. if (GEPLHS->hasAllZeroIndices()) - return foldGEPICmp(GEPRHS, GEPLHS->getOperand(0), - ICmpInst::getSwappedPredicate(Cond), I); + return foldGEPICmp(GEPRHS, GEPLHS->getOperand(0), Cond.getSwapped(), I); // If the other GEP has all zero indices, recurse. if (GEPRHS->hasAllZeroIndices()) @@ -1025,13 +1022,13 @@ if (NumDifferences == 0) // SAME GEP? return replaceInstUsesWith(I, // No comparison is needed here. - Builder->getInt1(ICmpInst::isTrueWhenEqual(Cond))); + Builder->getInt1(Cond.isTrueWhenEqual())); else if (NumDifferences == 1 && GEPsInBounds) { Value *LHSV = GEPLHS->getOperand(DiffOperand); Value *RHSV = GEPRHS->getOperand(DiffOperand); // Make sure we do a signed comparison here. - return new ICmpInst(ICmpInst::getSignedPredicate(Cond), LHSV, RHSV); + return new ICmpInst(Cond.getSigned(), LHSV, RHSV); } } @@ -1042,7 +1039,7 @@ // ((gep Ptr, OFFSET1) cmp (gep Ptr, OFFSET2) ---> (OFFSET1 cmp OFFSET2) Value *L = EmitGEPOffset(GEPLHS); Value *R = EmitGEPOffset(GEPRHS); - return new ICmpInst(ICmpInst::getSignedPredicate(Cond), L, R); + return new ICmpInst(Cond.getSigned(), L, R); } } @@ -1124,14 +1121,12 @@ Type *CmpTy = CmpInst::makeCmpResultType(Other->getType()); return replaceInstUsesWith( - ICI, - ConstantInt::get(CmpTy, !CmpInst::isTrueWhenEqual(ICI.getPredicate()))); + ICI, ConstantInt::get(CmpTy, !ICI.getPredicate().isTrueWhenEqual())); } /// Fold "icmp pred (X+CI), X". -Instruction *InstCombiner::foldICmpAddOpConst(Instruction &ICI, - Value *X, ConstantInt *CI, - ICmpInst::Predicate Pred) { +Instruction *InstCombiner::foldICmpAddOpConst(Instruction &ICI, Value *X, + ConstantInt *CI, Predicate Pred) { // From this point on, we know that (X+C <= X) --> (X+C < X) because C != 0, // so the values can never be equal. Similarly for all other "or equals" // operators. @@ -1139,17 +1134,17 @@ // (X+1) X >u (MAXUINT-1) --> X == 255 // (X+2) X >u (MAXUINT-2) --> X > 253 // (X+MAXUINT) X >u (MAXUINT-MAXUINT) --> X != 0 - if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_ULE) { + if (Pred == Predicate::ICMP_ULT || Pred == Predicate::ICMP_ULE) { Value *R = ConstantExpr::getSub(ConstantInt::getAllOnesValue(CI->getType()), CI); - return new ICmpInst(ICmpInst::ICMP_UGT, X, R); + return new ICmpInst(Predicate::ICMP_UGT, X, R); } // (X+1) >u X --> X X != 255 // (X+2) >u X --> X X u X --> X X X == 0 - if (Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_UGE) - return new ICmpInst(ICmpInst::ICMP_ULT, X, ConstantExpr::getNeg(CI)); + if (Pred == Predicate::ICMP_UGT || Pred == Predicate::ICMP_UGE) + return new ICmpInst(Predicate::ICMP_ULT, X, ConstantExpr::getNeg(CI)); unsigned BitWidth = CI->getType()->getPrimitiveSizeInBits(); ConstantInt *SMax = ConstantInt::get(X->getContext(), @@ -1161,8 +1156,8 @@ // (X+MINSINT) X >s (MAXSINT-MINSINT) --> X >s -1 // (X+ -2) X >s (MAXSINT- -2) --> X >s 126 // (X+ -1) X >s (MAXSINT- -1) --> X != 127 - if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SLE) - return new ICmpInst(ICmpInst::ICMP_SGT, X, ConstantExpr::getSub(SMax, CI)); + if (Pred == Predicate::ICMP_SLT || Pred == Predicate::ICMP_SLE) + return new ICmpInst(Predicate::ICMP_SGT, X, ConstantExpr::getSub(SMax, CI)); // (X+ 1) >s X --> X X != 127 // (X+ 2) >s X --> X X s X --> X X s X --> X X == -128 - assert(Pred == ICmpInst::ICMP_SGT || Pred == ICmpInst::ICMP_SGE); + assert(Pred == Predicate::ICMP_SGT || Pred == Predicate::ICMP_SGE); Constant *C = Builder->getInt(CI->getValue()-1); - return new ICmpInst(ICmpInst::ICMP_SLT, X, ConstantExpr::getSub(SMax, C)); + return new ICmpInst(Predicate::ICMP_SLT, X, ConstantExpr::getSub(SMax, C)); } /// Fold "icmp pred, ([su]div X, DivRHS), CmpRHS" where DivRHS and CmpRHS are @@ -1217,7 +1212,7 @@ ConstantExpr::getUDiv(Prod, DivRHS)) != CmpRHS; // Get the ICmp opcode - ICmpInst::Predicate Pred = ICI.getPredicate(); + Predicate Pred = ICI.getPredicate(); // If the division is known to be exact, then there is no remainder from the // divide, so the covered range size is unit, otherwise it is the divisor. @@ -1286,50 +1281,50 @@ } // Dividing by a negative swaps the condition. LT <-> GT - Pred = ICmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); } Value *X = DivI->getOperand(0); - switch (Pred) { + switch (Pred.getKind()) { default: llvm_unreachable("Unhandled icmp opcode!"); - case ICmpInst::ICMP_EQ: + case Predicate::ICMP_EQ: if (LoOverflow && HiOverflow) return replaceInstUsesWith(ICI, Builder->getFalse()); if (HiOverflow) - return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE : - ICmpInst::ICMP_UGE, X, LoBound); + return new ICmpInst( + DivIsSigned ? Predicate::ICMP_SGE : Predicate::ICMP_UGE, X, LoBound); if (LoOverflow) - return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT : - ICmpInst::ICMP_ULT, X, HiBound); + return new ICmpInst( + DivIsSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT, X, HiBound); return replaceInstUsesWith(ICI, InsertRangeTest(X, LoBound, HiBound, DivIsSigned, true)); - case ICmpInst::ICMP_NE: + case Predicate::ICMP_NE: if (LoOverflow && HiOverflow) return replaceInstUsesWith(ICI, Builder->getTrue()); if (HiOverflow) - return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT : - ICmpInst::ICMP_ULT, X, LoBound); + return new ICmpInst( + DivIsSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT, X, LoBound); if (LoOverflow) - return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE : - ICmpInst::ICMP_UGE, X, HiBound); + return new ICmpInst( + DivIsSigned ? Predicate::ICMP_SGE : Predicate::ICMP_UGE, X, HiBound); return replaceInstUsesWith(ICI, InsertRangeTest(X, LoBound, HiBound, DivIsSigned, false)); - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_ULT: + case Predicate::ICMP_SLT: if (LoOverflow == +1) // Low bound is greater than input range. return replaceInstUsesWith(ICI, Builder->getTrue()); if (LoOverflow == -1) // Low bound is less than input range. return replaceInstUsesWith(ICI, Builder->getFalse()); return new ICmpInst(Pred, X, LoBound); - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_UGT: + case Predicate::ICMP_SGT: if (HiOverflow == +1) // High bound greater than input range. return replaceInstUsesWith(ICI, Builder->getFalse()); if (HiOverflow == -1) // High bound less than input range. return replaceInstUsesWith(ICI, Builder->getTrue()); - if (Pred == ICmpInst::ICMP_UGT) - return new ICmpInst(ICmpInst::ICMP_UGE, X, HiBound); - return new ICmpInst(ICmpInst::ICMP_SGE, X, HiBound); + if (Pred == Predicate::ICMP_UGT) + return new ICmpInst(Predicate::ICMP_UGE, X, HiBound); + return new ICmpInst(Predicate::ICMP_SGE, X, HiBound); } } @@ -1396,7 +1391,7 @@ Comp = Comp.ashr(ShAmtVal); if (Comp != CmpRHSV) { // Comparing against a bit that we know is zero. - bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE; + bool IsICMP_NE = ICI.getPredicate() == Predicate::ICMP_NE; Constant *Cst = Builder->getInt1(IsICMP_NE); return replaceInstUsesWith(ICI, Cst); } @@ -1428,14 +1423,14 @@ assert(I.isEquality() && "Cannot fold icmp gt/lt"); auto getConstant = [&I, this](bool IsTrue) { - if (I.getPredicate() == I.ICMP_NE) + if (I.getPredicate() == Predicate::ICMP_NE) IsTrue = !IsTrue; return replaceInstUsesWith(I, ConstantInt::get(I.getType(), IsTrue)); }; - auto getICmp = [&I](CmpInst::Predicate Pred, Value *LHS, Value *RHS) { - if (I.getPredicate() == I.ICMP_NE) - Pred = CmpInst::getInversePredicate(Pred); + auto getICmp = [&I](Predicate Pred, Value *LHS, Value *RHS) { + if (I.getPredicate() == Predicate::ICMP_NE) + Pred = Pred.getInverse(); return new ICmpInst(Pred, LHS, RHS); }; @@ -1457,11 +1452,12 @@ if (!AP1) // 'A' must be large enough to shift out the highest set bit. - return getICmp(I.ICMP_UGT, A, + return getICmp(Predicate::ICMP_UGT, A, ConstantInt::get(A->getType(), AP2.logBase2())); if (AP1 == AP2) - return getICmp(I.ICMP_EQ, A, ConstantInt::getNullValue(A->getType())); + return getICmp(Predicate::ICMP_EQ, A, + ConstantInt::getNullValue(A->getType())); int Shift; if (IsAShr && AP1.isNegative()) @@ -1474,10 +1470,13 @@ // There are multiple solutions if we are comparing against -1 and the LHS // of the ashr is not a power of two. if (AP1.isAllOnesValue() && !AP2.isPowerOf2()) - return getICmp(I.ICMP_UGE, A, ConstantInt::get(A->getType(), Shift)); - return getICmp(I.ICMP_EQ, A, ConstantInt::get(A->getType(), Shift)); + return getICmp(Predicate::ICMP_UGE, A, + ConstantInt::get(A->getType(), Shift)); + return getICmp(Predicate::ICMP_EQ, A, + ConstantInt::get(A->getType(), Shift)); } else if (AP1 == AP2.lshr(Shift)) { - return getICmp(I.ICMP_EQ, A, ConstantInt::get(A->getType(), Shift)); + return getICmp(Predicate::ICMP_EQ, A, + ConstantInt::get(A->getType(), Shift)); } } // Shifting const2 will never be equal to const1. @@ -1492,14 +1491,14 @@ assert(I.isEquality() && "Cannot fold icmp gt/lt"); auto getConstant = [&I, this](bool IsTrue) { - if (I.getPredicate() == I.ICMP_NE) + if (I.getPredicate() == Predicate::ICMP_NE) IsTrue = !IsTrue; return replaceInstUsesWith(I, ConstantInt::get(I.getType(), IsTrue)); }; - auto getICmp = [&I](CmpInst::Predicate Pred, Value *LHS, Value *RHS) { - if (I.getPredicate() == I.ICMP_NE) - Pred = CmpInst::getInversePredicate(Pred); + auto getICmp = [&I](Predicate Pred, Value *LHS, Value *RHS) { + if (I.getPredicate() == Predicate::ICMP_NE) + Pred = Pred.getInverse(); return new ICmpInst(Pred, LHS, RHS); }; @@ -1513,17 +1512,20 @@ unsigned AP2TrailingZeros = AP2.countTrailingZeros(); if (!AP1 && AP2TrailingZeros != 0) - return getICmp(I.ICMP_UGE, A, - ConstantInt::get(A->getType(), AP2.getBitWidth() - AP2TrailingZeros)); + return getICmp( + Predicate::ICMP_UGE, A, + ConstantInt::get(A->getType(), AP2.getBitWidth() - AP2TrailingZeros)); if (AP1 == AP2) - return getICmp(I.ICMP_EQ, A, ConstantInt::getNullValue(A->getType())); + return getICmp(Predicate::ICMP_EQ, A, + ConstantInt::getNullValue(A->getType())); // Get the distance between the lowest bits that are set. int Shift = AP1.countTrailingZeros() - AP2TrailingZeros; if (Shift > 0 && AP2.shl(Shift) == AP1) - return getICmp(I.ICMP_EQ, A, ConstantInt::get(A->getType(), Shift)); + return getICmp(Predicate::ICMP_EQ, A, + ConstantInt::get(A->getType(), Shift)); // Shifting const2 will never be equal to const1. return getConstant(false); @@ -1540,9 +1542,9 @@ if (RHS->isOne() && RHSV.getBitWidth() > 1) { // icmp slt trunc(signum(V)) 1 --> icmp slt V, 1 Value *V = nullptr; - if (ICI.getPredicate() == ICmpInst::ICMP_SLT && + if (ICI.getPredicate() == Predicate::ICMP_SLT && match(LHSI->getOperand(0), m_Signum(m_Value(V)))) - return new ICmpInst(ICmpInst::ICMP_SLT, V, + return new ICmpInst(Predicate::ICMP_SLT, V, ConstantInt::get(V->getType(), 1)); } if (ICI.isEquality() && LHSI->hasOneUse()) { @@ -1568,8 +1570,9 @@ if (ConstantInt *XorCst = dyn_cast(LHSI->getOperand(1))) { // If this is a comparison that tests the signbit (X < 0) or (x > -1), // fold the xor. - if ((ICI.getPredicate() == ICmpInst::ICMP_SLT && RHSV == 0) || - (ICI.getPredicate() == ICmpInst::ICMP_SGT && RHSV.isAllOnesValue())) { + if ((ICI.getPredicate() == Predicate::ICMP_SLT && RHSV == 0) || + (ICI.getPredicate() == Predicate::ICMP_SGT && + RHSV.isAllOnesValue())) { Value *CompareVal = LHSI->getOperand(0); // If the sign bit of the XorCst is not set, there is no change to @@ -1581,26 +1584,23 @@ } // Was the old condition true if the operand is positive? - bool isTrueIfPositive = ICI.getPredicate() == ICmpInst::ICMP_SGT; + bool isTrueIfPositive = ICI.getPredicate() == Predicate::ICMP_SGT; // If so, the new one isn't. isTrueIfPositive ^= true; if (isTrueIfPositive) - return new ICmpInst(ICmpInst::ICMP_SGT, CompareVal, - SubOne(RHS)); + return new ICmpInst(Predicate::ICMP_SGT, CompareVal, SubOne(RHS)); else - return new ICmpInst(ICmpInst::ICMP_SLT, CompareVal, - AddOne(RHS)); + return new ICmpInst(Predicate::ICMP_SLT, CompareVal, AddOne(RHS)); } if (LHSI->hasOneUse()) { // (icmp u/s (xor A SignBit), C) -> (icmp s/u A, (xor C SignBit)) if (!ICI.isEquality() && XorCst->getValue().isSignBit()) { const APInt &SignBit = XorCst->getValue(); - ICmpInst::Predicate Pred = ICI.isSigned() - ? ICI.getUnsignedPredicate() - : ICI.getSignedPredicate(); + Predicate Pred = ICI.isSigned() ? ICI.getUnsignedPredicate() + : ICI.getSignedPredicate(); return new ICmpInst(Pred, LHSI->getOperand(0), Builder->getInt(RHSV ^ SignBit)); } @@ -1608,10 +1608,9 @@ // (icmp u/s (xor A ~SignBit), C) -> (icmp s/u (xor C ~SignBit), A) if (!ICI.isEquality() && XorCst->isMaxValue(true)) { const APInt &NotSignBit = XorCst->getValue(); - ICmpInst::Predicate Pred = ICI.isSigned() - ? ICI.getUnsignedPredicate() - : ICI.getSignedPredicate(); - Pred = ICI.getSwappedPredicate(Pred); + Predicate Pred = ICI.isSigned() ? ICI.getUnsignedPredicate() + : ICI.getSignedPredicate(); + Pred = Pred.getSwapped(); return new ICmpInst(Pred, LHSI->getOperand(0), Builder->getInt(RHSV ^ NotSignBit)); } @@ -1619,15 +1618,15 @@ // (icmp ugt (xor X, C), ~C) -> (icmp ult X, C) // iff -C is a power of 2 - if (ICI.getPredicate() == ICmpInst::ICMP_UGT && + if (ICI.getPredicate() == Predicate::ICMP_UGT && XorCst->getValue() == ~RHSV && (RHSV + 1).isPowerOf2()) - return new ICmpInst(ICmpInst::ICMP_ULT, LHSI->getOperand(0), XorCst); + return new ICmpInst(Predicate::ICMP_ULT, LHSI->getOperand(0), XorCst); // (icmp ult (xor X, C), -C) -> (icmp uge X, C) // iff -C is a power of 2 - if (ICI.getPredicate() == ICmpInst::ICMP_ULT && + if (ICI.getPredicate() == Predicate::ICMP_ULT && XorCst->getValue() == -RHSV && RHSV.isPowerOf2()) - return new ICmpInst(ICmpInst::ICMP_UGE, LHSI->getOperand(0), XorCst); + return new ICmpInst(Predicate::ICMP_UGE, LHSI->getOperand(0), XorCst); } break; case Instruction::And: // (icmp pred (and X, AndCst), RHS) @@ -1731,9 +1730,9 @@ // If we shifted bits out, the fold is not going to work out. // As a special case, check to see if this means that the // result is always true or false now. - if (ICI.getPredicate() == ICmpInst::ICMP_EQ) + if (ICI.getPredicate() == Predicate::ICMP_EQ) return replaceInstUsesWith(ICI, Builder->getFalse()); - if (ICI.getPredicate() == ICmpInst::ICMP_NE) + if (ICI.getPredicate() == Predicate::ICMP_NE) return replaceInstUsesWith(ICI, Builder->getTrue()); } else { ICI.setOperand(1, NewCst); @@ -1817,11 +1816,11 @@ // Replace ((X & AndCst) > RHSV) with ((X & AndCst) != 0), if any // bit set in (X & AndCst) will produce a result greater than RHSV. - if (ICI.getPredicate() == ICmpInst::ICMP_UGT) { + if (ICI.getPredicate() == Predicate::ICMP_UGT) { unsigned NTZ = AndCst->getValue().countTrailingZeros(); if ((NTZ < AndCst->getBitWidth()) && APInt::getOneBitSet(AndCst->getBitWidth(), NTZ).ugt(RHSV)) - return new ICmpInst(ICmpInst::ICMP_NE, LHSI, + return new ICmpInst(Predicate::ICMP_NE, LHSI, Constant::getNullValue(RHS->getType())); } } @@ -1843,10 +1842,10 @@ // X & -C != -C -> X <= u ~C // iff C is a power of 2 if (ICI.isEquality() && RHS == LHSI->getOperand(1) && (-RHSV).isPowerOf2()) - return new ICmpInst( - ICI.getPredicate() == ICmpInst::ICMP_EQ ? ICmpInst::ICMP_UGT - : ICmpInst::ICMP_ULE, - LHSI->getOperand(0), SubOne(RHS)); + return new ICmpInst(ICI.getPredicate() == Predicate::ICMP_EQ + ? Predicate::ICMP_UGT + : Predicate::ICMP_ULE, + LHSI->getOperand(0), SubOne(RHS)); // (icmp eq (and %A, C), 0) -> (icmp sgt (trunc %A), -1) // iff C is a power of 2 @@ -1857,9 +1856,9 @@ if (ExactLogBase2 != -1 && DL.isLegalInteger(ExactLogBase2 + 1)) { Type *NTy = IntegerType::get(ICI.getContext(), ExactLogBase2 + 1); Value *Trunc = Builder->CreateTrunc(LHSI->getOperand(0), NTy); - return new ICmpInst(ICI.getPredicate() == ICmpInst::ICMP_EQ - ? ICmpInst::ICMP_SGE - : ICmpInst::ICMP_SLT, + return new ICmpInst(ICI.getPredicate() == Predicate::ICMP_EQ + ? Predicate::ICMP_SGE + : Predicate::ICMP_SLT, Trunc, Constant::getNullValue(NTy)); } } @@ -1870,9 +1869,9 @@ if (RHS->isOne()) { // icmp slt signum(V) 1 --> icmp slt V, 1 Value *V = nullptr; - if (ICI.getPredicate() == ICmpInst::ICMP_SLT && + if (ICI.getPredicate() == Predicate::ICMP_SLT && match(LHSI, m_Signum(m_Value(V)))) - return new ICmpInst(ICmpInst::ICMP_SLT, V, + return new ICmpInst(Predicate::ICMP_SLT, V, ConstantInt::get(V->getType(), 1)); } @@ -1887,7 +1886,7 @@ Value *ICIQ = Builder->CreateICmp(ICI.getPredicate(), Q, Constant::getNullValue(Q->getType())); Instruction *Op; - if (ICI.getPredicate() == ICmpInst::ICMP_EQ) + if (ICI.getPredicate() == Predicate::ICMP_EQ) Op = BinaryOperator::CreateAnd(ICIP, ICIQ); else Op = BinaryOperator::CreateOr(ICIP, ICIQ); @@ -1902,11 +1901,10 @@ // If this is a signed comparison to 0 and the mul is sign preserving, // use the mul LHS operand instead. - ICmpInst::Predicate pred = ICI.getPredicate(); + Predicate pred = ICI.getPredicate(); if (isSignTest(pred, RHS) && !Val->isZero() && cast(LHSI)->hasNoSignedWrap()) - return new ICmpInst(Val->isNegative() ? - ICmpInst::getSwappedPredicate(pred) : pred, + return new ICmpInst(Val->isNegative() ? pred.getSwapped() : pred, LHSI->getOperand(0), Constant::getNullValue(RHS->getType())); @@ -1921,27 +1919,27 @@ // (1 << X) pred P2 -> X pred Log2(P2) if (match(LHSI, m_Shl(m_One(), m_Value(X)))) { bool RHSVIsPowerOf2 = RHSV.isPowerOf2(); - ICmpInst::Predicate Pred = ICI.getPredicate(); + Predicate Pred = ICI.getPredicate(); if (ICI.isUnsigned()) { if (!RHSVIsPowerOf2) { // (1 << X) < 30 -> X <= 4 // (1 << X) <= 30 -> X <= 4 // (1 << X) >= 30 -> X > 4 // (1 << X) > 30 -> X > 4 - if (Pred == ICmpInst::ICMP_ULT) - Pred = ICmpInst::ICMP_ULE; - else if (Pred == ICmpInst::ICMP_UGE) - Pred = ICmpInst::ICMP_UGT; + if (Pred == Predicate::ICMP_ULT) + Pred = Predicate::ICMP_ULE; + else if (Pred == Predicate::ICMP_UGE) + Pred = Predicate::ICMP_UGT; } unsigned RHSLog2 = RHSV.logBase2(); // (1 << X) >= 2147483648 -> X >= 31 -> X == 31 // (1 << X) < 2147483648 -> X < 31 -> X != 31 if (RHSLog2 == TypeBits-1) { - if (Pred == ICmpInst::ICMP_UGE) - Pred = ICmpInst::ICMP_EQ; - else if (Pred == ICmpInst::ICMP_ULT) - Pred = ICmpInst::ICMP_NE; + if (Pred == Predicate::ICMP_UGE) + Pred = Predicate::ICMP_EQ; + else if (Pred == Predicate::ICMP_ULT) + Pred = Predicate::ICMP_NE; } return new ICmpInst(Pred, X, @@ -1949,26 +1947,30 @@ } else if (ICI.isSigned()) { if (RHSV.isAllOnesValue()) { // (1 << X) <= -1 -> X == 31 - if (Pred == ICmpInst::ICMP_SLE) - return new ICmpInst(ICmpInst::ICMP_EQ, X, - ConstantInt::get(RHS->getType(), TypeBits-1)); + if (Pred == Predicate::ICMP_SLE) + return new ICmpInst( + Predicate::ICMP_EQ, X, + ConstantInt::get(RHS->getType(), TypeBits - 1)); // (1 << X) > -1 -> X != 31 - if (Pred == ICmpInst::ICMP_SGT) - return new ICmpInst(ICmpInst::ICMP_NE, X, - ConstantInt::get(RHS->getType(), TypeBits-1)); + if (Pred == Predicate::ICMP_SGT) + return new ICmpInst( + Predicate::ICMP_NE, X, + ConstantInt::get(RHS->getType(), TypeBits - 1)); } else if (!RHSV) { // (1 << X) < 0 -> X == 31 // (1 << X) <= 0 -> X == 31 - if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SLE) - return new ICmpInst(ICmpInst::ICMP_EQ, X, - ConstantInt::get(RHS->getType(), TypeBits-1)); + if (Pred == Predicate::ICMP_SLT || Pred == Predicate::ICMP_SLE) + return new ICmpInst( + Predicate::ICMP_EQ, X, + ConstantInt::get(RHS->getType(), TypeBits - 1)); // (1 << X) >= 0 -> X != 31 // (1 << X) > 0 -> X != 31 - if (Pred == ICmpInst::ICMP_SGT || Pred == ICmpInst::ICMP_SGE) - return new ICmpInst(ICmpInst::ICMP_NE, X, - ConstantInt::get(RHS->getType(), TypeBits-1)); + if (Pred == Predicate::ICMP_SGT || Pred == Predicate::ICMP_SGE) + return new ICmpInst( + Predicate::ICMP_NE, X, + ConstantInt::get(RHS->getType(), TypeBits - 1)); } } else if (ICI.isEquality()) { if (RHSVIsPowerOf2) @@ -1992,7 +1994,7 @@ ConstantExpr::getShl(ConstantExpr::getLShr(RHS, ShAmt), ShAmt); if (Comp != RHS) {// Comparing against a bit that we know is zero. - bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE; + bool IsICMP_NE = ICI.getPredicate() == Predicate::ICMP_NE; Constant *Cst = Builder->getInt1(IsICMP_NE); return replaceInstUsesWith(ICI, Cst); } @@ -2024,7 +2026,7 @@ // If this is a signed comparison to 0 and the shift is sign preserving, // use the shift LHS operand instead. - ICmpInst::Predicate pred = ICI.getPredicate(); + Predicate pred = ICI.getPredicate(); if (isSignTest(pred, RHS) && cast(LHSI)->hasNoSignedWrap()) return new ICmpInst(pred, @@ -2041,7 +2043,8 @@ TypeBits-ShAmt->getZExtValue()-1)); Value *And = Builder->CreateAnd(LHSI->getOperand(0), Mask, LHSI->getName()+".mask"); - return new ICmpInst(TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ, + return new ICmpInst(TrueIfSigned ? Predicate::ICMP_NE + : Predicate::ICMP_EQ, And, Constant::getNullValue(And->getType())); } @@ -2091,16 +2094,16 @@ const APInt &C2 = DivLHS->getValue(); assert(C2 != 0 && "udiv 0, X should have been simplified already."); // (icmp ugt (udiv C2, X), C1) -> (icmp ule X, C2/(C1+1)) - if (ICI.getPredicate() == ICmpInst::ICMP_UGT) { + if (ICI.getPredicate() == Predicate::ICMP_UGT) { assert(!C1.isMaxValue() && "icmp ugt X, UINT_MAX should have been simplified already."); - return new ICmpInst(ICmpInst::ICMP_ULE, X, + return new ICmpInst(Predicate::ICMP_ULE, X, ConstantInt::get(X->getType(), C2.udiv(C1 + 1))); } // (icmp ult (udiv C2, X), C1) -> (icmp ugt X, C2/C1) - if (ICI.getPredicate() == ICmpInst::ICMP_ULT) { + if (ICI.getPredicate() == Predicate::ICMP_ULT) { assert(C1 != 0 && "icmp ult X, 0 should have been simplified already."); - return new ICmpInst(ICmpInst::ICMP_UGT, X, + return new ICmpInst(Predicate::ICMP_UGT, X, ConstantInt::get(X->getType(), C2.udiv(C1))); } } @@ -2126,18 +2129,18 @@ // C1-X (X|(C2-1)) == C1 // iff C1 & (C2-1) == C2-1 // C2 is a power of 2 - if (ICI.getPredicate() == ICmpInst::ICMP_ULT && LHSI->hasOneUse() && + if (ICI.getPredicate() == Predicate::ICMP_ULT && LHSI->hasOneUse() && RHSV.isPowerOf2() && (LHSV & (RHSV - 1)) == (RHSV - 1)) - return new ICmpInst(ICmpInst::ICMP_EQ, + return new ICmpInst(Predicate::ICMP_EQ, Builder->CreateOr(LHSI->getOperand(1), RHSV - 1), LHSC); // C1-X >u C2 -> (X|C2) != C1 // iff C1 & C2 == C2 // C2+1 is a power of 2 - if (ICI.getPredicate() == ICmpInst::ICMP_UGT && LHSI->hasOneUse() && + if (ICI.getPredicate() == Predicate::ICMP_UGT && LHSI->hasOneUse() && (RHSV + 1).isPowerOf2() && (LHSV & RHSV) == RHSV) - return new ICmpInst(ICmpInst::ICMP_NE, + return new ICmpInst(Predicate::ICMP_NE, Builder->CreateOr(LHSI->getOperand(1), RHSV), LHSC); break; } @@ -2154,18 +2157,18 @@ if (ICI.isSigned()) { if (CR.getLower().isSignBit()) { - return new ICmpInst(ICmpInst::ICMP_SLT, LHSI->getOperand(0), + return new ICmpInst(Predicate::ICMP_SLT, LHSI->getOperand(0), Builder->getInt(CR.getUpper())); } else if (CR.getUpper().isSignBit()) { - return new ICmpInst(ICmpInst::ICMP_SGE, LHSI->getOperand(0), + return new ICmpInst(Predicate::ICMP_SGE, LHSI->getOperand(0), Builder->getInt(CR.getLower())); } } else { if (CR.getLower().isMinValue()) { - return new ICmpInst(ICmpInst::ICMP_ULT, LHSI->getOperand(0), + return new ICmpInst(Predicate::ICMP_ULT, LHSI->getOperand(0), Builder->getInt(CR.getUpper())); } else if (CR.getUpper().isMinValue()) { - return new ICmpInst(ICmpInst::ICMP_UGE, LHSI->getOperand(0), + return new ICmpInst(Predicate::ICMP_UGE, LHSI->getOperand(0), Builder->getInt(CR.getLower())); } } @@ -2173,18 +2176,18 @@ // X-C1 (X & -C2) == C1 // iff C1 & (C2-1) == 0 // C2 is a power of 2 - if (ICI.getPredicate() == ICmpInst::ICMP_ULT && LHSI->hasOneUse() && + if (ICI.getPredicate() == Predicate::ICMP_ULT && LHSI->hasOneUse() && RHSV.isPowerOf2() && (LHSV & (RHSV - 1)) == 0) - return new ICmpInst(ICmpInst::ICMP_EQ, + return new ICmpInst(Predicate::ICMP_EQ, Builder->CreateAnd(LHSI->getOperand(0), -RHSV), ConstantExpr::getNeg(LHSC)); // X-C1 >u C2 -> (X & ~C2) != C1 // iff C1 & C2 == 0 // C2+1 is a power of 2 - if (ICI.getPredicate() == ICmpInst::ICMP_UGT && LHSI->hasOneUse() && + if (ICI.getPredicate() == Predicate::ICMP_UGT && LHSI->hasOneUse() && (RHSV + 1).isPowerOf2() && (LHSV & RHSV) == 0) - return new ICmpInst(ICmpInst::ICMP_NE, + return new ICmpInst(Predicate::ICMP_NE, Builder->CreateAnd(LHSI->getOperand(0), ~RHSV), ConstantExpr::getNeg(LHSC)); } @@ -2206,7 +2209,7 @@ return nullptr; Constant *RHS = cast(ICI.getOperand(1)); - bool isICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE; + bool isICMP_NE = ICI.getPredicate() == Predicate::ICMP_NE; Value *BOp0 = BO->getOperand(0), *BOp1 = BO->getOperand(1); switch (BO->getOpcode()) { @@ -2287,7 +2290,7 @@ if (match(BOp1, m_APInt(BOC))) { // If we have ((X & C) == C), turn it into ((X & C) != 0). if (RHSV == BOC && RHSV->isPowerOf2()) - return new ICmpInst(isICMP_NE ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_NE, + return new ICmpInst(isICMP_NE ? Predicate::ICMP_EQ : Predicate::ICMP_NE, BO, Constant::getNullValue(RHS->getType())); // Don't perform the following transforms if the AND has multiple uses @@ -2297,16 +2300,14 @@ // Replace (and X, (1 << size(X)-1) != 0) with x s< 0 if (BOC->isSignBit()) { Constant *Zero = Constant::getNullValue(BOp0->getType()); - ICmpInst::Predicate Pred = - isICMP_NE ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE; + Predicate Pred = isICMP_NE ? Predicate::ICMP_SLT : Predicate::ICMP_SGE; return new ICmpInst(Pred, BOp0, Zero); } // ((X & ~7) == 0) --> X < 8 if (*RHSV == 0 && (~(*BOC) + 1).isPowerOf2()) { Constant *NegBOC = ConstantExpr::getNeg(cast(BOp1)); - ICmpInst::Predicate Pred = - isICMP_NE ? ICmpInst::ICMP_UGE : ICmpInst::ICMP_ULT; + Predicate Pred = isICMP_NE ? Predicate::ICMP_UGE : Predicate::ICMP_ULT; return new ICmpInst(Pred, BOp0, NegBOC); } } @@ -2327,8 +2328,7 @@ case Instruction::UDiv: if (*RHSV == 0) { // (icmp eq/ne (udiv A, B), 0) -> (icmp ugt/ule i32 B, A) - ICmpInst::Predicate Pred = - isICMP_NE ? ICmpInst::ICMP_ULE : ICmpInst::ICMP_UGT; + Predicate Pred = isICMP_NE ? Predicate::ICMP_ULE : Predicate::ICMP_UGT; return new ICmpInst(Pred, BOp1, BOp0); } break; @@ -2490,10 +2490,11 @@ Value *Result = Builder->CreateICmpSGT(LHSCIOp, NegOne, ICmp.getName()); // Finally, return the value computed. - if (ICmp.getPredicate() == ICmpInst::ICMP_ULT) + if (ICmp.getPredicate() == Predicate::ICMP_ULT) return replaceInstUsesWith(ICmp, Result); - assert(ICmp.getPredicate() == ICmpInst::ICMP_UGT && "ICmp should be folded!"); + assert(ICmp.getPredicate() == Predicate::ICMP_UGT && + "ICmp should be folded!"); return BinaryOperator::CreateNot(Result); } @@ -2756,9 +2757,9 @@ } // Recognize patterns - switch (I.getPredicate()) { - case ICmpInst::ICMP_EQ: - case ICmpInst::ICMP_NE: + switch (I.getPredicate().getKind()) { + case Predicate::ICMP_EQ: + case Predicate::ICMP_NE: // Recognize pattern: // mulval = mul(zext A, zext B) // cmp eq/neq mulval, zext trunc mulval @@ -2787,7 +2788,7 @@ } return nullptr; - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_UGT: // Recognize pattern: // mulval = mul(zext A, zext B) // cmp ugt mulval, max @@ -2799,7 +2800,7 @@ } return nullptr; - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: // Recognize pattern: // mulval = mul(zext A, zext B) // cmp uge mulval, max+1 @@ -2810,7 +2811,7 @@ } return nullptr; - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULE: // Recognize pattern: // mulval = mul(zext A, zext B) // cmp ule mulval, max @@ -2822,7 +2823,7 @@ } return nullptr; - case ICmpInst::ICMP_ULT: + case Predicate::ICMP_ULT: // Recognize pattern: // mulval = mul(zext A, zext B) // cmp ule mulval, max + 1 @@ -2886,20 +2887,20 @@ // The original icmp gets replaced with the overflow value, maybe inverted // depending on predicate. bool Inverse = false; - switch (I.getPredicate()) { - case ICmpInst::ICMP_NE: + switch (I.getPredicate().getKind()) { + case Predicate::ICMP_NE: break; - case ICmpInst::ICMP_EQ: + case Predicate::ICMP_EQ: Inverse = true; break; - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGT: + case Predicate::ICMP_UGE: if (I.getOperand(0) == MulVal) break; Inverse = true; break; - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULT: + case Predicate::ICMP_ULE: if (I.getOperand(1) == MulVal) break; Inverse = true; @@ -2927,12 +2928,12 @@ if (!CI) return APInt::getAllOnesValue(BitWidth); const APInt &RHS = CI->getValue(); - switch (I.getPredicate()) { + switch (I.getPredicate().getKind()) { // For a UGT comparison, we don't care about any bits that // correspond to the trailing ones of the comparand. The value of these // bits doesn't impact the outcome of the comparison, because any value // greater than the RHS must differ in a bit higher than these due to carry. - case ICmpInst::ICMP_UGT: { + case Predicate::ICMP_UGT: { unsigned trailingOnes = RHS.countTrailingOnes(); APInt lowBitsSet = APInt::getLowBitsSet(BitWidth, trailingOnes); return ~lowBitsSet; @@ -2940,7 +2941,7 @@ // Similarly, for a ULT comparison, we don't care about the trailing zeros. // Any value less than the RHS must differ in a higher bit because of carries. - case ICmpInst::ICMP_ULT: { + case Predicate::ICMP_ULT: { unsigned trailingZeros = RHS.countTrailingZeros(); APInt lowBitsSet = APInt::getLowBitsSet(BitWidth, trailingZeros); return ~lowBitsSet; @@ -3082,7 +3083,8 @@ const ICmpInst *Icmp, const unsigned SIOpd) { assert((SIOpd == 1 || SIOpd == 2) && "Invalid select operand!"); - if (isChainSelectCmpBranch(SI) && Icmp->getPredicate() == ICmpInst::ICMP_EQ) { + if (isChainSelectCmpBranch(SI) && + Icmp->getPredicate() == Predicate::ICMP_EQ) { BasicBlock *Succ = SI->getParent()->getTerminator()->getSuccessor(1); // The check for the unique predecessor is not the best that can be // done. But it protects efficiently against cases like when SI's @@ -3106,9 +3108,9 @@ /// it into the appropriate icmp lt or icmp gt instruction. This transform /// allows them to be folded in visitICmpInst. static ICmpInst *canonicalizeCmpWithConstant(ICmpInst &I) { - ICmpInst::Predicate Pred = I.getPredicate(); - if (Pred != ICmpInst::ICMP_SLE && Pred != ICmpInst::ICMP_SGE && - Pred != ICmpInst::ICMP_ULE && Pred != ICmpInst::ICMP_UGE) + Predicate Pred = I.getPredicate(); + if (!Pred.isOneOf(Predicate::ICMP_SLE, Predicate::ICMP_SGE, + Predicate::ICMP_ULE, Predicate::ICMP_UGE)) return nullptr; Value *Op0 = I.getOperand(0); @@ -3123,7 +3125,7 @@ // handle the edge cases. Type *Op1Type = Op1->getType(); bool IsSigned = I.isSigned(); - bool IsLE = (Pred == ICmpInst::ICMP_SLE || Pred == ICmpInst::ICMP_ULE); + bool IsLE = (Pred == Predicate::ICMP_SLE || Pred == Predicate::ICMP_ULE); auto *CI = dyn_cast(Op1C); if (CI) { // A <= MAX -> TRUE ; A >= MIN -> TRUE @@ -3154,8 +3156,8 @@ // Increment or decrement the constant and set the new comparison predicate: // ULE -> ULT ; UGE -> UGT ; SLE -> SLT ; SGE -> SGT Constant *OneOrNegOne = ConstantInt::get(Op1Type, IsLE ? 1 : -1, true); - CmpInst::Predicate NewPred = IsLE ? ICmpInst::ICMP_ULT: ICmpInst::ICMP_UGT; - NewPred = IsSigned ? ICmpInst::getSignedPredicate(NewPred) : NewPred; + Predicate NewPred = IsLE ? Predicate::ICMP_ULT : Predicate::ICMP_UGT; + NewPred = IsSigned ? NewPred.getSigned() : NewPred; return new ICmpInst(NewPred, Op0, ConstantExpr::getAdd(Op1C, OneOrNegOne)); } @@ -3181,7 +3183,7 @@ // comparing -val or val with non-zero is the same as just comparing val // ie, abs(val) != 0 -> val != 0 - if (I.getPredicate() == ICmpInst::ICMP_NE && match(Op1, m_Zero())) { + if (I.getPredicate() == Predicate::ICMP_NE && match(Op1, m_Zero())) { Value *Cond, *SelectTrue, *SelectFalse; if (match(Op0, m_Select(m_Value(Cond), m_Value(SelectTrue), m_Value(SelectFalse)))) { @@ -3200,40 +3202,40 @@ // icmp's with boolean values can always be turned into bitwise operations if (Ty->getScalarType()->isIntegerTy(1)) { - switch (I.getPredicate()) { + switch (I.getPredicate().getKind()) { default: llvm_unreachable("Invalid icmp instruction!"); - case ICmpInst::ICMP_EQ: { // icmp eq i1 A, B -> ~(A^B) + case Predicate::ICMP_EQ: { // icmp eq i1 A, B -> ~(A^B) Value *Xor = Builder->CreateXor(Op0, Op1, I.getName() + "tmp"); return BinaryOperator::CreateNot(Xor); } - case ICmpInst::ICMP_NE: // icmp ne i1 A, B -> A^B + case Predicate::ICMP_NE: // icmp ne i1 A, B -> A^B return BinaryOperator::CreateXor(Op0, Op1); - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_UGT: std::swap(Op0, Op1); // Change icmp ugt -> icmp ult // FALL THROUGH - case ICmpInst::ICMP_ULT:{ // icmp ult i1 A, B -> ~A & B + case Predicate::ICMP_ULT: { // icmp ult i1 A, B -> ~A & B Value *Not = Builder->CreateNot(Op0, I.getName() + "tmp"); return BinaryOperator::CreateAnd(Not, Op1); } - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: std::swap(Op0, Op1); // Change icmp sgt -> icmp slt // FALL THROUGH - case ICmpInst::ICMP_SLT: { // icmp slt i1 A, B -> A & ~B + case Predicate::ICMP_SLT: { // icmp slt i1 A, B -> A & ~B Value *Not = Builder->CreateNot(Op1, I.getName() + "tmp"); return BinaryOperator::CreateAnd(Not, Op0); } - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: std::swap(Op0, Op1); // Change icmp uge -> icmp ule // FALL THROUGH - case ICmpInst::ICMP_ULE: { // icmp ule i1 A, B -> ~A | B + case Predicate::ICMP_ULE: { // icmp ule i1 A, B -> ~A | B Value *Not = Builder->CreateNot(Op0, I.getName() + "tmp"); return BinaryOperator::CreateOr(Not, Op1); } - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: std::swap(Op0, Op1); // Change icmp sge -> icmp sle // FALL THROUGH - case ICmpInst::ICMP_SLE: { // icmp sle i1 A, B -> A | ~B + case Predicate::ICMP_SLE: { // icmp sle i1 A, B -> A | ~B Value *Not = Builder->CreateNot(Op1, I.getName() + "tmp"); return BinaryOperator::CreateOr(Not, Op0); } @@ -3269,14 +3271,14 @@ // if (sum+128 >u 255) ... -> llvm.sadd.with.overflow.i8 { ConstantInt *CI2; // I = icmp ugt (add (add A, B), CI2), CI - if (I.getPredicate() == ICmpInst::ICMP_UGT && + if (I.getPredicate() == Predicate::ICMP_UGT && match(Op0, m_Add(m_Add(m_Value(A), m_Value(B)), m_ConstantInt(CI2)))) if (Instruction *Res = ProcessUGT_ADDCST_ADD(I, A, B, CI2, CI, *this)) return Res; } // (icmp sgt smin(PosA, B) 0) -> (icmp sgt B 0) - if (CI->isZero() && I.getPredicate() == ICmpInst::ICMP_SGT) + if (CI->isZero() && I.getPredicate() == Predicate::ICMP_SGT) if (auto *SI = dyn_cast(Op0)) { SelectPatternResult SPR = matchSelectPattern(SI, A, B); if (SPR.Flavor == SPF_SMIN) { @@ -3297,24 +3299,24 @@ return new ICmpInst(I.getPredicate(), A, B); // (icmp sgt (sub nsw A B), -1) -> (icmp sge A, B) - if (I.getPredicate() == ICmpInst::ICMP_SGT && CI->isAllOnesValue() && + if (I.getPredicate() == Predicate::ICMP_SGT && CI->isAllOnesValue() && match(Op0, m_NSWSub(m_Value(A), m_Value(B)))) - return new ICmpInst(ICmpInst::ICMP_SGE, A, B); + return new ICmpInst(Predicate::ICMP_SGE, A, B); // (icmp sgt (sub nsw A B), 0) -> (icmp sgt A, B) - if (I.getPredicate() == ICmpInst::ICMP_SGT && CI->isZero() && + if (I.getPredicate() == Predicate::ICMP_SGT && CI->isZero() && match(Op0, m_NSWSub(m_Value(A), m_Value(B)))) - return new ICmpInst(ICmpInst::ICMP_SGT, A, B); + return new ICmpInst(Predicate::ICMP_SGT, A, B); // (icmp slt (sub nsw A B), 0) -> (icmp slt A, B) - if (I.getPredicate() == ICmpInst::ICMP_SLT && CI->isZero() && + if (I.getPredicate() == Predicate::ICMP_SLT && CI->isZero() && match(Op0, m_NSWSub(m_Value(A), m_Value(B)))) - return new ICmpInst(ICmpInst::ICMP_SLT, A, B); + return new ICmpInst(Predicate::ICMP_SLT, A, B); // (icmp slt (sub nsw A B), 1) -> (icmp sle A, B) - if (I.getPredicate() == ICmpInst::ICMP_SLT && CI->isOne() && + if (I.getPredicate() == Predicate::ICMP_SLT && CI->isOne() && match(Op0, m_NSWSub(m_Value(A), m_Value(B)))) - return new ICmpInst(ICmpInst::ICMP_SLE, A, B); + return new ICmpInst(Predicate::ICMP_SLE, A, B); } if (I.isEquality()) { @@ -3341,7 +3343,7 @@ BasicBlock *Parent = I.getParent(); BasicBlock *Dom = Parent->getSinglePredecessor(); auto *BI = Dom ? dyn_cast(Dom->getTerminator()) : nullptr; - ICmpInst::Predicate Pred; + Predicate Pred; BasicBlock *TrueBB, *FalseBB; ConstantInt *CI2; if (BI && match(BI, m_Br(m_ICmp(Pred, m_Specific(Op0), m_ConstantInt(CI2)), @@ -3352,8 +3354,8 @@ ConstantRange DominatingCR = (Parent == TrueBB) ? ConstantRange::makeExactICmpRegion(Pred, CI2->getValue()) - : ConstantRange::makeExactICmpRegion( - CmpInst::getInversePredicate(Pred), CI2->getValue()); + : ConstantRange::makeExactICmpRegion(Pred.getInverse(), + CI2->getValue()); ConstantRange Intersection = DominatingCR.intersectWith(CR); ConstantRange Difference = DominatingCR.difference(CR); if (Intersection.isEmptySet()) @@ -3367,9 +3369,9 @@ // than compare and branch instruction. if (!isBranchOnSignBitCheck(I, isSignBit) && !I.isEquality()) { if (auto *AI = Intersection.getSingleElement()) - return new ICmpInst(ICmpInst::ICMP_EQ, Op0, Builder->getInt(*AI)); + return new ICmpInst(Predicate::ICMP_EQ, Op0, Builder->getInt(*AI)); if (auto *AD = Difference.getSingleElement()) - return new ICmpInst(ICmpInst::ICMP_NE, Op0, Builder->getInt(*AD)); + return new ICmpInst(Predicate::ICMP_NE, Op0, Builder->getInt(*AD)); } } } @@ -3418,9 +3420,9 @@ // Based on the range information we know about the LHS, see if we can // simplify this comparison. For example, (x&4) < 8 is always true. - switch (I.getPredicate()) { + switch (I.getPredicate().getKind()) { default: llvm_unreachable("Unknown icmp opcode!"); - case ICmpInst::ICMP_EQ: { + case Predicate::ICMP_EQ: { if (Op0Max.ult(Op1Min) || Op0Min.ugt(Op1Max)) return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())); @@ -3444,11 +3446,11 @@ APInt ValToCheck = Op0KnownZeroInverted; if (ValToCheck.isPowerOf2()) { unsigned CmpVal = ValToCheck.countTrailingZeros(); - return new ICmpInst(ICmpInst::ICMP_NE, X, + return new ICmpInst(Predicate::ICMP_NE, X, ConstantInt::get(X->getType(), CmpVal)); } else if ((++ValToCheck).isPowerOf2()) { unsigned CmpVal = ValToCheck.countTrailingZeros() - 1; - return new ICmpInst(ICmpInst::ICMP_UGT, X, + return new ICmpInst(Predicate::ICMP_UGT, X, ConstantInt::get(X->getType(), CmpVal)); } } @@ -3458,13 +3460,13 @@ const APInt *CI; if (Op0KnownZeroInverted == 1 && match(LHS, m_LShr(m_Power2(CI), m_Value(X)))) - return new ICmpInst(ICmpInst::ICMP_NE, X, - ConstantInt::get(X->getType(), - CI->countTrailingZeros())); + return new ICmpInst( + Predicate::ICMP_NE, X, + ConstantInt::get(X->getType(), CI->countTrailingZeros())); } break; } - case ICmpInst::ICMP_NE: { + case Predicate::ICMP_NE: { if (Op0Max.ult(Op1Min) || Op0Min.ugt(Op1Max)) return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); @@ -3488,11 +3490,11 @@ APInt ValToCheck = Op0KnownZeroInverted; if (ValToCheck.isPowerOf2()) { unsigned CmpVal = ValToCheck.countTrailingZeros(); - return new ICmpInst(ICmpInst::ICMP_EQ, X, + return new ICmpInst(Predicate::ICMP_EQ, X, ConstantInt::get(X->getType(), CmpVal)); } else if ((++ValToCheck).isPowerOf2()) { unsigned CmpVal = ValToCheck.countTrailingZeros(); - return new ICmpInst(ICmpInst::ICMP_ULT, X, + return new ICmpInst(Predicate::ICMP_ULT, X, ConstantInt::get(X->getType(), CmpVal)); } } @@ -3502,98 +3504,98 @@ const APInt *CI; if (Op0KnownZeroInverted == 1 && match(LHS, m_LShr(m_Power2(CI), m_Value(X)))) - return new ICmpInst(ICmpInst::ICMP_EQ, X, - ConstantInt::get(X->getType(), - CI->countTrailingZeros())); + return new ICmpInst( + Predicate::ICMP_EQ, X, + ConstantInt::get(X->getType(), CI->countTrailingZeros())); } break; } - case ICmpInst::ICMP_ULT: + case Predicate::ICMP_ULT: if (Op0Max.ult(Op1Min)) // A true if max(A) < min(B) return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); if (Op0Min.uge(Op1Max)) // A false if min(A) >= max(B) return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())); if (Op1Min == Op0Max) // A A != B if max(A) == min(B) - return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1); + return new ICmpInst(Predicate::ICMP_NE, Op0, Op1); if (ConstantInt *CI = dyn_cast(Op1)) { if (Op1Max == Op0Min+1) // A A == C-1 if min(A)+1 == C - return new ICmpInst(ICmpInst::ICMP_EQ, Op0, - Builder->getInt(CI->getValue()-1)); + return new ICmpInst(Predicate::ICMP_EQ, Op0, + Builder->getInt(CI->getValue() - 1)); // (x (x >s -1) -> true if sign bit clear if (CI->isMinValue(true)) - return new ICmpInst(ICmpInst::ICMP_SGT, Op0, - Constant::getAllOnesValue(Op0->getType())); + return new ICmpInst(Predicate::ICMP_SGT, Op0, + Constant::getAllOnesValue(Op0->getType())); } break; - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_UGT: if (Op0Min.ugt(Op1Max)) // A >u B -> true if min(A) > max(B) return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); if (Op0Max.ule(Op1Min)) // A >u B -> false if max(A) <= max(B) return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())); if (Op1Max == Op0Min) // A >u B -> A != B if min(A) == max(B) - return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1); + return new ICmpInst(Predicate::ICMP_NE, Op0, Op1); if (ConstantInt *CI = dyn_cast(Op1)) { if (Op1Min == Op0Max-1) // A >u C -> A == C+1 if max(a)-1 == C - return new ICmpInst(ICmpInst::ICMP_EQ, Op0, - Builder->getInt(CI->getValue()+1)); + return new ICmpInst(Predicate::ICMP_EQ, Op0, + Builder->getInt(CI->getValue() + 1)); // (x >u 2147483647) -> (x true if sign bit set if (CI->isMaxValue(true)) - return new ICmpInst(ICmpInst::ICMP_SLT, Op0, + return new ICmpInst(Predicate::ICMP_SLT, Op0, Constant::getNullValue(Op0->getType())); } break; - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: if (Op0Max.slt(Op1Min)) // A true if max(A) < min(C) return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); if (Op0Min.sge(Op1Max)) // A false if min(A) >= max(C) return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())); if (Op1Min == Op0Max) // A A != B if max(A) == min(B) - return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1); + return new ICmpInst(Predicate::ICMP_NE, Op0, Op1); if (ConstantInt *CI = dyn_cast(Op1)) { if (Op1Max == Op0Min+1) // A A == C-1 if min(A)+1 == C - return new ICmpInst(ICmpInst::ICMP_EQ, Op0, - Builder->getInt(CI->getValue()-1)); + return new ICmpInst(Predicate::ICMP_EQ, Op0, + Builder->getInt(CI->getValue() - 1)); } break; - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: if (Op0Min.sgt(Op1Max)) // A >s B -> true if min(A) > max(B) return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); if (Op0Max.sle(Op1Min)) // A >s B -> false if max(A) <= min(B) return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())); if (Op1Max == Op0Min) // A >s B -> A != B if min(A) == max(B) - return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1); + return new ICmpInst(Predicate::ICMP_NE, Op0, Op1); if (ConstantInt *CI = dyn_cast(Op1)) { if (Op1Min == Op0Max-1) // A >s C -> A == C+1 if max(A)-1 == C - return new ICmpInst(ICmpInst::ICMP_EQ, Op0, - Builder->getInt(CI->getValue()+1)); + return new ICmpInst(Predicate::ICMP_EQ, Op0, + Builder->getInt(CI->getValue() + 1)); } break; - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: assert(!isa(Op1) && "ICMP_SGE with ConstantInt not folded!"); if (Op0Min.sge(Op1Max)) // A >=s B -> true if min(A) >= max(B) return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); if (Op0Max.slt(Op1Min)) // A >=s B -> false if max(A) < min(B) return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())); break; - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLE: assert(!isa(Op1) && "ICMP_SLE with ConstantInt not folded!"); if (Op0Max.sle(Op1Min)) // A <=s B -> true if max(A) <= min(B) return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); if (Op0Min.sgt(Op1Max)) // A <=s B -> false if min(A) > max(B) return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())); break; - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: assert(!isa(Op1) && "ICMP_UGE with ConstantInt not folded!"); if (Op0Min.uge(Op1Max)) // A >=u B -> true if min(A) >= max(B) return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); if (Op0Max.ult(Op1Min)) // A >=u B -> false if max(A) < min(B) return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())); break; - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULE: assert(!isa(Op1) && "ICMP_ULE with ConstantInt not folded!"); if (Op0Max.ule(Op1Min)) // A <=u B -> true if max(A) <= min(B) return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); @@ -3738,8 +3740,8 @@ if (Instruction *NI = foldGEPICmp(GEP, Op1, I.getPredicate(), I)) return NI; if (GEPOperator *GEP = dyn_cast(Op1)) - if (Instruction *NI = foldGEPICmp(GEP, Op0, - ICmpInst::getSwappedPredicate(I.getPredicate()), I)) + if (Instruction *NI = + foldGEPICmp(GEP, Op0, I.getPredicate().getSwapped(), I)) return NI; // Try to optimize equality comparisons against alloca-based pointers. @@ -3797,16 +3799,16 @@ BinaryOperator *BO0 = dyn_cast(Op0); BinaryOperator *BO1 = dyn_cast(Op1); if (BO0 || BO1) { - CmpInst::Predicate Pred = I.getPredicate(); + Predicate Pred = I.getPredicate(); bool NoOp0WrapProblem = false, NoOp1WrapProblem = false; if (BO0 && isa(BO0)) - NoOp0WrapProblem = ICmpInst::isEquality(Pred) || - (CmpInst::isUnsigned(Pred) && BO0->hasNoUnsignedWrap()) || - (CmpInst::isSigned(Pred) && BO0->hasNoSignedWrap()); + NoOp0WrapProblem = Pred.isEquality() || + (Pred.isUnsigned() && BO0->hasNoUnsignedWrap()) || + (Pred.isSigned() && BO0->hasNoSignedWrap()); if (BO1 && isa(BO1)) - NoOp1WrapProblem = ICmpInst::isEquality(Pred) || - (CmpInst::isUnsigned(Pred) && BO1->hasNoUnsignedWrap()) || - (CmpInst::isSigned(Pred) && BO1->hasNoSignedWrap()); + NoOp1WrapProblem = Pred.isEquality() || + (Pred.isUnsigned() && BO1->hasNoUnsignedWrap()) || + (Pred.isSigned() && BO1->hasNoSignedWrap()); // Analyze the case when either Op0 or Op1 is an add instruction. // Op0 = A + B (or A and B are null); Op1 = C + D (or C and D are null). @@ -3821,7 +3823,7 @@ } // icmp (X+cst) < 0 --> X < -cst - if (NoOp0WrapProblem && ICmpInst::isSigned(Pred) && match(Op1, m_Zero())) + if (NoOp0WrapProblem && Pred.isSigned() && match(Op1, m_Zero())) if (ConstantInt *RHSC = dyn_cast_or_null(B)) if (!RHSC->isMinValue(/*isSigned=*/true)) return new ICmpInst(Pred, A, ConstantExpr::getNeg(RHSC)); @@ -3865,44 +3867,44 @@ } // icmp slt (X + -1), Y -> icmp sle X, Y - if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SLT && + if (A && NoOp0WrapProblem && Pred == Predicate::ICMP_SLT && match(B, m_AllOnes())) - return new ICmpInst(CmpInst::ICMP_SLE, A, Op1); + return new ICmpInst(Predicate::ICMP_SLE, A, Op1); // icmp sge (X + -1), Y -> icmp sgt X, Y - if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SGE && + if (A && NoOp0WrapProblem && Pred == Predicate::ICMP_SGE && match(B, m_AllOnes())) - return new ICmpInst(CmpInst::ICMP_SGT, A, Op1); + return new ICmpInst(Predicate::ICMP_SGT, A, Op1); // icmp sle (X + 1), Y -> icmp slt X, Y - if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SLE && + if (A && NoOp0WrapProblem && Pred == Predicate::ICMP_SLE && match(B, m_One())) - return new ICmpInst(CmpInst::ICMP_SLT, A, Op1); + return new ICmpInst(Predicate::ICMP_SLT, A, Op1); // icmp sgt (X + 1), Y -> icmp sge X, Y - if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SGT && + if (A && NoOp0WrapProblem && Pred == Predicate::ICMP_SGT && match(B, m_One())) - return new ICmpInst(CmpInst::ICMP_SGE, A, Op1); + return new ICmpInst(Predicate::ICMP_SGE, A, Op1); // icmp sgt X, (Y + -1) -> icmp sge X, Y - if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SGT && + if (C && NoOp1WrapProblem && Pred == Predicate::ICMP_SGT && match(D, m_AllOnes())) - return new ICmpInst(CmpInst::ICMP_SGE, Op0, C); + return new ICmpInst(Predicate::ICMP_SGE, Op0, C); // icmp sle X, (Y + -1) -> icmp slt X, Y - if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SLE && + if (C && NoOp1WrapProblem && Pred == Predicate::ICMP_SLE && match(D, m_AllOnes())) - return new ICmpInst(CmpInst::ICMP_SLT, Op0, C); + return new ICmpInst(Predicate::ICMP_SLT, Op0, C); // icmp sge X, (Y + 1) -> icmp sgt X, Y - if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SGE && + if (C && NoOp1WrapProblem && Pred == Predicate::ICMP_SGE && match(D, m_One())) - return new ICmpInst(CmpInst::ICMP_SGT, Op0, C); + return new ICmpInst(Predicate::ICMP_SGT, Op0, C); // icmp slt X, (Y + 1) -> icmp sle X, Y - if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SLT && + if (C && NoOp1WrapProblem && Pred == Predicate::ICMP_SLT && match(D, m_One())) - return new ICmpInst(CmpInst::ICMP_SLE, Op0, C); + return new ICmpInst(Predicate::ICMP_SLE, Op0, C); // if C1 has greater magnitude than C2: // icmp (X + C1), (Y + C2) -> icmp (X + C3), Y @@ -3969,7 +3971,7 @@ return new ICmpInst(Pred, D, B); // icmp (0-X) < cst --> x > -cst - if (NoOp0WrapProblem && ICmpInst::isSigned(Pred)) { + if (NoOp0WrapProblem && Pred.isSigned()) { Value *X; if (match(BO0, m_Neg(m_Value(X)))) if (ConstantInt *RHSC = dyn_cast(Op1)) @@ -3990,20 +3992,21 @@ if (SRem) { // We don't check hasOneUse to avoid increasing register pressure because // the value we use is the same value this instruction was already using. - switch (SRem == BO0 ? ICmpInst::getSwappedPredicate(Pred) : Pred) { - default: break; - case ICmpInst::ICMP_EQ: - return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())); - case ICmpInst::ICMP_NE: - return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); - case ICmpInst::ICMP_SGT: - case ICmpInst::ICMP_SGE: - return new ICmpInst(ICmpInst::ICMP_SGT, SRem->getOperand(1), - Constant::getAllOnesValue(SRem->getType())); - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_SLE: - return new ICmpInst(ICmpInst::ICMP_SLT, SRem->getOperand(1), - Constant::getNullValue(SRem->getType())); + switch ((SRem == BO0 ? Pred.getSwapped() : Pred).getKind()) { + default: + break; + case Predicate::ICMP_EQ: + return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType())); + case Predicate::ICMP_NE: + return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType())); + case Predicate::ICMP_SGT: + case Predicate::ICMP_SGE: + return new ICmpInst(Predicate::ICMP_SGT, SRem->getOperand(1), + Constant::getAllOnesValue(SRem->getType())); + case Predicate::ICMP_SLT: + case Predicate::ICMP_SLE: + return new ICmpInst(Predicate::ICMP_SLT, SRem->getOperand(1), + Constant::getNullValue(SRem->getType())); } } @@ -4021,18 +4024,16 @@ // icmp u/s (a ^ signbit), (b ^ signbit) --> icmp s/u a, b if (ConstantInt *CI = dyn_cast(BO0->getOperand(1))) { if (CI->getValue().isSignBit()) { - ICmpInst::Predicate Pred = I.isSigned() - ? I.getUnsignedPredicate() - : I.getSignedPredicate(); + Predicate Pred = I.isSigned() ? I.getUnsignedPredicate() + : I.getSignedPredicate(); return new ICmpInst(Pred, BO0->getOperand(0), BO1->getOperand(0)); } if (BO0->getOpcode() == Instruction::Xor && CI->isMaxValue(true)) { - ICmpInst::Predicate Pred = I.isSigned() - ? I.getUnsignedPredicate() - : I.getSignedPredicate(); - Pred = I.getSwappedPredicate(Pred); + Predicate Pred = I.isSigned() ? I.getUnsignedPredicate() + : I.getSignedPredicate(); + Pred = Pred.getSwapped(); return new ICmpInst(Pred, BO0->getOperand(0), BO1->getOperand(0)); } @@ -4087,9 +4088,9 @@ auto BitwiseAnd = m_CombineOr(m_And(m_Value(), LSubOne), m_And(LSubOne, m_Value())); - if (match(BO0, BitwiseAnd) && I.getPredicate() == ICmpInst::ICMP_ULT) { + if (match(BO0, BitwiseAnd) && I.getPredicate() == Predicate::ICMP_ULT) { auto *Zero = Constant::getNullValue(BO0->getType()); - return new ICmpInst(ICmpInst::ICMP_NE, Op1, Zero); + return new ICmpInst(Predicate::ICMP_NE, Op1, Zero); } } } @@ -4223,9 +4224,9 @@ unsigned TypeBits = Cst1->getBitWidth(); unsigned ShAmt = (unsigned)Cst1->getLimitedValue(TypeBits); if (ShAmt < TypeBits && ShAmt != 0) { - ICmpInst::Predicate Pred = I.getPredicate() == ICmpInst::ICMP_NE - ? ICmpInst::ICMP_UGE - : ICmpInst::ICMP_ULT; + Predicate Pred = I.getPredicate() == Predicate::ICMP_NE + ? Predicate::ICMP_UGE + : Predicate::ICMP_ULT; Value *Xor = Builder->CreateXor(A, B, I.getName() + ".unshifted"); APInt CmpVal = APInt::getOneBitSet(TypeBits, ShAmt); return new ICmpInst(Pred, Xor, Builder->getInt(CmpVal)); @@ -4282,7 +4283,7 @@ // N.B. This transform is only valid when the 'cmpxchg' is not permitted to // spuriously fail. In those cases, the old value may equal the expected // value but it is possible for the swap to not occur. - if (I.getPredicate() == ICmpInst::ICMP_EQ) + if (I.getPredicate() == Predicate::ICMP_EQ) if (auto *EVI = dyn_cast(Op0)) if (auto *ACXI = dyn_cast(EVI->getAggregateOperand())) if (EVI->getIndices()[0] == 0 && ACXI->getCompareOperand() == Op1 && @@ -4318,7 +4319,7 @@ bool LHSUnsigned = isa(LHSI); if (I.isEquality()) { - FCmpInst::Predicate P = I.getPredicate(); + Predicate P = I.getPredicate(); bool IsExact = false; APSInt RHSCvt(IntTy->getBitWidth(), LHSUnsigned); RHS.convertToInteger(RHSCvt, APFloat::rmNearestTiesToEven, &IsExact); @@ -4330,10 +4331,10 @@ APFloat RHSRoundInt(RHS); RHSRoundInt.roundToIntegral(APFloat::rmNearestTiesToEven); if (RHS.compare(RHSRoundInt) != APFloat::cmpEqual) { - if (P == FCmpInst::FCMP_OEQ || P == FCmpInst::FCMP_UEQ) + if (P == Predicate::FCMP_OEQ || P == Predicate::FCMP_UEQ) return replaceInstUsesWith(I, Builder->getFalse()); - assert(P == FCmpInst::FCMP_ONE || P == FCmpInst::FCMP_UNE); + assert(P == Predicate::FCMP_ONE || P == Predicate::FCMP_UNE); return replaceInstUsesWith(I, Builder->getTrue()); } } @@ -4372,36 +4373,36 @@ // not a NAN (it would have been previously simplified). assert(!RHS.isNaN() && "NaN comparison not already folded!"); - ICmpInst::Predicate Pred; - switch (I.getPredicate()) { + Predicate Pred; + switch (I.getPredicate().getKind()) { default: llvm_unreachable("Unexpected predicate!"); - case FCmpInst::FCMP_UEQ: - case FCmpInst::FCMP_OEQ: - Pred = ICmpInst::ICMP_EQ; + case Predicate::FCMP_UEQ: + case Predicate::FCMP_OEQ: + Pred = Predicate::ICMP_EQ; break; - case FCmpInst::FCMP_UGT: - case FCmpInst::FCMP_OGT: - Pred = LHSUnsigned ? ICmpInst::ICMP_UGT : ICmpInst::ICMP_SGT; + case Predicate::FCMP_UGT: + case Predicate::FCMP_OGT: + Pred = LHSUnsigned ? Predicate::ICMP_UGT : Predicate::ICMP_SGT; break; - case FCmpInst::FCMP_UGE: - case FCmpInst::FCMP_OGE: - Pred = LHSUnsigned ? ICmpInst::ICMP_UGE : ICmpInst::ICMP_SGE; + case Predicate::FCMP_UGE: + case Predicate::FCMP_OGE: + Pred = LHSUnsigned ? Predicate::ICMP_UGE : Predicate::ICMP_SGE; break; - case FCmpInst::FCMP_ULT: - case FCmpInst::FCMP_OLT: - Pred = LHSUnsigned ? ICmpInst::ICMP_ULT : ICmpInst::ICMP_SLT; + case Predicate::FCMP_ULT: + case Predicate::FCMP_OLT: + Pred = LHSUnsigned ? Predicate::ICMP_ULT : Predicate::ICMP_SLT; break; - case FCmpInst::FCMP_ULE: - case FCmpInst::FCMP_OLE: - Pred = LHSUnsigned ? ICmpInst::ICMP_ULE : ICmpInst::ICMP_SLE; + case Predicate::FCMP_ULE: + case Predicate::FCMP_OLE: + Pred = LHSUnsigned ? Predicate::ICMP_ULE : Predicate::ICMP_SLE; break; - case FCmpInst::FCMP_UNE: - case FCmpInst::FCMP_ONE: - Pred = ICmpInst::ICMP_NE; + case Predicate::FCMP_UNE: + case Predicate::FCMP_ONE: + Pred = Predicate::ICMP_NE; break; - case FCmpInst::FCMP_ORD: + case Predicate::FCMP_ORD: return replaceInstUsesWith(I, Builder->getTrue()); - case FCmpInst::FCMP_UNO: + case Predicate::FCMP_UNO: return replaceInstUsesWith(I, Builder->getFalse()); } @@ -4418,8 +4419,8 @@ SMax.convertFromAPInt(APInt::getSignedMaxValue(IntWidth), true, APFloat::rmNearestTiesToEven); if (SMax.compare(RHS) == APFloat::cmpLessThan) { // smax < 13123.0 - if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_SLT || - Pred == ICmpInst::ICMP_SLE) + if (Pred.isOneOf(Predicate::ICMP_NE, Predicate::ICMP_SLT, + Predicate::ICMP_SLE)) return replaceInstUsesWith(I, Builder->getTrue()); return replaceInstUsesWith(I, Builder->getFalse()); } @@ -4430,8 +4431,8 @@ UMax.convertFromAPInt(APInt::getMaxValue(IntWidth), false, APFloat::rmNearestTiesToEven); if (UMax.compare(RHS) == APFloat::cmpLessThan) { // umax < 13123.0 - if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_ULT || - Pred == ICmpInst::ICMP_ULE) + if (Pred.isOneOf(Predicate::ICMP_NE, Predicate::ICMP_ULT, + Predicate::ICMP_ULE)) return replaceInstUsesWith(I, Builder->getTrue()); return replaceInstUsesWith(I, Builder->getFalse()); } @@ -4443,8 +4444,8 @@ SMin.convertFromAPInt(APInt::getSignedMinValue(IntWidth), true, APFloat::rmNearestTiesToEven); if (SMin.compare(RHS) == APFloat::cmpGreaterThan) { // smin > 12312.0 - if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_SGT || - Pred == ICmpInst::ICMP_SGE) + if (Pred.isOneOf(Predicate::ICMP_NE, Predicate::ICMP_SGT, + Predicate::ICMP_SGE)) return replaceInstUsesWith(I, Builder->getTrue()); return replaceInstUsesWith(I, Builder->getFalse()); } @@ -4454,8 +4455,8 @@ SMin.convertFromAPInt(APInt::getMinValue(IntWidth), true, APFloat::rmNearestTiesToEven); if (SMin.compare(RHS) == APFloat::cmpGreaterThan) { // umin > 12312.0 - if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_UGT || - Pred == ICmpInst::ICMP_UGE) + if (Pred.isOneOf(Predicate::ICMP_NE, Predicate::ICMP_UGT, + Predicate::ICMP_UGE)) return replaceInstUsesWith(I, Builder->getTrue()); return replaceInstUsesWith(I, Builder->getFalse()); } @@ -4476,61 +4477,61 @@ // If we had a comparison against a fractional value, we have to adjust // the compare predicate and sometimes the value. RHSC is rounded towards // zero at this point. - switch (Pred) { + switch (Pred.getKind()) { default: llvm_unreachable("Unexpected integer comparison!"); - case ICmpInst::ICMP_NE: // (float)int != 4.4 --> true + case Predicate::ICMP_NE: // (float)int != 4.4 --> true return replaceInstUsesWith(I, Builder->getTrue()); - case ICmpInst::ICMP_EQ: // (float)int == 4.4 --> false + case Predicate::ICMP_EQ: // (float)int == 4.4 --> false return replaceInstUsesWith(I, Builder->getFalse()); - case ICmpInst::ICMP_ULE: + case Predicate::ICMP_ULE: // (float)int <= 4.4 --> int <= 4 // (float)int <= -4.4 --> false if (RHS.isNegative()) return replaceInstUsesWith(I, Builder->getFalse()); break; - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLE: // (float)int <= 4.4 --> int <= 4 // (float)int <= -4.4 --> int < -4 if (RHS.isNegative()) - Pred = ICmpInst::ICMP_SLT; + Pred = Predicate::ICMP_SLT; break; - case ICmpInst::ICMP_ULT: + case Predicate::ICMP_ULT: // (float)int < -4.4 --> false // (float)int < 4.4 --> int <= 4 if (RHS.isNegative()) return replaceInstUsesWith(I, Builder->getFalse()); - Pred = ICmpInst::ICMP_ULE; + Pred = Predicate::ICMP_ULE; break; - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: // (float)int < -4.4 --> int < -4 // (float)int < 4.4 --> int <= 4 if (!RHS.isNegative()) - Pred = ICmpInst::ICMP_SLE; + Pred = Predicate::ICMP_SLE; break; - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_UGT: // (float)int > 4.4 --> int > 4 // (float)int > -4.4 --> true if (RHS.isNegative()) return replaceInstUsesWith(I, Builder->getTrue()); break; - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: // (float)int > 4.4 --> int > 4 // (float)int > -4.4 --> int >= -4 if (RHS.isNegative()) - Pred = ICmpInst::ICMP_SGE; + Pred = Predicate::ICMP_SGE; break; - case ICmpInst::ICMP_UGE: + case Predicate::ICMP_UGE: // (float)int >= -4.4 --> true // (float)int >= 4.4 --> int > 4 if (RHS.isNegative()) return replaceInstUsesWith(I, Builder->getTrue()); - Pred = ICmpInst::ICMP_UGT; + Pred = Predicate::ICMP_UGT; break; - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: // (float)int >= -4.4 --> int >= -4 // (float)int >= 4.4 --> int > 4 if (!RHS.isNegative()) - Pred = ICmpInst::ICMP_SGT; + Pred = Predicate::ICMP_SGT; break; } } @@ -4560,23 +4561,23 @@ // Simplify 'fcmp pred X, X' if (Op0 == Op1) { - switch (I.getPredicate()) { + switch (I.getPredicate().getKind()) { default: llvm_unreachable("Unknown predicate!"); - case FCmpInst::FCMP_UNO: // True if unordered: isnan(X) | isnan(Y) - case FCmpInst::FCMP_ULT: // True if unordered or less than - case FCmpInst::FCMP_UGT: // True if unordered or greater than - case FCmpInst::FCMP_UNE: // True if unordered or not equal + case Predicate::FCMP_UNO: // True if unordered: isnan(X) | isnan(Y) + case Predicate::FCMP_ULT: // True if unordered or less than + case Predicate::FCMP_UGT: // True if unordered or greater than + case Predicate::FCMP_UNE: // True if unordered or not equal // Canonicalize these to be 'fcmp uno %X, 0.0'. - I.setPredicate(FCmpInst::FCMP_UNO); + I.setPredicate(Predicate::FCMP_UNO); I.setOperand(1, Constant::getNullValue(Op0->getType())); return &I; - case FCmpInst::FCMP_ORD: // True if ordered (no nans) - case FCmpInst::FCMP_OEQ: // True if ordered and equal - case FCmpInst::FCMP_OGE: // True if ordered and greater than or equal - case FCmpInst::FCMP_OLE: // True if ordered and less than or equal + case Predicate::FCMP_ORD: // True if ordered (no nans) + case Predicate::FCMP_OEQ: // True if ordered and equal + case Predicate::FCMP_OGE: // True if ordered and greater than or equal + case Predicate::FCMP_OLE: // True if ordered and less than or equal // Canonicalize these to be 'fcmp ord %X, 0.0'. - I.setPredicate(FCmpInst::FCMP_ORD); + I.setPredicate(Predicate::FCMP_ORD); I.setOperand(1, Constant::getNullValue(Op0->getType())); return &I; } @@ -4680,27 +4681,27 @@ break; // Various optimization for fabs compared with zero. - switch (I.getPredicate()) { + switch (I.getPredicate().getKind()) { default: break; // fabs(x) < 0 --> false - case FCmpInst::FCMP_OLT: + case Predicate::FCMP_OLT: llvm_unreachable("handled by SimplifyFCmpInst"); // fabs(x) > 0 --> x != 0 - case FCmpInst::FCMP_OGT: - return new FCmpInst(FCmpInst::FCMP_ONE, CI->getArgOperand(0), RHSC); + case Predicate::FCMP_OGT: + return new FCmpInst(Predicate::FCMP_ONE, CI->getArgOperand(0), RHSC); // fabs(x) <= 0 --> x == 0 - case FCmpInst::FCMP_OLE: - return new FCmpInst(FCmpInst::FCMP_OEQ, CI->getArgOperand(0), RHSC); + case Predicate::FCMP_OLE: + return new FCmpInst(Predicate::FCMP_OEQ, CI->getArgOperand(0), RHSC); // fabs(x) >= 0 --> !isnan(x) - case FCmpInst::FCMP_OGE: - return new FCmpInst(FCmpInst::FCMP_ORD, CI->getArgOperand(0), RHSC); + case Predicate::FCMP_OGE: + return new FCmpInst(Predicate::FCMP_ORD, CI->getArgOperand(0), RHSC); // fabs(x) == 0 --> x == 0 // fabs(x) != 0 --> x != 0 - case FCmpInst::FCMP_OEQ: - case FCmpInst::FCMP_UEQ: - case FCmpInst::FCMP_ONE: - case FCmpInst::FCMP_UNE: + case Predicate::FCMP_OEQ: + case Predicate::FCMP_UEQ: + case Predicate::FCMP_ONE: + case Predicate::FCMP_UNE: return new FCmpInst(I.getPredicate(), CI->getArgOperand(0), RHSC); } } Index: lib/Transforms/InstCombine/InstCombineInternal.h =================================================================== --- lib/Transforms/InstCombine/InstCombineInternal.h +++ lib/Transforms/InstCombine/InstCombineInternal.h @@ -539,8 +539,8 @@ Instruction *FoldPHIArgLoadIntoPHI(PHINode &PN); Instruction *FoldPHIArgZextsIntoPHI(PHINode &PN); - Instruction *foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, - ICmpInst::Predicate Cond, Instruction &I); + Instruction *foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, Predicate Cond, + Instruction &I); Instruction *foldAllocaCmp(ICmpInst &ICI, AllocaInst *Alloca, Value *Other); Instruction *foldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, GlobalVariable *GV, CmpInst &ICI, @@ -556,7 +556,7 @@ Instruction *foldICmpCstShlConst(ICmpInst &I, Value *Op, Value *A, ConstantInt *CI1, ConstantInt *CI2); Instruction *foldICmpAddOpConst(Instruction &ICI, Value *X, ConstantInt *CI, - ICmpInst::Predicate Pred); + Predicate Pred); Instruction *foldICmpWithCastAndCast(ICmpInst &ICI); Instruction *foldICmpWithConstant(ICmpInst &ICI, Instruction *LHS, ConstantInt *RHS); Index: lib/Transforms/InstCombine/InstCombineSelect.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineSelect.cpp +++ lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -38,32 +38,32 @@ } } -static CmpInst::Predicate getCmpPredicateForMinMax(SelectPatternFlavor SPF, - bool Ordered=false) { +static Predicate getCmpPredicateForMinMax(SelectPatternFlavor SPF, + bool Ordered = false) { switch (SPF) { default: llvm_unreachable("unhandled!"); case SPF_SMIN: - return ICmpInst::ICMP_SLT; + return Predicate::ICMP_SLT; case SPF_UMIN: - return ICmpInst::ICMP_ULT; + return Predicate::ICMP_ULT; case SPF_SMAX: - return ICmpInst::ICMP_SGT; + return Predicate::ICMP_SGT; case SPF_UMAX: - return ICmpInst::ICMP_UGT; + return Predicate::ICMP_UGT; case SPF_FMINNUM: - return Ordered ? FCmpInst::FCMP_OLT : FCmpInst::FCMP_ULT; + return Ordered ? Predicate::FCMP_OLT : Predicate::FCMP_ULT; case SPF_FMAXNUM: - return Ordered ? FCmpInst::FCMP_OGT : FCmpInst::FCMP_UGT; + return Ordered ? Predicate::FCMP_OGT : Predicate::FCMP_UGT; } } static Value *generateMinMaxSelectPattern(InstCombiner::BuilderTy *Builder, SelectPatternFlavor SPF, Value *A, Value *B) { - CmpInst::Predicate Pred = getCmpPredicateForMinMax(SPF); - assert(CmpInst::isIntPredicate(Pred)); + Predicate Pred = getCmpPredicateForMinMax(SPF); + assert(Pred.isInt()); return Builder->CreateSelect(Builder->CreateICmp(Pred, A, B), A, B); } @@ -347,9 +347,9 @@ } else V = Builder->CreateZExtOrTrunc(V, Y->getType()); - ICmpInst::Predicate Pred = IC->getPredicate(); - if ((Pred == ICmpInst::ICMP_NE && OrOnFalseVal) || - (Pred == ICmpInst::ICMP_EQ && OrOnTrueVal)) + Predicate Pred = IC->getPredicate(); + if ((Pred == Predicate::ICMP_NE && OrOnFalseVal) || + (Pred == Predicate::ICMP_EQ && OrOnTrueVal)) V = Builder->CreateXor(V, *C2); return Builder->CreateOr(V, Y); @@ -369,7 +369,7 @@ /// %0 = tail call i32 @llvm.cttz.i32(i32 %x, i1 false) static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal, InstCombiner::BuilderTy *Builder) { - ICmpInst::Predicate Pred = ICI->getPredicate(); + Predicate Pred = ICI->getPredicate(); Value *CmpLHS = ICI->getOperand(0); Value *CmpRHS = ICI->getOperand(1); @@ -379,7 +379,7 @@ Value *Count = FalseVal; Value *ValueOnZero = TrueVal; - if (Pred == ICmpInst::ICMP_NE) + if (Pred == Predicate::ICMP_NE) std::swap(Count, ValueOnZero); // Skip zero extend/truncate. @@ -415,7 +415,7 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI, ICmpInst *ICI) { bool Changed = false; - ICmpInst::Predicate Pred = ICI->getPredicate(); + Predicate Pred = ICI->getPredicate(); Value *CmpLHS = ICI->getOperand(0); Value *CmpRHS = ICI->getOperand(1); Value *TrueVal = SI.getTrueValue(); @@ -426,21 +426,21 @@ // here, so make sure the select is the only user. if (ICI->hasOneUse()) if (ConstantInt *CI = dyn_cast(CmpRHS)) { - switch (Pred) { + switch (Pred.getKind()) { default: break; - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_SLT: - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_SGT: { + case Predicate::ICMP_ULT: + case Predicate::ICMP_SLT: + case Predicate::ICMP_UGT: + case Predicate::ICMP_SGT: { // These transformations only work for selects over integers. IntegerType *SelectTy = dyn_cast(SI.getType()); if (!SelectTy) break; Constant *AdjustedRHS; - if (Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_SGT) + if (Pred == Predicate::ICMP_UGT || Pred == Predicate::ICMP_SGT) AdjustedRHS = ConstantInt::get(CI->getContext(), CI->getValue() + 1); - else // (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_SLT) + else // (Pred == Predicate::ICMP_ULT || Pred == Predicate::ICMP_SLT) AdjustedRHS = ConstantInt::get(CI->getContext(), CI->getValue() - 1); // X > C ? X : C+1 --> X < C+1 ? C+1 : X @@ -489,7 +489,7 @@ } else break; - Pred = ICmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); CmpRHS = AdjustedRHS; std::swap(FalseVal, TrueVal); ICI->setPredicate(Pred); @@ -517,10 +517,10 @@ if (TrueVal->getType() == Ty) { if (ConstantInt *Cmp = dyn_cast(CmpRHS)) { ConstantInt *C1 = nullptr, *C2 = nullptr; - if (Pred == ICmpInst::ICMP_SGT && Cmp->isAllOnesValue()) { + if (Pred == Predicate::ICMP_SGT && Cmp->isAllOnesValue()) { C1 = dyn_cast(TrueVal); C2 = dyn_cast(FalseVal); - } else if (Pred == ICmpInst::ICMP_SLT && Cmp->isNullValue()) { + } else if (Pred == Predicate::ICMP_SLT && Cmp->isNullValue()) { C1 = dyn_cast(FalseVal); C2 = dyn_cast(TrueVal); } @@ -542,11 +542,11 @@ // NOTE: if we wanted to, this is where to detect integer MIN/MAX if (CmpRHS != CmpLHS && isa(CmpRHS)) { - if (CmpLHS == TrueVal && Pred == ICmpInst::ICMP_EQ) { + if (CmpLHS == TrueVal && Pred == Predicate::ICMP_EQ) { // Transform (X == C) ? X : Y -> (X == C) ? C : Y SI.setOperand(1, CmpRHS); Changed = true; - } else if (CmpLHS == FalseVal && Pred == ICmpInst::ICMP_NE) { + } else if (CmpLHS == FalseVal && Pred == Predicate::ICMP_NE) { // Transform (X != C) ? Y : X -> (X != C) ? Y : C SI.setOperand(2, CmpRHS); Changed = true; @@ -563,17 +563,16 @@ const APInt *Y, *C; bool TrueWhenUnset; bool IsBitTest = false; - if (ICmpInst::isEquality(Pred) && - match(CmpLHS, m_And(m_Value(X), m_Power2(Y))) && + if (Pred.isEquality() && match(CmpLHS, m_And(m_Value(X), m_Power2(Y))) && match(CmpRHS, m_Zero())) { IsBitTest = true; - TrueWhenUnset = Pred == ICmpInst::ICMP_EQ; - } else if (Pred == ICmpInst::ICMP_SLT && match(CmpRHS, m_Zero())) { + TrueWhenUnset = Pred == Predicate::ICMP_EQ; + } else if (Pred == Predicate::ICMP_SLT && match(CmpRHS, m_Zero())) { X = CmpLHS; Y = &MinSignedValue; IsBitTest = true; TrueWhenUnset = false; - } else if (Pred == ICmpInst::ICMP_SGT && match(CmpRHS, m_AllOnes())) { + } else if (Pred == Predicate::ICMP_SGT && match(CmpRHS, m_AllOnes())) { X = CmpLHS; Y = &MinSignedValue; IsBitTest = true; @@ -830,7 +829,7 @@ // Okay, now we know that everything is set up, we just don't know whether we // have a icmp_ne or icmp_eq and whether the true or false val is the zero. bool ShouldNotVal = !TrueVal->isZero(); - ShouldNotVal ^= IC->getPredicate() == ICmpInst::ICMP_NE; + ShouldNotVal ^= IC->getPredicate() == Predicate::ICMP_NE; if (ShouldNotVal) V = Builder->CreateXor(V, ValC); @@ -1026,7 +1025,7 @@ if (FCmpInst *FCI = dyn_cast(CondVal)) { if (FCI->getOperand(0) == TrueVal && FCI->getOperand(1) == FalseVal) { // Transform (X == Y) ? X : Y -> Y - if (FCI->getPredicate() == FCmpInst::FCMP_OEQ) { + if (FCI->getPredicate() == Predicate::FCMP_OEQ) { // This is not safe in general for floating point: // consider X== -0, Y== +0. // It becomes safe if either operand is a nonzero constant. @@ -1038,7 +1037,7 @@ return replaceInstUsesWith(SI, FalseVal); } // Transform (X une Y) ? X : Y -> X - if (FCI->getPredicate() == FCmpInst::FCMP_UNE) { + if (FCI->getPredicate() == Predicate::FCMP_UNE) { // This is not safe in general for floating point: // consider X== -0, Y== +0. // It becomes safe if either operand is a nonzero constant. @@ -1055,8 +1054,8 @@ // // e.g. // (X ugt Y) ? X : Y -> (X ole Y) ? Y : X - if (FCI->hasOneUse() && FCmpInst::isUnordered(FCI->getPredicate())) { - FCmpInst::Predicate InvPred = FCI->getInversePredicate(); + if (FCI->hasOneUse() && FCI->getPredicate().isUnordered()) { + Predicate InvPred = FCI->getInversePredicate(); IRBuilder<>::FastMathFlagGuard FMFG(*Builder); Builder->setFastMathFlags(FCI->getFastMathFlags()); Value *NewCond = Builder->CreateFCmp(InvPred, TrueVal, FalseVal, @@ -1069,7 +1068,7 @@ // NOTE: if we wanted to, this is where to detect MIN/MAX } else if (FCI->getOperand(0) == FalseVal && FCI->getOperand(1) == TrueVal){ // Transform (X == Y) ? Y : X -> X - if (FCI->getPredicate() == FCmpInst::FCMP_OEQ) { + if (FCI->getPredicate() == Predicate::FCMP_OEQ) { // This is not safe in general for floating point: // consider X== -0, Y== +0. // It becomes safe if either operand is a nonzero constant. @@ -1081,7 +1080,7 @@ return replaceInstUsesWith(SI, FalseVal); } // Transform (X une Y) ? Y : X -> Y - if (FCI->getPredicate() == FCmpInst::FCMP_UNE) { + if (FCI->getPredicate() == Predicate::FCMP_UNE) { // This is not safe in general for floating point: // consider X== -0, Y== +0. // It becomes safe if either operand is a nonzero constant. @@ -1098,8 +1097,8 @@ // // e.g. // (X ugt Y) ? X : Y -> (X ole Y) ? X : Y - if (FCI->hasOneUse() && FCmpInst::isUnordered(FCI->getPredicate())) { - FCmpInst::Predicate InvPred = FCI->getInversePredicate(); + if (FCI->hasOneUse() && FCI->getPredicate().isUnordered()) { + Predicate InvPred = FCI->getInversePredicate(); IRBuilder<>::FastMathFlagGuard FMFG(*Builder); Builder->setFastMathFlags(FCI->getFastMathFlags()); Value *NewCond = Builder->CreateFCmp(InvPred, FalseVal, TrueVal, @@ -1168,10 +1167,10 @@ // Canonicalize so that type casts are outside select patterns. if (LHS->getType()->getPrimitiveSizeInBits() != SelType->getPrimitiveSizeInBits()) { - CmpInst::Predicate Pred = getCmpPredicateForMinMax(SPF, SPR.Ordered); + Predicate Pred = getCmpPredicateForMinMax(SPF, SPR.Ordered); Value *Cmp; - if (CmpInst::isIntPredicate(Pred)) { + if (Pred.isInt()) { Cmp = Builder->CreateICmp(Pred, LHS, RHS); } else { IRBuilder<>::FastMathFlagGuard FMFG(*Builder); Index: lib/Transforms/InstCombine/InstructionCombining.cpp =================================================================== --- lib/Transforms/InstCombine/InstructionCombining.cpp +++ lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2113,16 +2113,16 @@ // Validate the rest of constraint #1 by matching on the pred branch. TerminatorInst *TI = PredBB->getTerminator(); BasicBlock *TrueBB, *FalseBB; - ICmpInst::Predicate Pred; + Predicate Pred; if (!match(TI, m_Br(m_ICmp(Pred, m_Specific(Op), m_Zero()), TrueBB, FalseBB))) return nullptr; - if (Pred != ICmpInst::ICMP_EQ && Pred != ICmpInst::ICMP_NE) + if (!Pred.isOneOf(Predicate::ICMP_EQ, Predicate::ICMP_NE)) return nullptr; // Validate constraint #3: Ensure the null case just falls through. - if (SuccBB != (Pred == ICmpInst::ICMP_EQ ? TrueBB : FalseBB)) + if (SuccBB != (Pred == Predicate::ICMP_EQ ? TrueBB : FalseBB)) return nullptr; - assert(FreeInstrBB == (Pred == ICmpInst::ICMP_EQ ? FalseBB : TrueBB) && + assert(FreeInstrBB == (Pred == Predicate::ICMP_EQ ? FalseBB : TrueBB) && "Broken CFG: missing edge from predecessor to successor"); FI.moveBefore(TI); @@ -2202,14 +2202,15 @@ } // Canonicalize fcmp_one -> fcmp_oeq - FCmpInst::Predicate FPred; Value *Y; + Predicate FPred; + Value *Y; if (match(&BI, m_Br(m_FCmp(FPred, m_Value(X), m_Value(Y)), TrueDest, FalseDest)) && BI.getCondition()->hasOneUse()) - if (FPred == FCmpInst::FCMP_ONE || FPred == FCmpInst::FCMP_OLE || - FPred == FCmpInst::FCMP_OGE) { + if (FPred.isOneOf(Predicate::FCMP_ONE, Predicate::FCMP_OLE, + Predicate::FCMP_OGE)) { FCmpInst *Cond = cast(BI.getCondition()); - Cond->setPredicate(FCmpInst::getInversePredicate(FPred)); + Cond->setPredicate(FPred.getInverse()); // Swap Destinations and condition. BI.swapSuccessors(); @@ -2218,15 +2219,15 @@ } // Canonicalize icmp_ne -> icmp_eq - ICmpInst::Predicate IPred; + Predicate IPred; if (match(&BI, m_Br(m_ICmp(IPred, m_Value(X), m_Value(Y)), TrueDest, FalseDest)) && BI.getCondition()->hasOneUse()) - if (IPred == ICmpInst::ICMP_NE || IPred == ICmpInst::ICMP_ULE || - IPred == ICmpInst::ICMP_SLE || IPred == ICmpInst::ICMP_UGE || - IPred == ICmpInst::ICMP_SGE) { + if (IPred.isOneOf(Predicate::ICMP_NE, Predicate::ICMP_ULE, + Predicate::ICMP_SLE, Predicate::ICMP_UGE, + Predicate::ICMP_SGE)) { ICmpInst *Cond = cast(BI.getCondition()); - Cond->setPredicate(ICmpInst::getInversePredicate(IPred)); + Cond->setPredicate(IPred.getInverse()); // Swap Destinations and condition. BI.swapSuccessors(); Worklist.Add(Cond); @@ -2381,7 +2382,7 @@ // overflow = uadd a, -4 --> overflow = icmp ugt a, 3 if (II->getIntrinsicID() == Intrinsic::uadd_with_overflow) if (ConstantInt *CI = dyn_cast(II->getArgOperand(1))) - return new ICmpInst(ICmpInst::ICMP_UGT, II->getArgOperand(0), + return new ICmpInst(Predicate::ICMP_UGT, II->getArgOperand(0), ConstantExpr::getNot(CI)); break; case Intrinsic::usub_with_overflow: Index: lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1793,7 +1793,7 @@ void handleSignedRelationalComparison(ICmpInst &I) { Constant *constOp; Value *op = nullptr; - CmpInst::Predicate pre; + Predicate pre; if ((constOp = dyn_cast(I.getOperand(1)))) { op = I.getOperand(0); pre = I.getPredicate(); @@ -1806,9 +1806,9 @@ } if ((constOp->isNullValue() && - (pre == CmpInst::ICMP_SLT || pre == CmpInst::ICMP_SGE)) || + pre.isOneOf(Predicate::ICMP_SLT, Predicate::ICMP_SGE)) || (constOp->isAllOnesValue() && - (pre == CmpInst::ICMP_SGT || pre == CmpInst::ICMP_SLE))) { + pre.isOneOf(Predicate::ICMP_SGT, Predicate::ICMP_SLE))) { IRBuilder<> IRB(&I); Value *Shadow = IRB.CreateICmpSLT(getShadow(op), getCleanShadow(op), "_msprop_icmp_s"); Index: lib/Transforms/Instrumentation/SanitizerCoverage.cpp =================================================================== --- lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -500,7 +500,8 @@ // __sanitizer_cov_trace_cmp((type_size << 32) | predicate, A0, A1); IRB.CreateCall( SanCovTraceCmpFunction, - {ConstantInt::get(Int64Ty, (TypeSize << 32) | ICMP->getPredicate()), + {ConstantInt::get(Int64Ty, + (TypeSize << 32) | ICMP->getPredicate().getKind()), IRB.CreateIntCast(A0, Int64Ty, true), IRB.CreateIntCast(A1, Int64Ty, true)}); } Index: lib/Transforms/Scalar/AlignmentFromAssumptions.cpp =================================================================== --- lib/Transforms/Scalar/AlignmentFromAssumptions.cpp +++ lib/Transforms/Scalar/AlignmentFromAssumptions.cpp @@ -208,7 +208,7 @@ return false; // This must be an expression of the form: x & m == 0. - if (ICI->getPredicate() != ICmpInst::ICMP_EQ) + if (ICI->getPredicate() != Predicate::ICMP_EQ) return false; // Swap things around so that the RHS is 0. Index: lib/Transforms/Scalar/CorrelatedValuePropagation.cpp =================================================================== --- lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -131,9 +131,9 @@ Constant *C = dyn_cast(SI->getFalseValue()); if (!C) continue; - if (LVI->getPredicateOnEdge(ICmpInst::ICMP_EQ, SI, C, - P->getIncomingBlock(i), BB, P) != - LazyValueInfo::False) + if (LVI->getPredicateOnEdge(Predicate::ICMP_EQ, SI, C, + P->getIncomingBlock(i), BB, + P) != LazyValueInfo::False) continue; V = SI->getTrueValue(); } @@ -240,9 +240,8 @@ LazyValueInfo::Tristate State = LazyValueInfo::Unknown; for (pred_iterator PI = PB; PI != PE; ++PI) { // Is the switch condition equal to the case value? - LazyValueInfo::Tristate Value = LVI->getPredicateOnEdge(CmpInst::ICMP_EQ, - Cond, Case, *PI, - BB, SI); + LazyValueInfo::Tristate Value = + LVI->getPredicateOnEdge(Predicate::ICMP_EQ, Cond, Case, *PI, BB, SI); // Give up on this case if nothing is known. if (Value == LazyValueInfo::Unknown) { State = LazyValueInfo::Unknown; @@ -305,8 +304,8 @@ // relatively expensive analysis for constants which are obviously either // null or non-null to start with. if (Type && !CS.paramHasAttr(ArgNo + 1, Attribute::NonNull) && - !isa(V) && - LVI->getPredicateAt(ICmpInst::ICMP_EQ, V, + !isa(V) && + LVI->getPredicateAt(Predicate::ICMP_EQ, V, ConstantPointerNull::get(Type), CS.getInstruction()) == LazyValueInfo::False) Indices.push_back(ArgNo + 1); @@ -341,7 +340,7 @@ static bool hasPositiveOperands(BinaryOperator *SDI, LazyValueInfo *LVI) { Constant *Zero = ConstantInt::get(SDI->getType(), 0); for (Value *O : SDI->operands()) { - auto Result = LVI->getPredicateAt(ICmpInst::ICMP_SGE, O, Zero, SDI); + auto Result = LVI->getPredicateAt(Predicate::ICMP_SGE, O, Zero, SDI); if (Result != LazyValueInfo::True) return false; } Index: lib/Transforms/Scalar/EarlyCSE.cpp =================================================================== --- lib/Transforms/Scalar/EarlyCSE.cpp +++ lib/Transforms/Scalar/EarlyCSE.cpp @@ -104,12 +104,12 @@ if (CmpInst *CI = dyn_cast(Inst)) { Value *LHS = CI->getOperand(0); Value *RHS = CI->getOperand(1); - CmpInst::Predicate Pred = CI->getPredicate(); + Predicate Pred = CI->getPredicate(); if (Inst->getOperand(0) > Inst->getOperand(1)) { std::swap(LHS, RHS); - Pred = CI->getSwappedPredicate(); + Pred = Pred.getSwapped(); } - return hash_combine(Inst->getOpcode(), Pred, LHS, RHS); + return hash_combine(Inst->getOpcode(), Pred.getKind(), LHS, RHS); } if (CastInst *CI = dyn_cast(Inst)) Index: lib/Transforms/Scalar/Float2Int.cpp =================================================================== --- lib/Transforms/Scalar/Float2Int.cpp +++ lib/Transforms/Scalar/Float2Int.cpp @@ -79,28 +79,28 @@ // Given a FCmp predicate, return a matching ICmp predicate if one // exists, otherwise return BAD_ICMP_PREDICATE. -static CmpInst::Predicate mapFCmpPred(CmpInst::Predicate P) { - switch (P) { - case CmpInst::FCMP_OEQ: - case CmpInst::FCMP_UEQ: - return CmpInst::ICMP_EQ; - case CmpInst::FCMP_OGT: - case CmpInst::FCMP_UGT: - return CmpInst::ICMP_SGT; - case CmpInst::FCMP_OGE: - case CmpInst::FCMP_UGE: - return CmpInst::ICMP_SGE; - case CmpInst::FCMP_OLT: - case CmpInst::FCMP_ULT: - return CmpInst::ICMP_SLT; - case CmpInst::FCMP_OLE: - case CmpInst::FCMP_ULE: - return CmpInst::ICMP_SLE; - case CmpInst::FCMP_ONE: - case CmpInst::FCMP_UNE: - return CmpInst::ICMP_NE; +static Predicate mapFCmpPred(Predicate P) { + switch (P.getKind()) { + case Predicate::FCMP_OEQ: + case Predicate::FCMP_UEQ: + return Predicate::ICMP_EQ; + case Predicate::FCMP_OGT: + case Predicate::FCMP_UGT: + return Predicate::ICMP_SGT; + case Predicate::FCMP_OGE: + case Predicate::FCMP_UGE: + return Predicate::ICMP_SGE; + case Predicate::FCMP_OLT: + case Predicate::FCMP_ULT: + return Predicate::ICMP_SLT; + case Predicate::FCMP_OLE: + case Predicate::FCMP_ULE: + return Predicate::ICMP_SLE; + case Predicate::FCMP_ONE: + case Predicate::FCMP_UNE: + return Predicate::ICMP_NE; default: - return CmpInst::BAD_ICMP_PREDICATE; + return Predicate::BAD_ICMP_PREDICATE; } } @@ -129,7 +129,7 @@ break; case Instruction::FCmp: if (mapFCmpPred(cast(&I)->getPredicate()) != - CmpInst::BAD_ICMP_PREDICATE) + Predicate::BAD_ICMP_PREDICATE) Roots.insert(&I); break; } @@ -467,8 +467,8 @@ break; case Instruction::FCmp: { - CmpInst::Predicate P = mapFCmpPred(cast(I)->getPredicate()); - assert(P != CmpInst::BAD_ICMP_PREDICATE && "Unhandled predicate!"); + Predicate P = mapFCmpPred(cast(I)->getPredicate()); + assert(P != Predicate::BAD_ICMP_PREDICATE && "Unhandled predicate!"); NewV = IRB.CreateICmp(P, NewOperands[0], NewOperands[1], I->getName()); break; } Index: lib/Transforms/Scalar/GVN.cpp =================================================================== --- lib/Transforms/Scalar/GVN.cpp +++ lib/Transforms/Scalar/GVN.cpp @@ -247,12 +247,12 @@ if (CmpInst *C = dyn_cast(I)) { // Sort the operand value numbers so xx get the same value number. - CmpInst::Predicate Predicate = C->getPredicate(); + Predicate Pred = C->getPredicate(); if (e.varargs[0] > e.varargs[1]) { std::swap(e.varargs[0], e.varargs[1]); - Predicate = CmpInst::getSwappedPredicate(Predicate); + Pred = Pred.getSwapped(); } - e.opcode = (C->getOpcode() << 8) | Predicate; + e.opcode = (C->getOpcode() << 8) | Pred.getKind(); } else if (InsertValueInst *E = dyn_cast(I)) { for (InsertValueInst::idx_iterator II = E->idx_begin(), IE = E->idx_end(); II != IE; ++II) @@ -262,8 +262,7 @@ return e; } -GVN::Expression GVN::ValueTable::createCmpExpr(unsigned Opcode, - CmpInst::Predicate Predicate, +GVN::Expression GVN::ValueTable::createCmpExpr(unsigned Opcode, Predicate Pred, Value *LHS, Value *RHS) { assert((Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) && "Not a comparison!"); @@ -275,9 +274,9 @@ // Sort the operand value numbers so xx get the same value number. if (e.varargs[0] > e.varargs[1]) { std::swap(e.varargs[0], e.varargs[1]); - Predicate = CmpInst::getSwappedPredicate(Predicate); + Pred = Pred.getSwapped(); } - e.opcode = (Opcode << 8) | Predicate; + e.opcode = (Opcode << 8) | Pred.getKind(); return e; } @@ -549,8 +548,7 @@ /// assigning it a new number if it did not have one before. Useful when /// we deduced the result of a comparison, but don't immediately have an /// instruction realizing that comparison to hand. -uint32_t GVN::ValueTable::lookupOrAddCmp(unsigned Opcode, - CmpInst::Predicate Predicate, +uint32_t GVN::ValueTable::lookupOrAddCmp(unsigned Opcode, Predicate Predicate, Value *LHS, Value *RHS) { Expression exp = createCmpExpr(Opcode, Predicate, LHS, RHS); uint32_t& e = expressionNumbering[exp]; @@ -1732,9 +1730,9 @@ // call void @llvm.assume(i1 %cmp) // ret float %0 ; will change it to ret float 3.000000e+00 if (auto *CmpI = dyn_cast(V)) { - if (CmpI->getPredicate() == CmpInst::Predicate::ICMP_EQ || - CmpI->getPredicate() == CmpInst::Predicate::FCMP_OEQ || - (CmpI->getPredicate() == CmpInst::Predicate::FCMP_UEQ && + if (CmpI->getPredicate() == Predicate::ICMP_EQ || + CmpI->getPredicate() == Predicate::FCMP_OEQ || + (CmpI->getPredicate() == Predicate::FCMP_UEQ && CmpI->getFastMathFlags().noNaNs())) { Value *CmpLHS = CmpI->getOperand(0); Value *CmpRHS = CmpI->getOperand(1); @@ -2001,13 +1999,13 @@ // If "A == B" is known true, or "A != B" is known false, then replace // A with B everywhere in the scope. - if ((isKnownTrue && Cmp->getPredicate() == CmpInst::ICMP_EQ) || - (isKnownFalse && Cmp->getPredicate() == CmpInst::ICMP_NE)) + if ((isKnownTrue && Cmp->getPredicate() == Predicate::ICMP_EQ) || + (isKnownFalse && Cmp->getPredicate() == Predicate::ICMP_NE)) Worklist.push_back(std::make_pair(Op0, Op1)); // Handle the floating point versions of equality comparisons too. - if ((isKnownTrue && Cmp->getPredicate() == CmpInst::FCMP_OEQ) || - (isKnownFalse && Cmp->getPredicate() == CmpInst::FCMP_UNE)) { + if ((isKnownTrue && Cmp->getPredicate() == Predicate::FCMP_OEQ) || + (isKnownFalse && Cmp->getPredicate() == Predicate::FCMP_UNE)) { // Floating point -0.0 and 0.0 compare equal, so we can only // propagate values if we know that we have a constant and that @@ -2022,7 +2020,7 @@ } // If "A >= B" is known true, replace "A < B" with false everywhere. - CmpInst::Predicate NotPred = Cmp->getInversePredicate(); + Predicate NotPred = Cmp->getInversePredicate(); Constant *NotVal = ConstantInt::get(Cmp->getType(), isKnownFalse); // Since we don't have the instruction "A < B" immediately to hand, work // out the value number that it would have and use that to find an Index: lib/Transforms/Scalar/GuardWidening.cpp =================================================================== --- lib/Transforms/Scalar/GuardWidening.cpp +++ lib/Transforms/Scalar/GuardWidening.cpp @@ -409,7 +409,7 @@ // L >u C0 && L >u C1 -> L >u max(C0, C1) ConstantInt *RHS0, *RHS1; Value *LHS; - ICmpInst::Predicate Pred0, Pred1; + Predicate Pred0, Pred1; if (match(Cond0, m_ICmp(Pred0, m_Value(LHS), m_ConstantInt(RHS0))) && match(Cond1, m_ICmp(Pred1, m_Specific(LHS), m_ConstantInt(RHS1)))) { @@ -431,7 +431,7 @@ auto SupersetIntersect = CR0.intersectWith(CR1); APInt NewRHSAP; - CmpInst::Predicate Pred; + Predicate Pred; if (SubsetIntersect == SupersetIntersect && SubsetIntersect.getEquivalentICmp(Pred, NewRHSAP)) { if (InsertPt) { @@ -494,12 +494,12 @@ auto *IC = dyn_cast(CheckCond); if (!IC || !IC->getOperand(0)->getType()->isIntegerTy() || - (IC->getPredicate() != ICmpInst::ICMP_ULT && - IC->getPredicate() != ICmpInst::ICMP_UGT)) + (IC->getPredicate() != Predicate::ICMP_ULT && + IC->getPredicate() != Predicate::ICMP_UGT)) return false; Value *CmpLHS = IC->getOperand(0), *CmpRHS = IC->getOperand(1); - if (IC->getPredicate() == ICmpInst::ICMP_UGT) + if (IC->getPredicate() == Predicate::ICMP_UGT) std::swap(CmpLHS, CmpRHS); auto &DL = IC->getModule()->getDataLayout(); Index: lib/Transforms/Scalar/IndVarSimplify.cpp =================================================================== --- lib/Transforms/Scalar/IndVarSimplify.cpp +++ lib/Transforms/Scalar/IndVarSimplify.cpp @@ -306,21 +306,33 @@ return; // Find new predicate for integer comparison. - CmpInst::Predicate NewPred = CmpInst::BAD_ICMP_PREDICATE; - switch (Compare->getPredicate()) { + Predicate NewPred = Predicate::BAD_ICMP_PREDICATE; + switch (Compare->getPredicate().getKind()) { default: return; // Unknown comparison. - case CmpInst::FCMP_OEQ: - case CmpInst::FCMP_UEQ: NewPred = CmpInst::ICMP_EQ; break; - case CmpInst::FCMP_ONE: - case CmpInst::FCMP_UNE: NewPred = CmpInst::ICMP_NE; break; - case CmpInst::FCMP_OGT: - case CmpInst::FCMP_UGT: NewPred = CmpInst::ICMP_SGT; break; - case CmpInst::FCMP_OGE: - case CmpInst::FCMP_UGE: NewPred = CmpInst::ICMP_SGE; break; - case CmpInst::FCMP_OLT: - case CmpInst::FCMP_ULT: NewPred = CmpInst::ICMP_SLT; break; - case CmpInst::FCMP_OLE: - case CmpInst::FCMP_ULE: NewPred = CmpInst::ICMP_SLE; break; + case Predicate::FCMP_OEQ: + case Predicate::FCMP_UEQ: + NewPred = Predicate::ICMP_EQ; + break; + case Predicate::FCMP_ONE: + case Predicate::FCMP_UNE: + NewPred = Predicate::ICMP_NE; + break; + case Predicate::FCMP_OGT: + case Predicate::FCMP_UGT: + NewPred = Predicate::ICMP_SGT; + break; + case Predicate::FCMP_OGE: + case Predicate::FCMP_UGE: + NewPred = Predicate::ICMP_SGE; + break; + case Predicate::FCMP_OLT: + case Predicate::FCMP_ULT: + NewPred = Predicate::ICMP_SLT; + break; + case Predicate::FCMP_OLE: + case Predicate::FCMP_ULE: + NewPred = Predicate::ICMP_SLE; + break; } // We convert the floating point induction variable to a signed i32 value if @@ -347,7 +359,7 @@ uint32_t Range = uint32_t(ExitValue-InitValue); // Check for infinite loop, either: // while (i <= Exit) or until (i > Exit) - if (NewPred == CmpInst::ICMP_SLE || NewPred == CmpInst::ICMP_SGT) { + if (NewPred == Predicate::ICMP_SLE || NewPred == Predicate::ICMP_SGT) { if (++Range == 0) return; // Range overflows. } @@ -356,7 +368,7 @@ // If this is an equality comparison, we require that the strided value // exactly land on the exit value, otherwise the IV condition will wrap // around and do things the fp IV wouldn't. - if ((NewPred == CmpInst::ICMP_EQ || NewPred == CmpInst::ICMP_NE) && + if ((NewPred == Predicate::ICMP_EQ || NewPred == Predicate::ICMP_NE) && Leftover != 0) return; @@ -374,7 +386,7 @@ uint32_t Range = uint32_t(InitValue-ExitValue); // Check for infinite loop, either: // while (i >= Exit) or until (i < Exit) - if (NewPred == CmpInst::ICMP_SGE || NewPred == CmpInst::ICMP_SLT) { + if (NewPred == Predicate::ICMP_SGE || NewPred == Predicate::ICMP_SLT) { if (++Range == 0) return; // Range overflows. } @@ -383,7 +395,7 @@ // If this is an equality comparison, we require that the strided value // exactly land on the exit value, otherwise the IV condition will wrap // around and do things the fp IV wouldn't. - if ((NewPred == CmpInst::ICMP_EQ || NewPred == CmpInst::ICMP_NE) && + if ((NewPred == Predicate::ICMP_EQ || NewPred == Predicate::ICMP_NE) && Leftover != 0) return; @@ -1371,7 +1383,7 @@ void WidenIV::pushNarrowIVUsers(Instruction *NarrowDef, Instruction *WideDef) { const SCEV *NarrowSCEV = SE->getSCEV(NarrowDef); bool NeverNegative = - SE->isKnownPredicate(ICmpInst::ICMP_SGE, NarrowSCEV, + SE->isKnownPredicate(Predicate::ICMP_SGE, NarrowSCEV, SE->getConstant(NarrowSCEV->getType(), 0)); for (User *U : NarrowDef->users()) { Instruction *NarrowUser = cast(U); @@ -1641,8 +1653,8 @@ return true; // Do LFTR to simplify the exit ICMP to EQ/NE - ICmpInst::Predicate Pred = Cond->getPredicate(); - if (Pred != ICmpInst::ICMP_NE && Pred != ICmpInst::ICMP_EQ) + Predicate Pred = Cond->getPredicate(); + if (Pred != Predicate::ICMP_NE && Pred != Predicate::ICMP_EQ) return true; // Look for a loop invariant RHS @@ -1940,16 +1952,16 @@ // Insert a new icmp_ne or icmp_eq instruction before the branch. BranchInst *BI = cast(L->getExitingBlock()->getTerminator()); - ICmpInst::Predicate P; + Predicate P; if (L->contains(BI->getSuccessor(0))) - P = ICmpInst::ICMP_NE; + P = Predicate::ICMP_NE; else - P = ICmpInst::ICMP_EQ; + P = Predicate::ICMP_EQ; DEBUG(dbgs() << "INDVARS: Rewriting loop exit condition to:\n" << " LHS:" << *CmpIndVar << '\n' - << " op:\t" - << (P == ICmpInst::ICMP_NE ? "!=" : "==") << "\n" + << " op:\t" << (P == Predicate::ICMP_NE ? "!=" : "==") + << "\n" << " RHS:\t" << *ExitCnt << "\n" << " IVCount:\t" << *IVCount << "\n"); Index: lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp =================================================================== --- lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp +++ lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp @@ -263,28 +263,28 @@ using namespace llvm::PatternMatch; - ICmpInst::Predicate Pred = ICI->getPredicate(); + Predicate Pred = ICI->getPredicate(); Value *LHS = ICI->getOperand(0); Value *RHS = ICI->getOperand(1); - switch (Pred) { + switch (Pred.getKind()) { default: return RANGE_CHECK_UNKNOWN; - case ICmpInst::ICMP_SLE: + case Predicate::ICMP_SLE: std::swap(LHS, RHS); // fallthrough - case ICmpInst::ICMP_SGE: + case Predicate::ICMP_SGE: if (match(RHS, m_ConstantInt<0>())) { Index = LHS; return RANGE_CHECK_LOWER; } return RANGE_CHECK_UNKNOWN; - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: std::swap(LHS, RHS); // fallthrough - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: if (match(RHS, m_ConstantInt<-1>())) { Index = LHS; return RANGE_CHECK_LOWER; @@ -297,10 +297,10 @@ } return RANGE_CHECK_UNKNOWN; - case ICmpInst::ICMP_ULT: + case Predicate::ICMP_ULT: std::swap(LHS, RHS); // fallthrough - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_UGT: if (IsNonNegativeAndNotLoopVarying(LHS)) { Index = RHS; Length = LHS; @@ -666,7 +666,7 @@ return None; } - ICmpInst::Predicate Pred = ICI->getPredicate(); + Predicate Pred = ICI->getPredicate(); Value *LeftValue = ICI->getOperand(0); const SCEV *LeftSCEV = SE.getSCEV(LeftValue); IntegerType *IndVarTy = cast(LeftValue->getType()); @@ -679,7 +679,7 @@ if (isa(RightSCEV)) { std::swap(LeftSCEV, RightSCEV); std::swap(LeftValue, RightValue); - Pred = ICmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); } else { FailureReason = "no add recurrences in the icmp"; return None; @@ -748,8 +748,8 @@ // TODO: generalize the predicates here to also match their unsigned variants. if (IsIncreasing) { bool FoundExpectedPred = - (Pred == ICmpInst::ICMP_SLT && LatchBrExitIdx == 1) || - (Pred == ICmpInst::ICMP_SGT && LatchBrExitIdx == 0); + (Pred == Predicate::ICMP_SLT && LatchBrExitIdx == 1) || + (Pred == Predicate::ICMP_SGT && LatchBrExitIdx == 0); if (!FoundExpectedPred) { FailureReason = "expected icmp slt semantically, found something else"; @@ -770,8 +770,8 @@ } else { bool FoundExpectedPred = - (Pred == ICmpInst::ICMP_SGT && LatchBrExitIdx == 1) || - (Pred == ICmpInst::ICMP_SLT && LatchBrExitIdx == 0); + (Pred == Predicate::ICMP_SGT && LatchBrExitIdx == 1) || + (Pred == Predicate::ICMP_SLT && LatchBrExitIdx == 0); if (!FoundExpectedPred) { FailureReason = "expected icmp sgt semantically, found something else"; @@ -880,12 +880,12 @@ // In some cases we can prove that we don't need a pre or post loop bool ProvablyNoPreloop = - SE.isKnownPredicate(ICmpInst::ICMP_SLE, Range.getBegin(), Smallest); + SE.isKnownPredicate(Predicate::ICMP_SLE, Range.getBegin(), Smallest); if (!ProvablyNoPreloop) Result.LowLimit = Clamp(Range.getBegin()); bool ProvablyNoPostLoop = - SE.isKnownPredicate(ICmpInst::ICMP_SLE, Greatest, Range.getEnd()); + SE.isKnownPredicate(Predicate::ICMP_SLE, Greatest, Range.getEnd()); if (!ProvablyNoPostLoop) Result.HighLimit = Clamp(Range.getEnd()); Index: lib/Transforms/Scalar/LoopIdiomRecognize.cpp =================================================================== --- lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -969,9 +969,9 @@ if (!CmpZero || !CmpZero->isZero()) return nullptr; - ICmpInst::Predicate Pred = Cond->getPredicate(); - if ((Pred == ICmpInst::ICMP_NE && BI->getSuccessor(0) == LoopEntry) || - (Pred == ICmpInst::ICMP_EQ && BI->getSuccessor(1) == LoopEntry)) + Predicate Pred = Cond->getPredicate(); + if ((Pred == Predicate::ICMP_NE && BI->getSuccessor(0) == LoopEntry) || + (Pred == Predicate::ICMP_EQ && BI->getSuccessor(1) == LoopEntry)) return Cond->getOperand(0); return nullptr; @@ -1268,8 +1268,8 @@ TcPhi->addIncoming(TripCnt, PreHead); TcPhi->addIncoming(TcDec, Body); - CmpInst::Predicate Pred = - (LbBr->getSuccessor(0) == Body) ? CmpInst::ICMP_UGT : CmpInst::ICMP_SLE; + Predicate Pred = (LbBr->getSuccessor(0) == Body) ? Predicate::ICMP_UGT + : Predicate::ICMP_SLE; LbCond->setPredicate(Pred); LbCond->setOperand(0, TcDec); LbCond->setOperand(1, ConstantInt::get(Ty, 0)); Index: lib/Transforms/Scalar/LoopRerollPass.cpp =================================================================== --- lib/Transforms/Scalar/LoopRerollPass.cpp +++ lib/Transforms/Scalar/LoopRerollPass.cpp @@ -1545,8 +1545,8 @@ Value *ICMinusPlus1 = Expander.expandCodeFor( ICMinusPlus1SCEV, NewIV->getType(), InsertPtr); - Value *Cond = - new ICmpInst(BI, CmpInst::ICMP_EQ, NewIV, ICMinusPlus1, "exitcond"); + Value *Cond = new ICmpInst(BI, Predicate::ICMP_EQ, NewIV, ICMinusPlus1, + "exitcond"); BI->setCondition(Cond); if (BI->getSuccessor(1) != Header) Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp =================================================================== --- lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1958,8 +1958,8 @@ /// ICmpInst *LSRInstance::OptimizeMax(ICmpInst *Cond, IVStrideUse* &CondUse) { // Check that the loop matches the pattern we're looking for. - if (Cond->getPredicate() != CmpInst::ICMP_EQ && - Cond->getPredicate() != CmpInst::ICMP_NE) + if (Cond->getPredicate() != Predicate::ICMP_EQ && + Cond->getPredicate() != Predicate::ICMP_NE) return Cond; SelectInst *Sel = dyn_cast(Cond->getOperand(1)); @@ -1977,16 +1977,16 @@ // Check for a max calculation that matches the pattern. There's no check // for ICMP_ULE here because the comparison would be with zero, which // isn't interesting. - CmpInst::Predicate Pred = ICmpInst::BAD_ICMP_PREDICATE; + Predicate Pred = Predicate::BAD_ICMP_PREDICATE; const SCEVNAryExpr *Max = nullptr; if (const SCEVSMaxExpr *S = dyn_cast(BackedgeTakenCount)) { - Pred = ICmpInst::ICMP_SLE; + Pred = Predicate::ICMP_SLE; Max = S; } else if (const SCEVSMaxExpr *S = dyn_cast(IterationCount)) { - Pred = ICmpInst::ICMP_SLT; + Pred = Predicate::ICMP_SLT; Max = S; } else if (const SCEVUMaxExpr *U = dyn_cast(IterationCount)) { - Pred = ICmpInst::ICMP_ULT; + Pred = Predicate::ICMP_ULT; Max = U; } else { // No match; bail. @@ -2003,8 +2003,7 @@ // ScalarEvolution canonicalizes constants to the left. For < and >, look // for a comparison with 1. For <= and >=, a comparison with zero. - if (!MaxLHS || - (ICmpInst::isTrueWhenEqual(Pred) ? !MaxLHS->isZero() : (MaxLHS != One))) + if (!MaxLHS || (Pred.isTrueWhenEqual() ? !MaxLHS->isZero() : (MaxLHS != One))) return Cond; // Check the relevant induction variable for conformance to @@ -2022,7 +2021,7 @@ // Check the right operand of the select, and remember it, as it will // be used in the new comparison instruction. Value *NewRHS = nullptr; - if (ICmpInst::isTrueWhenEqual(Pred)) { + if (Pred.isTrueWhenEqual()) { // Look for n+1, and grab n. if (AddOperator *BO = dyn_cast(Sel->getOperand(1))) if (ConstantInt *BO1 = dyn_cast(BO->getOperand(1))) @@ -2046,8 +2045,8 @@ // Determine the new comparison opcode. It may be signed or unsigned, // and the original comparison may be either equality or inequality. - if (Cond->getPredicate() == CmpInst::ICMP_EQ) - Pred = CmpInst::getInversePredicate(Pred); + if (Cond->getPredicate() == Predicate::ICMP_EQ) + Pred = Pred.getInverse(); // Ok, everything looks ok to change the condition into an SLT or SGE and // delete the max calculation. Index: lib/Transforms/Scalar/LoopUnswitch.cpp =================================================================== --- lib/Transforms/Scalar/LoopUnswitch.cpp +++ lib/Transforms/Scalar/LoopUnswitch.cpp @@ -791,7 +791,7 @@ bool Swapped = false; if (!isa(Val) || Val->getType() != Type::getInt1Ty(LIC->getContext())) - BranchVal = new ICmpInst(InsertPt, ICmpInst::ICMP_EQ, LIC, Val); + BranchVal = new ICmpInst(InsertPt, Predicate::ICMP_EQ, LIC, Val); else if (Val != ConstantInt::getTrue(Val->getContext())) { // We want to enter the new loop when the condition is true. std::swap(TrueDest, FalseDest); Index: lib/Transforms/Scalar/LowerExpectIntrinsic.cpp =================================================================== --- lib/Transforms/Scalar/LowerExpectIntrinsic.cpp +++ lib/Transforms/Scalar/LowerExpectIntrinsic.cpp @@ -102,7 +102,7 @@ if (!CmpI) { CI = dyn_cast(BI.getCondition()); } else { - if (CmpI->getPredicate() != CmpInst::ICMP_NE) + if (CmpI->getPredicate() != Predicate::ICMP_NE) return false; CI = dyn_cast(CmpI->getOperand(0)); } Index: lib/Transforms/Utils/CmpInstAnalysis.cpp =================================================================== --- lib/Transforms/Utils/CmpInstAnalysis.cpp +++ lib/Transforms/Utils/CmpInstAnalysis.cpp @@ -19,86 +19,108 @@ using namespace llvm; unsigned llvm::getICmpCode(const ICmpInst *ICI, bool InvertPred) { - ICmpInst::Predicate Pred = InvertPred ? ICI->getInversePredicate() - : ICI->getPredicate(); - switch (Pred) { - // False -> 0 - case ICmpInst::ICMP_UGT: return 1; // 001 - case ICmpInst::ICMP_SGT: return 1; // 001 - case ICmpInst::ICMP_EQ: return 2; // 010 - case ICmpInst::ICMP_UGE: return 3; // 011 - case ICmpInst::ICMP_SGE: return 3; // 011 - case ICmpInst::ICMP_ULT: return 4; // 100 - case ICmpInst::ICMP_SLT: return 4; // 100 - case ICmpInst::ICMP_NE: return 5; // 101 - case ICmpInst::ICMP_ULE: return 6; // 110 - case ICmpInst::ICMP_SLE: return 6; // 110 - // True -> 7 - default: - llvm_unreachable("Invalid ICmp predicate!"); + Predicate Pred = + InvertPred ? ICI->getInversePredicate() : ICI->getPredicate(); + switch (Pred.getKind()) { + // False -> 0 + case Predicate::ICMP_UGT: + return 1; // 001 + case Predicate::ICMP_SGT: + return 1; // 001 + case Predicate::ICMP_EQ: + return 2; // 010 + case Predicate::ICMP_UGE: + return 3; // 011 + case Predicate::ICMP_SGE: + return 3; // 011 + case Predicate::ICMP_ULT: + return 4; // 100 + case Predicate::ICMP_SLT: + return 4; // 100 + case Predicate::ICMP_NE: + return 5; // 101 + case Predicate::ICMP_ULE: + return 6; // 110 + case Predicate::ICMP_SLE: + return 6; // 110 + // True -> 7 + default: + llvm_unreachable("Invalid ICmp predicate!"); } } Value *llvm::getICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, - CmpInst::Predicate &NewICmpPred) { + Predicate &NewICmpPred) { switch (Code) { default: llvm_unreachable("Illegal ICmp code!"); case 0: // False. return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0); - case 1: NewICmpPred = Sign ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; break; - case 2: NewICmpPred = ICmpInst::ICMP_EQ; break; - case 3: NewICmpPred = Sign ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE; break; - case 4: NewICmpPred = Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; break; - case 5: NewICmpPred = ICmpInst::ICMP_NE; break; - case 6: NewICmpPred = Sign ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE; break; + case 1: + NewICmpPred = Sign ? Predicate::ICMP_SGT : Predicate::ICMP_UGT; + break; + case 2: + NewICmpPred = Predicate::ICMP_EQ; + break; + case 3: + NewICmpPred = Sign ? Predicate::ICMP_SGE : Predicate::ICMP_UGE; + break; + case 4: + NewICmpPred = Sign ? Predicate::ICMP_SLT : Predicate::ICMP_ULT; + break; + case 5: + NewICmpPred = Predicate::ICMP_NE; + break; + case 6: + NewICmpPred = Sign ? Predicate::ICMP_SLE : Predicate::ICMP_ULE; + break; case 7: // True. return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 1); } return nullptr; } -bool llvm::PredicatesFoldable(ICmpInst::Predicate p1, ICmpInst::Predicate p2) { - return (CmpInst::isSigned(p1) == CmpInst::isSigned(p2)) || - (CmpInst::isSigned(p1) && ICmpInst::isEquality(p2)) || - (CmpInst::isSigned(p2) && ICmpInst::isEquality(p1)); +bool llvm::PredicatesFoldable(Predicate p1, Predicate p2) { + return (p1.isSigned() == p2.isSigned()) || + (p1.isSigned() && p2.isEquality()) || + (p2.isSigned() && p1.isEquality()); } -bool llvm::decomposeBitTestICmp(const ICmpInst *I, CmpInst::Predicate &Pred, - Value *&X, Value *&Y, Value *&Z) { +bool llvm::decomposeBitTestICmp(const ICmpInst *I, Predicate &Pred, Value *&X, + Value *&Y, Value *&Z) { ConstantInt *C = dyn_cast(I->getOperand(1)); if (!C) return false; - switch (I->getPredicate()) { + switch (I->getPredicate().getKind()) { default: return false; - case ICmpInst::ICMP_SLT: + case Predicate::ICMP_SLT: // X < 0 is equivalent to (X & SignBit) != 0. if (!C->isZero()) return false; Y = ConstantInt::get(I->getContext(), APInt::getSignBit(C->getBitWidth())); - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; break; - case ICmpInst::ICMP_SGT: + case Predicate::ICMP_SGT: // X > -1 is equivalent to (X & SignBit) == 0. if (!C->isAllOnesValue()) return false; Y = ConstantInt::get(I->getContext(), APInt::getSignBit(C->getBitWidth())); - Pred = ICmpInst::ICMP_EQ; + Pred = Predicate::ICMP_EQ; break; - case ICmpInst::ICMP_ULT: + case Predicate::ICMP_ULT: // X getValue().isPowerOf2()) return false; Y = ConstantInt::get(I->getContext(), -C->getValue()); - Pred = ICmpInst::ICMP_EQ; + Pred = Predicate::ICMP_EQ; break; - case ICmpInst::ICMP_UGT: + case Predicate::ICMP_UGT: // X >u 2^n-1 is equivalent to (X & ~(2^n-1)) != 0. if (!(C->getValue() + 1).isPowerOf2()) return false; Y = ConstantInt::get(I->getContext(), ~C->getValue()); - Pred = ICmpInst::ICMP_NE; + Pred = Predicate::ICMP_NE; break; } Index: lib/Transforms/Utils/FlattenCFG.cpp =================================================================== --- lib/Transforms/Utils/FlattenCFG.cpp +++ lib/Transforms/Utils/FlattenCFG.cpp @@ -244,10 +244,10 @@ if (!CI) continue; - CmpInst::Predicate Predicate = CI->getPredicate(); + Predicate Pred = CI->getPredicate(); // Canonicalize icmp_ne -> icmp_eq, fcmp_one -> fcmp_oeq - if ((Predicate == CmpInst::ICMP_NE) || (Predicate == CmpInst::FCMP_ONE)) { - CI->setPredicate(ICmpInst::getInversePredicate(Predicate)); + if (Pred.isOneOf(Predicate::ICMP_NE, Predicate::FCMP_ONE)) { + CI->setPredicate(Pred.getInverse()); BI->swapSuccessors(); EverChanged = true; } Index: lib/Transforms/Utils/LoopUtils.cpp =================================================================== --- lib/Transforms/Utils/LoopUtils.cpp +++ lib/Transforms/Utils/LoopUtils.cpp @@ -614,27 +614,27 @@ Value *RecurrenceDescriptor::createMinMaxOp(IRBuilder<> &Builder, MinMaxRecurrenceKind RK, Value *Left, Value *Right) { - CmpInst::Predicate P = CmpInst::ICMP_NE; + Predicate P = Predicate::ICMP_NE; switch (RK) { default: llvm_unreachable("Unknown min/max recurrence kind"); case MRK_UIntMin: - P = CmpInst::ICMP_ULT; + P = Predicate::ICMP_ULT; break; case MRK_UIntMax: - P = CmpInst::ICMP_UGT; + P = Predicate::ICMP_UGT; break; case MRK_SIntMin: - P = CmpInst::ICMP_SLT; + P = Predicate::ICMP_SLT; break; case MRK_SIntMax: - P = CmpInst::ICMP_SGT; + P = Predicate::ICMP_SGT; break; case MRK_FloatMin: - P = CmpInst::FCMP_OLT; + P = Predicate::FCMP_OLT; break; case MRK_FloatMax: - P = CmpInst::FCMP_OGT; + P = Predicate::FCMP_OGT; break; } Index: lib/Transforms/Utils/LowerSwitch.cpp =================================================================== --- lib/Transforms/Utils/LowerSwitch.cpp +++ lib/Transforms/Utils/LowerSwitch.cpp @@ -271,8 +271,7 @@ Function* F = OrigBlock->getParent(); BasicBlock* NewNode = BasicBlock::Create(Val->getContext(), "NodeBlock"); - ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_SLT, - Val, Pivot.Low, "Pivot"); + ICmpInst *Comp = new ICmpInst(Predicate::ICMP_SLT, Val, Pivot.Low, "Pivot"); BasicBlock *LBranch = switchConvert(LHS.begin(), LHS.end(), LowerBound, NewUpperBound, Val, NewNode, OrigBlock, @@ -304,18 +303,18 @@ ICmpInst* Comp = nullptr; if (Leaf.Low == Leaf.High) { // Make the seteq instruction... - Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_EQ, Val, - Leaf.Low, "SwitchLeaf"); + Comp = + new ICmpInst(*NewLeaf, Predicate::ICMP_EQ, Val, Leaf.Low, "SwitchLeaf"); } else { // Make range comparison if (Leaf.Low->isMinValue(true /*isSigned*/)) { // Val >= Min && Val <= Hi --> Val <= Hi - Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_SLE, Val, Leaf.High, + Comp = new ICmpInst(*NewLeaf, Predicate::ICMP_SLE, Val, Leaf.High, "SwitchLeaf"); } else if (Leaf.Low->isZero()) { // Val >= 0 && Val <= Hi --> Val <=u Hi - Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_ULE, Val, Leaf.High, - "SwitchLeaf"); + Comp = new ICmpInst(*NewLeaf, Predicate::ICMP_ULE, Val, Leaf.High, + "SwitchLeaf"); } else { // Emit V-Lo <=u Hi-Lo Constant* NegLo = ConstantExpr::getNeg(Leaf.Low); @@ -323,7 +322,7 @@ Val->getName()+".off", NewLeaf); Constant *UpperBound = ConstantExpr::getAdd(NegLo, Leaf.High); - Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_ULE, Add, UpperBound, + Comp = new ICmpInst(*NewLeaf, Predicate::ICMP_ULE, Add, UpperBound, "SwitchLeaf"); } } Index: lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- lib/Transforms/Utils/SimplifyCFG.cpp +++ lib/Transforms/Utils/SimplifyCFG.cpp @@ -447,7 +447,8 @@ // Pattern match a special case // (x & ~2^z) == y --> x == y || x == y|2^z // This undoes a transformation done by instcombine to fuse 2 compares. - if (ICI->getPredicate() == (isEQ ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_NE)) { + if (ICI->getPredicate() == + (isEQ ? Predicate::ICMP_EQ : Predicate::ICMP_NE)) { // It's a little bit hard to see why the following transformations are // correct. Here is a CVC3 program to verify them for 64-bit values: @@ -683,10 +684,11 @@ BranchInst *BI = cast(TI); ICmpInst *ICI = cast(BI->getCondition()); - BasicBlock *Succ = BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_NE); + BasicBlock *Succ = + BI->getSuccessor(ICI->getPredicate() == Predicate::ICMP_NE); Cases.push_back(ValueEqualityComparisonCase( GetConstantInt(ICI->getOperand(1), DL), Succ)); - return BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_EQ); + return BI->getSuccessor(ICI->getPredicate() == Predicate::ICMP_EQ); } /// Given a vector of bb/value pairs, remove any entries @@ -920,7 +922,7 @@ if (BranchInst *BI = dyn_cast(TI)) { assert(Weights.size() == 2); ICmpInst *ICI = cast(BI->getCondition()); - if (ICI->getPredicate() == ICmpInst::ICMP_EQ) + if (ICI->getPredicate() == Predicate::ICMP_EQ) std::swap(Weights.front(), Weights.back()); } } @@ -3184,7 +3186,7 @@ // and zap it. if (SI->findCaseValue(Cst) != SI->case_default()) { Value *V; - if (ICI->getPredicate() == ICmpInst::ICMP_EQ) + if (ICI->getPredicate() == Predicate::ICMP_EQ) V = ConstantInt::getFalse(BB->getContext()); else V = ConstantInt::getTrue(BB->getContext()); @@ -3208,7 +3210,7 @@ Constant *DefaultCst = ConstantInt::getTrue(BB->getContext()); Constant *NewCst = ConstantInt::getFalse(BB->getContext()); - if (ICI->getPredicate() == ICmpInst::ICMP_EQ) + if (ICI->getPredicate() == Predicate::ICMP_EQ) std::swap(DefaultCst, NewCst); // Replace ICI (which is used by the PHI for the default value) with true or Index: lib/Transforms/Utils/SimplifyIndVar.cpp =================================================================== --- lib/Transforms/Utils/SimplifyIndVar.cpp +++ lib/Transforms/Utils/SimplifyIndVar.cpp @@ -149,12 +149,12 @@ /// comparisons against an induction variable. void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp, Value *IVOperand) { unsigned IVOperIdx = 0; - ICmpInst::Predicate Pred = ICmp->getPredicate(); + Predicate Pred = ICmp->getPredicate(); if (IVOperand != ICmp->getOperand(0)) { // Swapped assert(IVOperand == ICmp->getOperand(1) && "Can't find IVOperand"); IVOperIdx = 1; - Pred = ICmpInst::getSwappedPredicate(Pred); + Pred = Pred.getSwapped(); } // Get the SCEVs for the ICmp operands. @@ -166,7 +166,7 @@ S = SE->getSCEVAtScope(S, ICmpLoop); X = SE->getSCEVAtScope(X, ICmpLoop); - ICmpInst::Predicate InvariantPredicate; + Predicate InvariantPredicate; const SCEV *InvariantLHS, *InvariantRHS; // If the condition is always true or always false, replace it with @@ -175,7 +175,7 @@ ICmp->replaceAllUsesWith(ConstantInt::getTrue(ICmp->getContext())); DeadInsts.emplace_back(ICmp); DEBUG(dbgs() << "INDVARS: Eliminated comparison: " << *ICmp << '\n'); - } else if (SE->isKnownPredicate(ICmpInst::getInversePredicate(Pred), S, X)) { + } else if (SE->isKnownPredicate(Pred.getInverse(), S, X)) { ICmp->replaceAllUsesWith(ConstantInt::getFalse(ICmp->getContext())); DeadInsts.emplace_back(ICmp); DEBUG(dbgs() << "INDVARS: Eliminated comparison: " << *ICmp << '\n'); @@ -286,7 +286,7 @@ // i % n --> i if i is in [0,n). if ((!IsSigned || SE->isKnownNonNegative(S)) && - SE->isKnownPredicate(IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, + SE->isKnownPredicate(IsSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT, S, X)) Rem->replaceAllUsesWith(Rem->getOperand(0)); else { @@ -295,13 +295,12 @@ if (IsSigned && !SE->isKnownNonNegative(LessOne)) return; - if (!SE->isKnownPredicate(IsSigned ? - ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, - LessOne, X)) + if (!SE->isKnownPredicate( + IsSigned ? Predicate::ICMP_SLT : Predicate::ICMP_ULT, LessOne, X)) return; - ICmpInst *ICmp = new ICmpInst(Rem, ICmpInst::ICMP_EQ, - Rem->getOperand(0), Rem->getOperand(1)); + ICmpInst *ICmp = new ICmpInst(Rem, Predicate::ICMP_EQ, Rem->getOperand(0), + Rem->getOperand(1)); SelectInst *Sel = SelectInst::Create(ICmp, ConstantInt::get(Rem->getType(), 0), Index: lib/Transforms/Utils/SimplifyLibCalls.cpp =================================================================== --- lib/Transforms/Utils/SimplifyLibCalls.cpp +++ lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -668,8 +668,8 @@ // First check that the bit field access is within bounds. Value *C = B.CreateZExtOrTrunc(CI->getArgOperand(1), BitfieldC->getType()); - Value *Bounds = B.CreateICmp(ICmpInst::ICMP_ULT, C, B.getIntN(Width, Width), - "memchr.bounds"); + Value *Bounds = B.CreateICmp(Predicate::ICMP_ULT, C, + B.getIntN(Width, Width), "memchr.bounds"); // Create code that checks if the given bit is set in the field. Value *Shl = B.CreateShl(B.getIntN(Width, 1ULL), C); Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2807,7 +2807,7 @@ Value *Cmp = nullptr; if (IfPredicateStore) { Cmp = Builder.CreateExtractElement(Cond[Part], Builder.getInt32(Width)); - Cmp = Builder.CreateICmp(ICmpInst::ICMP_EQ, Cmp, + Cmp = Builder.CreateICmp(Predicate::ICMP_EQ, Cmp, ConstantInt::get(Cmp->getType(), 1)); } @@ -3233,7 +3233,7 @@ // all of the iterations in the first vector loop. // If (N - N%VF) == N, then we *don't* need to run the remainder. Value *CmpN = - CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, Count, + CmpInst::Create(Instruction::ICmp, Predicate::ICMP_EQ, Count, CountRoundDown, "cmp.n", MiddleBlock->getTerminator()); ReplaceInstWithInst(MiddleBlock->getTerminator(), BranchInst::Create(ExitBlock, ScalarPH, CmpN)); @@ -6444,7 +6444,7 @@ if (Cond[Part]->getType()->isVectorTy()) Cond[Part] = Builder.CreateExtractElement(Cond[Part], Builder.getInt32(0)); - Cmp = Builder.CreateICmp(ICmpInst::ICMP_EQ, Cond[Part], + Cmp = Builder.CreateICmp(Predicate::ICMP_EQ, Cond[Part], ConstantInt::get(Cond[Part]->getType(), 1)); } Index: lib/Transforms/Vectorize/SLPVectorizer.cpp =================================================================== --- lib/Transforms/Vectorize/SLPVectorizer.cpp +++ lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1246,7 +1246,7 @@ case Instruction::ICmp: case Instruction::FCmp: { // Check that all of the compares have the same predicate. - CmpInst::Predicate P0 = cast(VL0)->getPredicate(); + Predicate P0 = cast(VL0)->getPredicate(); Type *ComparedTy = cast(VL[0])->getOperand(0)->getType(); for (unsigned i = 1, e = VL.size(); i < e; ++i) { CmpInst *Cmp = cast(VL[i]); @@ -2341,7 +2341,7 @@ if (Value *V = alreadyVectorized(E->Scalars)) return V; - CmpInst::Predicate P0 = cast(VL0)->getPredicate(); + Predicate P0 = cast(VL0)->getPredicate(); Value *V; if (Opcode == Instruction::FCmp) V = Builder.CreateFCmp(P0, L, R); Index: tools/bugpoint/Miscompilation.cpp =================================================================== --- tools/bugpoint/Miscompilation.cpp +++ tools/bugpoint/Miscompilation.cpp @@ -869,7 +869,7 @@ // Check to see if we already looked up the value. Value *CachedVal = new LoadInst(Cache, "fpcache", EntryBB); - Value *IsNull = new ICmpInst(*EntryBB, ICmpInst::ICMP_EQ, CachedVal, + Value *IsNull = new ICmpInst(*EntryBB, Predicate::ICMP_EQ, CachedVal, NullPtr, "isNull"); BranchInst::Create(LookupBB, DoCallBB, IsNull, EntryBB); Index: tools/llvm-stress/llvm-stress.cpp =================================================================== --- tools/llvm-stress/llvm-stress.cpp +++ tools/llvm-stress/llvm-stress.cpp @@ -599,20 +599,20 @@ if (Val0->getType()->isPointerTy()) return; bool fp = Val0->getType()->getScalarType()->isFloatingPointTy(); - int op; + unsigned op; if (fp) { - op = Ran->Rand() % - (CmpInst::LAST_FCMP_PREDICATE - CmpInst::FIRST_FCMP_PREDICATE) + - CmpInst::FIRST_FCMP_PREDICATE; + op = Ran->Rand() % (Predicate::LAST_FCMP_PREDICATE - + Predicate::FIRST_FCMP_PREDICATE) + + Predicate::FIRST_FCMP_PREDICATE; } else { - op = Ran->Rand() % - (CmpInst::LAST_ICMP_PREDICATE - CmpInst::FIRST_ICMP_PREDICATE) + - CmpInst::FIRST_ICMP_PREDICATE; + op = Ran->Rand() % (Predicate::LAST_ICMP_PREDICATE - + Predicate::FIRST_ICMP_PREDICATE) + + Predicate::FIRST_ICMP_PREDICATE; } - Value *V = CmpInst::Create(fp ? Instruction::FCmp : Instruction::ICmp, - (CmpInst::Predicate)op, Val0, Val1, "Cmp", - BB->getTerminator()); + Value *V = + CmpInst::Create(fp ? Instruction::FCmp : Instruction::ICmp, + Predicate{op}, Val0, Val1, "Cmp", BB->getTerminator()); return PT->push_back(V); } }; Index: unittests/IR/ConstantRangeTest.cpp =================================================================== --- unittests/IR/ConstantRangeTest.cpp +++ unittests/IR/ConstantRangeTest.cpp @@ -552,7 +552,7 @@ TEST(ConstantRange, MakeAllowedICmpRegion) { // PR8250 ConstantRange SMax = ConstantRange(APInt::getSignedMaxValue(32)); - EXPECT_TRUE(ConstantRange::makeAllowedICmpRegion(ICmpInst::ICMP_SGT, SMax) + EXPECT_TRUE(ConstantRange::makeAllowedICmpRegion(Predicate::ICMP_SGT, SMax) .isEmptySet()); } @@ -561,51 +561,53 @@ ConstantRange HighHalf(APInt(8, 128), APInt(8, 0)); ConstantRange EmptySet(8, /* isFullSet = */ false); - EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_NE, LowHalf), - HighHalf); + EXPECT_EQ( + ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_NE, LowHalf), + HighHalf); EXPECT_EQ( - ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_NE, HighHalf), + ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_NE, HighHalf), LowHalf); - EXPECT_TRUE(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_EQ, - HighHalf).isEmptySet()); + EXPECT_TRUE( + ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_EQ, HighHalf) + .isEmptySet()); ConstantRange UnsignedSample(APInt(8, 5), APInt(8, 200)); - EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_ULT, + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_ULT, UnsignedSample), ConstantRange(APInt(8, 0), APInt(8, 5))); - EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_ULE, + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_ULE, UnsignedSample), ConstantRange(APInt(8, 0), APInt(8, 6))); - EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_UGT, + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_UGT, UnsignedSample), ConstantRange(APInt(8, 200), APInt(8, 0))); - EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_UGE, + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_UGE, UnsignedSample), ConstantRange(APInt(8, 199), APInt(8, 0))); ConstantRange SignedSample(APInt(8, -5), APInt(8, 5)); - EXPECT_EQ( - ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SLT, SignedSample), - ConstantRange(APInt(8, -128), APInt(8, -5))); + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_SLT, + SignedSample), + ConstantRange(APInt(8, -128), APInt(8, -5))); - EXPECT_EQ( - ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SLE, SignedSample), - ConstantRange(APInt(8, -128), APInt(8, -4))); + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_SLE, + SignedSample), + ConstantRange(APInt(8, -128), APInt(8, -4))); - EXPECT_EQ( - ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SGT, SignedSample), - ConstantRange(APInt(8, 5), APInt(8, -128))); + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_SGT, + SignedSample), + ConstantRange(APInt(8, 5), APInt(8, -128))); - EXPECT_EQ( - ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SGE, SignedSample), - ConstantRange(APInt(8, 4), APInt(8, -128))); + EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(Predicate::ICMP_SGE, + SignedSample), + ConstantRange(APInt(8, 4), APInt(8, -128))); } TEST(ConstantRange, MakeGuaranteedNoWrapRegion) { @@ -718,36 +720,36 @@ TEST(ConstantRange, GetEquivalentICmp) { APInt RHS; - CmpInst::Predicate Pred; + Predicate Pred; EXPECT_TRUE(ConstantRange(APInt::getMinValue(32), APInt(32, 100)) .getEquivalentICmp(Pred, RHS)); - EXPECT_EQ(Pred, CmpInst::ICMP_ULT); + EXPECT_EQ(Pred, Predicate::ICMP_ULT); EXPECT_EQ(RHS, APInt(32, 100)); EXPECT_TRUE(ConstantRange(APInt::getSignedMinValue(32), APInt(32, 100)) .getEquivalentICmp(Pred, RHS)); - EXPECT_EQ(Pred, CmpInst::ICMP_SLT); + EXPECT_EQ(Pred, Predicate::ICMP_SLT); EXPECT_EQ(RHS, APInt(32, 100)); EXPECT_TRUE(ConstantRange(APInt(32, 100), APInt::getMinValue(32)) .getEquivalentICmp(Pred, RHS)); - EXPECT_EQ(Pred, CmpInst::ICMP_UGE); + EXPECT_EQ(Pred, Predicate::ICMP_UGE); EXPECT_EQ(RHS, APInt(32, 100)); EXPECT_TRUE(ConstantRange(APInt(32, 100), APInt::getSignedMinValue(32)) .getEquivalentICmp(Pred, RHS)); - EXPECT_EQ(Pred, CmpInst::ICMP_SGE); + EXPECT_EQ(Pred, Predicate::ICMP_SGE); EXPECT_EQ(RHS, APInt(32, 100)); EXPECT_TRUE( ConstantRange(32, /*isFullSet=*/true).getEquivalentICmp(Pred, RHS)); - EXPECT_EQ(Pred, CmpInst::ICMP_UGE); + EXPECT_EQ(Pred, Predicate::ICMP_UGE); EXPECT_EQ(RHS, APInt(32, 0)); EXPECT_TRUE( ConstantRange(32, /*isFullSet=*/false).getEquivalentICmp(Pred, RHS)); - EXPECT_EQ(Pred, CmpInst::ICMP_ULT); + EXPECT_EQ(Pred, Predicate::ICMP_ULT); EXPECT_EQ(RHS, APInt(32, 0)); EXPECT_FALSE(ConstantRange(APInt(32, 100), APInt(32, 200)) Index: unittests/IR/ConstantsTest.cpp =================================================================== --- unittests/IR/ConstantsTest.cpp +++ unittests/IR/ConstantsTest.cpp @@ -270,10 +270,10 @@ CHECK(ConstantExpr::getSelect(P3, P0, P4), "select i1 " P3STR ", i32 " P0STR ", i32 " P4STR); - CHECK(ConstantExpr::getICmp(CmpInst::ICMP_EQ, P0, P4), "icmp eq i32 " P0STR - ", " P4STR); - CHECK(ConstantExpr::getFCmp(CmpInst::FCMP_ULT, P1, P5), "fcmp ult float " - P1STR ", " P5STR); + CHECK(ConstantExpr::getICmp(Predicate::ICMP_EQ, P0, P4), + "icmp eq i32 " P0STR ", " P4STR); + CHECK(ConstantExpr::getFCmp(Predicate::FCMP_ULT, P1, P5), + "fcmp ult float " P1STR ", " P5STR); std::vector V; V.push_back(One); Index: unittests/IR/InstructionsTest.cpp =================================================================== --- unittests/IR/InstructionsTest.cpp +++ unittests/IR/InstructionsTest.cpp @@ -315,13 +315,13 @@ CastInst *PtrVecA = new IntToPtrInst(C2xi32a, V2xi32PTy); CastInst *PtrVecB = new IntToPtrInst(C2xi32b, V2xi32PTy); - ICmpInst *ICmp0 = new ICmpInst(ICmpInst::ICMP_SGT, PtrVecA, PtrVecB); - ICmpInst *ICmp1 = new ICmpInst(ICmpInst::ICMP_ULT, PtrVecA, PtrVecB); + ICmpInst *ICmp0 = new ICmpInst(Predicate::ICMP_SGT, PtrVecA, PtrVecB); + ICmpInst *ICmp1 = new ICmpInst(Predicate::ICMP_ULT, PtrVecA, PtrVecB); EXPECT_NE(ICmp0, ICmp1); // suppress warning. BasicBlock* BB0 = BasicBlock::Create(C); // Test InsertAtEnd ICmpInst constructor. - ICmpInst *ICmp2 = new ICmpInst(*BB0, ICmpInst::ICMP_SGE, PtrVecA, PtrVecB); + ICmpInst *ICmp2 = new ICmpInst(*BB0, Predicate::ICMP_SGE, PtrVecA, PtrVecB); EXPECT_NE(ICmp0, ICmp2); // suppress warning. GetElementPtrInst *Gep0 = GetElementPtrInst::Create(I32Ty, PtrVecA, C2xi32a);