From 7af96fb3afd6725a2824a0a5ca5dad34e5e0b056 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 17 May 2017 20:22:39 +0000 Subject: Vendor import of llvm trunk r303291: https://llvm.org/svn/llvm-project/llvm/trunk@303291 --- lib/Transforms/InstCombine/InstCombineInternal.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/Transforms/InstCombine/InstCombineInternal.h') diff --git a/lib/Transforms/InstCombine/InstCombineInternal.h b/lib/Transforms/InstCombine/InstCombineInternal.h index 1424f61fe7017..f88a2c6acc3f8 100644 --- a/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/lib/Transforms/InstCombine/InstCombineInternal.h @@ -74,6 +74,27 @@ static inline unsigned getComplexity(Value *V) { return isa(V) ? (isa(V) ? 0 : 1) : 2; } +/// Predicate canonicalization reduces the number of patterns that need to be +/// matched by other transforms. For example, we may swap the operands of a +/// conditional branch or select to create a compare with a canonical (inverted) +/// predicate which is then more likely to be matched with other values. +static inline bool isCanonicalPredicate(CmpInst::Predicate Pred) { + switch (Pred) { + case CmpInst::ICMP_NE: + case CmpInst::ICMP_ULE: + case CmpInst::ICMP_SLE: + case CmpInst::ICMP_UGE: + case CmpInst::ICMP_SGE: + // TODO: There are 16 FCMP predicates. Should others be (not) canonical? + case CmpInst::FCMP_ONE: + case CmpInst::FCMP_OLE: + case CmpInst::FCMP_OGE: + return false; + default: + return true; + } +} + /// \brief Add one to a Constant static inline Constant *AddOne(Constant *C) { return ConstantExpr::getAdd(C, ConstantInt::get(C->getType(), 1)); -- cgit v1.2.3