|
LLVM
4.0.0
|
#include "InstCombineInternal.h"#include "llvm/Analysis/InstructionSimplify.h"#include "llvm/IR/ConstantRange.h"#include "llvm/IR/Intrinsics.h"#include "llvm/IR/PatternMatch.h"#include "llvm/Transforms/Utils/CmpInstAnalysis.h"#include "llvm/Transforms/Utils/Local.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "instcombine" |
Enumerations | |
| enum | MaskedICmpType { FoldMskICmp_AMask_AllOnes = 1, FoldMskICmp_AMask_NotAllOnes = 2, FoldMskICmp_BMask_AllOnes = 4, FoldMskICmp_BMask_NotAllOnes = 8, FoldMskICmp_Mask_AllZeroes = 16, FoldMskICmp_Mask_NotAllZeroes = 32, FoldMskICmp_AMask_Mixed = 64, FoldMskICmp_AMask_NotMixed = 128, FoldMskICmp_BMask_Mixed = 256, FoldMskICmp_BMask_NotMixed = 512 } |
| enum for classifying (icmp eq (A & B), C) and (icmp ne (A & B), C) One of A and B is considered the mask, the other the value. More... | |
Functions | |
| static Value * | dyn_castNotVal (Value *V) |
| static unsigned | getFCmpCode (FCmpInst::Predicate CC) |
| Similar to getICmpCode but for FCmpInst. More... | |
| static Value * | getNewICmpValue (bool Sign, unsigned Code, Value *LHS, Value *RHS, InstCombiner::BuilderTy *Builder) |
| This is the complement of getICmpCode, which turns an opcode and two operands into either a constant true or false, or a brand new ICmp instruction. More... | |
| static Value * | getFCmpValue (unsigned Code, Value *LHS, Value *RHS, InstCombiner::BuilderTy *Builder) |
| This is the complement of getFCmpCode, which turns an opcode and two operands into either a FCmp instruction, or a true/false constant. More... | |
| static bool | isRunOfOnes (ConstantInt *Val, uint32_t &MB, uint32_t &ME) |
| Returns true iff Val consists of one contiguous run of 1s with any number of 0s on either side. More... | |
| static unsigned | getTypeOfMaskedICmp (Value *A, Value *B, Value *C, ICmpInst::Predicate SCC) |
| Return the set of pattern classes (from MaskedICmpType) that (icmp SCC (A & B), C) satisfies. More... | |
| static unsigned | conjugateICmpMask (unsigned Mask) |
| Convert an analysis of a masked ICmp into its equivalent if all boolean operations had the opposite sense. More... | |
| static unsigned | foldLogOpOfMaskedICmpsHelper (Value *&A, Value *&B, Value *&C, Value *&D, Value *&E, ICmpInst *LHS, ICmpInst *RHS, ICmpInst::Predicate &LHSCC, ICmpInst::Predicate &RHSCC) |
| Handle (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) Return the set of pattern classes (from MaskedICmpType) that both LHS and RHS satisfy. More... | |
| static Value * | foldLogOpOfMaskedICmps (ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, llvm::InstCombiner::BuilderTy *Builder) |
| Try to fold (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) into a single (icmp(A & X) ==/!= Y). More... | |
| static Instruction * | matchDeMorgansLaws (BinaryOperator &I, InstCombiner::BuilderTy *Builder) |
| Match De Morgan's Laws: (~A & ~B) == (~(A | B)) (~A | ~B) == (~(A & B)) More... | |
| static Instruction * | foldLogicCastConstant (BinaryOperator &Logic, CastInst *Cast, InstCombiner::BuilderTy *Builder) |
| Fold {and,or,xor} (cast X), C. More... | |
| static Instruction * | foldBoolSextMaskToSelect (BinaryOperator &I) |
| static bool | areInverseVectorBitmasks (Constant *C1, Constant *C2) |
| If all elements of two constant vectors are 0/-1 and inverses, return true. More... | |
| static Value * | getSelectCondition (Value *A, Value *B, InstCombiner::BuilderTy &Builder) |
| We have an expression of the form (A & C) | (B & D). More... | |
| static Value * | matchSelectFromAndOr (Value *A, Value *C, Value *B, Value *D, InstCombiner::BuilderTy &Builder) |
| We have an expression of the form (A & C) | (B & D). More... | |
| #define DEBUG_TYPE "instcombine" |
Definition at line 24 of file InstCombineAndOrXor.cpp.
| enum MaskedICmpType |
enum for classifying (icmp eq (A & B), C) and (icmp ne (A & B), C) One of A and B is considered the mask, the other the value.
This is described as the "AMask" or "BMask" part of the enum. If the enum contains only "Mask", then both A and B can be considered masks. If A is the mask, then it was proven, that (A & C) == C. This is trivial if C == A, or C == 0. If both A and C are constants, this proof is also easy. For the following explanations we assume that A is the mask. The part "AllOnes" declares, that the comparison is true only if (A & B) == A, or all bits of A are set in B. Example: (icmp eq (A & 3), 3) -> FoldMskICmp_AMask_AllOnes The part "AllZeroes" declares, that the comparison is true only if (A & B) == 0, or all bits of A are cleared in B. Example: (icmp eq (A & 3), 0) -> FoldMskICmp_Mask_AllZeroes The part "Mixed" declares, that (A & B) == C and C might or might not contain any number of one bits and zero bits. Example: (icmp eq (A & 3), 1) -> FoldMskICmp_AMask_Mixed The Part "Not" means, that in above descriptions "==" should be replaced by "!=". Example: (icmp ne (A & 3), 3) -> FoldMskICmp_AMask_NotAllOnes If the mask A contains a single bit, then the following is equivalent: (icmp eq (A & B), A) equals (icmp ne (A & B), 0) (icmp ne (A & B), A) equals (icmp eq (A & B), 0)
Definition at line 399 of file InstCombineAndOrXor.cpp.
If all elements of two constant vectors are 0/-1 and inverses, return true.
Definition at line 1545 of file InstCombineAndOrXor.cpp.
References llvm::Constant::getAggregateElement(), llvm::Value::getType(), llvm::Type::getVectorNumElements(), i, llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_Zero(), and llvm::PatternMatch::match().
Referenced by getSelectCondition().
Convert an analysis of a masked ICmp into its equivalent if all boolean operations had the opposite sense.
Since each "NotXXX" flag (recording !=) is adjacent to the corresponding normal flag (recording ==), this just involves swapping those bits over.
Definition at line 483 of file InstCombineAndOrXor.cpp.
References FoldMskICmp_AMask_AllOnes, FoldMskICmp_AMask_Mixed, FoldMskICmp_AMask_NotAllOnes, FoldMskICmp_AMask_NotMixed, FoldMskICmp_BMask_AllOnes, FoldMskICmp_BMask_Mixed, FoldMskICmp_BMask_NotAllOnes, FoldMskICmp_BMask_NotMixed, FoldMskICmp_Mask_AllZeroes, and FoldMskICmp_Mask_NotAllZeroes.
Referenced by foldLogOpOfMaskedICmps().
Definition at line 26 of file InstCombineAndOrXor.cpp.
References C, llvm::ConstantInt::get(), llvm::BinaryOperator::getNotArgument(), llvm::Value::hasOneUse(), llvm::IsFreeToInvert(), and llvm::BinaryOperator::isNot().
Referenced by matchDeMorgansLaws(), and llvm::InstCombiner::visitXor().
|
static |
Definition at line 1235 of file InstCombineAndOrXor.cpp.
References llvm::SelectInst::Create(), llvm::Constant::getNullValue(), llvm::User::getOperand(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::Type::isIntegerTy(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), std::swap(), and Zero.
Referenced by llvm::InstCombiner::visitAnd().
|
static |
Fold {and,or,xor} (cast X), C.
Definition at line 1127 of file InstCombineAndOrXor.cpp.
References C, llvm::IRBuilder< T, Inserter >::CreateBinOp(), llvm::CastInst::CreateBitOrPointerCast(), llvm::ConstantExpr::getBitCast(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::CastInst::getSrcTy(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), llvm::ConstantExpr::getZExt(), llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), and X.
|
static |
Try to fold (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) into a single (icmp(A & X) ==/!= Y).
Definition at line 616 of file InstCombineAndOrXor.cpp.
References A, assert(), B, C, conjugateICmpMask(), llvm::IRBuilder< T, Inserter >::CreateAnd(), llvm::IRBuilder< T, Inserter >::CreateICmp(), llvm::IRBuilder< T, Inserter >::CreateOr(), D, llvm::dyn_cast(), E, foldLogOpOfMaskedICmpsHelper(), FoldMskICmp_AMask_AllOnes, FoldMskICmp_AMask_NotAllOnes, FoldMskICmp_BMask_AllOnes, FoldMskICmp_BMask_Mixed, FoldMskICmp_BMask_NotAllOnes, FoldMskICmp_Mask_AllZeroes, FoldMskICmp_Mask_NotAllZeroes, llvm::ConstantInt::get(), llvm::Constant::getNullValue(), llvm::ConstantExpr::getOr(), llvm::CmpInst::getPredicate(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::ConstantExpr::getXor(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::ICmpInst::isEquality(), and Zero.
Referenced by llvm::InstCombiner::FoldAndOfICmps(), and llvm::InstCombiner::FoldOrOfICmps().
|
static |
Handle (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) Return the set of pattern classes (from MaskedICmpType) that both LHS and RHS satisfy.
Definition at line 502 of file InstCombineAndOrXor.cpp.
References llvm::decomposeBitTestICmp(), llvm::Constant::getAllOnesValue(), llvm::User::getOperand(), llvm::Value::getType(), getTypeOfMaskedICmp(), llvm::ICmpInst::isEquality(), llvm::Type::isIntegerTy(), llvm::Type::isVectorTy(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and R2.
Referenced by foldLogOpOfMaskedICmps().
|
static |
Similar to getICmpCode but for FCmpInst.
This encodes a fcmp predicate into a four bit mask.
Definition at line 43 of file InstCombineAndOrXor.cpp.
References assert(), llvm::CmpInst::FCMP_FALSE, llvm::CmpInst::FCMP_OEQ, llvm::CmpInst::FCMP_OGE, llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLE, llvm::CmpInst::FCMP_OLT, llvm::CmpInst::FCMP_ONE, llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_TRUE, llvm::CmpInst::FCMP_UEQ, llvm::CmpInst::FCMP_UGE, llvm::CmpInst::FCMP_UGT, llvm::CmpInst::FCMP_ULE, llvm::CmpInst::FCMP_ULT, llvm::CmpInst::FCMP_UNE, and llvm::CmpInst::FCMP_UNO.
Referenced by llvm::InstCombiner::FoldAndOfFCmps(), and llvm::InstCombiner::FoldOrOfFCmps().
|
static |
This is the complement of getFCmpCode, which turns an opcode and two operands into either a FCmp instruction, or a true/false constant.
Definition at line 81 of file InstCombineAndOrXor.cpp.
References assert(), llvm::IRBuilder< T, Inserter >::CreateFCmp(), llvm::CmpInst::FCMP_FALSE, llvm::CmpInst::FCMP_TRUE, llvm::ConstantInt::get(), llvm::Value::getType(), and llvm::CmpInst::makeCmpResultType().
Referenced by llvm::InstCombiner::FoldAndOfFCmps(), and llvm::InstCombiner::FoldOrOfFCmps().
|
static |
This is the complement of getICmpCode, which turns an opcode and two operands into either a constant true or false, or a brand new ICmp instruction.
The sign is passed in to determine which kind of predicate to use in the new icmp instruction.
Definition at line 71 of file InstCombineAndOrXor.cpp.
References llvm::IRBuilder< T, Inserter >::CreateICmp(), and llvm::getICmpValue().
Referenced by llvm::InstCombiner::FoldAndOfICmps(), llvm::InstCombiner::FoldOrOfICmps(), and llvm::InstCombiner::visitXor().
|
static |
We have an expression of the form (A & C) | (B & D).
If A is a scalar or vector composed of all-zeros or all-ones values and is the bitwise 'not' of B, it can be used as the condition operand of a select instruction.
Definition at line 1565 of file InstCombineAndOrXor.cpp.
References areInverseVectorBitmasks(), llvm::IRBuilder< T, Inserter >::CreateXor(), llvm::Type::getScalarType(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), llvm::Type::isIntegerTy(), llvm::Type::isVectorTy(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::CmpInst::makeCmpResultType(), and llvm::PatternMatch::match().
Referenced by matchSelectFromAndOr().
|
static |
Return the set of pattern classes (from MaskedICmpType) that (icmp SCC (A & B), C) satisfies.
Definition at line 414 of file InstCombineAndOrXor.cpp.
References A, B, C, llvm::dyn_cast(), FoldMskICmp_AMask_AllOnes, FoldMskICmp_AMask_Mixed, FoldMskICmp_AMask_NotAllOnes, FoldMskICmp_AMask_NotMixed, FoldMskICmp_BMask_AllOnes, FoldMskICmp_BMask_Mixed, FoldMskICmp_BMask_NotAllOnes, FoldMskICmp_BMask_NotMixed, FoldMskICmp_Mask_AllZeroes, FoldMskICmp_Mask_NotAllZeroes, llvm::ConstantExpr::getAnd(), llvm::ConstantInt::getValue(), llvm::CmpInst::ICMP_EQ, llvm::APInt::isPowerOf2(), and llvm::ConstantInt::isZero().
Referenced by foldLogOpOfMaskedICmpsHelper().
|
static |
Returns true iff Val consists of one contiguous run of 1s with any number of 0s on either side.
The 1s are allowed to wrap from LSB to MSB, so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is not, since all 1s are not contiguous.
Definition at line 309 of file InstCombineAndOrXor.cpp.
References llvm::APInt::getActiveBits(), llvm::IntegerType::getBitWidth(), llvm::ConstantInt::getType(), llvm::ConstantInt::getValue(), and llvm::APIntOps::isShiftedMask().
|
static |
Match De Morgan's Laws: (~A & ~B) == (~(A | B)) (~A | ~B) == (~(A & B))
Definition at line 1079 of file InstCombineAndOrXor.cpp.
References llvm::APIntOps::And(), assert(), llvm::IRBuilder< T, Inserter >::CreateBinOp(), llvm::BinaryOperator::CreateNot(), dyn_castNotVal(), llvm::Value::getName(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Value::hasOneUse(), and llvm::APIntOps::Or().
Referenced by llvm::InstCombiner::visitAnd(), and llvm::InstCombiner::visitOr().
|
static |
We have an expression of the form (A & C) | (B & D).
Try to simplify this to "A' ? C : D", where A' is a boolean or vector of booleans.
Definition at line 1605 of file InstCombineAndOrXor.cpp.
References llvm::IRBuilder< T, Inserter >::CreateBitCast(), llvm::IRBuilder< T, Inserter >::CreateSelect(), getSelectCondition(), llvm::Value::getType(), llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and llvm::MCID::Select.
Referenced by llvm::InstCombiner::visitOr().
1.8.6