LLVM
15.0.0git
|
#include "InstCombineInternal.h"
#include "llvm/Analysis/CmpInstAnalysis.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Transforms/InstCombine/InstCombiner.h"
#include "llvm/Transforms/Utils/Local.h"
Go to the source code of this file.
Classes | |
struct | IntPart |
Macros | |
#define | DEBUG_TYPE "instcombine" |
Enumerations | |
enum | MaskedICmpType { AMask_AllOnes = 1, AMask_NotAllOnes = 2, BMask_AllOnes = 4, BMask_NotAllOnes = 8, Mask_AllZeros = 16, Mask_NotAllZeros = 32, AMask_Mixed = 64, AMask_NotMixed = 128, BMask_Mixed = 256, BMask_NotMixed = 512 } |
Classify (icmp eq (A & B), C) and (icmp ne (A & B), C) as matching patterns that can be simplified. More... | |
Functions | |
static Value * | getNewICmpValue (unsigned Code, bool Sign, 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 Value * | SimplifyBSwap (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
Transform BITWISE_OP(BSWAP(A),BSWAP(B)) or BITWISE_OP(BSWAP(A), Constant) to BSWAP(BITWISE_OP(A, B)) More... | |
static unsigned | getMaskedICmpType (Value *A, Value *B, Value *C, ICmpInst::Predicate Pred) |
Return the set of patterns (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 bool | decomposeBitTestICmp (Value *LHS, Value *RHS, CmpInst::Predicate &Pred, Value *&X, Value *&Y, Value *&Z) |
static Optional< std::pair< unsigned, unsigned > > | getMaskedTypeForICmpPair (Value *&A, Value *&B, Value *&C, Value *&D, Value *&E, ICmpInst *LHS, ICmpInst *RHS, ICmpInst::Predicate &PredL, ICmpInst::Predicate &PredR) |
Handle (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E). More... | |
static Value * | foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed (ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, Value *A, Value *B, Value *C, Value *D, Value *E, ICmpInst::Predicate PredL, ICmpInst::Predicate PredR, InstCombiner::BuilderTy &Builder) |
Try to fold (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) into a single (icmp(A & X) ==/!= Y), where the left-hand side is of type Mask_NotAllZeros and the right hand side is of type BMask_Mixed. More... | |
static Value * | foldLogOpOfMaskedICmpsAsymmetric (ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, Value *A, Value *B, Value *C, Value *D, Value *E, ICmpInst::Predicate PredL, ICmpInst::Predicate PredR, unsigned LHSMask, unsigned RHSMask, InstCombiner::BuilderTy &Builder) |
Try to fold (icmp(A & B) ==/!= 0) &/| (icmp(A & D) ==/!= E) into a single (icmp(A & X) ==/!= Y), where the left-hand side and the right hand side aren't of the common mask pattern type. More... | |
static Value * | foldLogOpOfMaskedICmps (ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, bool IsLogical, InstCombiner::BuilderTy &Builder) |
Try to fold (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) into a single (icmp(A & X) ==/!= Y). More... | |
static Value * | foldSignedTruncationCheck (ICmpInst *ICmp0, ICmpInst *ICmp1, Instruction &CxtI, InstCombiner::BuilderTy &Builder) |
General pattern: X & Y. More... | |
static Value * | foldIsPowerOf2OrZero (ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd, InstCombiner::BuilderTy &Builder) |
Fold (icmp eq ctpop(X) 1) | (icmp eq X 0) into (icmp ult ctpop(X) 2) and fold (icmp ne ctpop(X) 1) & (icmp ne X 0) into (icmp ugt ctpop(X) 1). More... | |
static Value * | foldIsPowerOf2 (ICmpInst *Cmp0, ICmpInst *Cmp1, bool JoinedByAnd, InstCombiner::BuilderTy &Builder) |
Reduce a pair of compares that check if a value has exactly 1 bit set. More... | |
static Value * | foldUnsignedUnderflowCheck (ICmpInst *ZeroICmp, ICmpInst *UnsignedICmp, bool IsAnd, const SimplifyQuery &Q, InstCombiner::BuilderTy &Builder) |
Commuted variants are assumed to be handled by calling this function again with the parameters swapped. More... | |
static Optional< IntPart > | matchIntPart (Value *V) |
Match an extraction of bits from an integer. More... | |
static Value * | extractIntPart (const IntPart &P, IRBuilderBase &Builder) |
Materialize an extraction of bits from an integer in IR. More... | |
static Value * | foldAndOrOfICmpsWithConstEq (ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd, InstCombiner::BuilderTy &Builder, const SimplifyQuery &Q) |
Reduce logic-of-compares with equality to a constant by substituting a common operand with the constant. More... | |
static Instruction * | reassociateFCmps (BinaryOperator &BO, InstCombiner::BuilderTy &Builder) |
This a limited reassociation for a special case (see above) where we are checking if two values are either both NAN (unordered) or not-NAN (ordered). More... | |
static Instruction * | matchDeMorgansLaws (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
Match variations of 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 * | foldAndToXor (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
static Instruction * | foldOrToXor (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
static bool | canNarrowShiftAmt (Constant *C, unsigned BitWidth) |
Return true if a constant shift amount is always less than the specified bit-width. More... | |
static Instruction * | foldComplexAndOrPatterns (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
Try folding relatively complex patterns for both And and Or operations with all And and Or swapped. More... | |
static Instruction * | matchFunnelShift (Instruction &Or, InstCombinerImpl &IC) |
Match UB-safe variants of the funnel shift intrinsic. More... | |
static Instruction * | matchOrConcat (Instruction &Or, InstCombiner::BuilderTy &Builder) |
Attempt to combine or(zext(x),shl(zext(y),bw/2) concat packing patterns. More... | |
static bool | areInverseVectorBitmasks (Constant *C1, Constant *C2) |
If all elements of two constant vectors are 0/-1 and inverses, return true. More... | |
Value * | foldAndOrOfICmpEqZeroAndICmp (ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, IRBuilderBase &Builder) |
static Instruction * | foldXorToXor (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
A ^ B can be specified using other logic ops in a variety of patterns. More... | |
static Instruction * | visitMaskedMerge (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
If we have a masked merge, in the canonical form of: (assuming that A only has one use.) | A | |B| ((x ^ y) & M) ^ y | D |. More... | |
static Instruction * | sinkNotIntoXor (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
static Instruction * | canonicalizeAbs (BinaryOperator &Xor, InstCombiner::BuilderTy &Builder) |
Canonicalize a shifty way to code absolute value to the more common pattern that uses negation and select. More... | |
#define DEBUG_TYPE "instcombine" |
Definition at line 25 of file InstCombineAndOrXor.cpp.
enum MaskedICmpType |
Classify (icmp eq (A & B), C) and (icmp ne (A & B), C) as matching patterns that can be simplified.
One of A and B is considered the mask. The other is 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.
"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) -> AMask_AllOnes
"AllZeros" 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) -> Mask_AllZeroes
"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) -> AMask_Mixed
"Not" means that in above descriptions "==" should be replaced by "!=". Example: (icmp ne (A & 3), 3) -> 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)
Enumerator | |
---|---|
AMask_AllOnes | |
AMask_NotAllOnes | |
BMask_AllOnes | |
BMask_NotAllOnes | |
Mask_AllZeros | |
Mask_NotAllZeros | |
AMask_Mixed | |
AMask_NotMixed | |
BMask_Mixed | |
BMask_NotMixed |
Definition at line 141 of file InstCombineAndOrXor.cpp.
If all elements of two constant vectors are 0/-1 and inverses, return true.
Definition at line 2358 of file InstCombineAndOrXor.cpp.
References C1, llvm::Constant::getAggregateElement(), i, llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_Zero(), and llvm::PatternMatch::match().
|
static |
Return true if a constant shift amount is always less than the specified bit-width.
If not, the shift could create poison in the narrower type.
Definition at line 1538 of file InstCombineAndOrXor.cpp.
References llvm::BitWidth, llvm::CmpInst::ICMP_ULT, llvm::PatternMatch::m_SpecificInt_ICMP(), and llvm::PatternMatch::match().
|
static |
Canonicalize a shifty way to code absolute value to the more common pattern that uses negation and select.
Definition at line 3349 of file InstCombineAndOrXor.cpp.
References assert(), Builder, llvm::SelectInst::Create(), llvm::Type::getScalarSizeInBits(), llvm::Value::hasNUses(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_AShr(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), std::swap(), and llvm::Xor.
Referenced by llvm::InstCombinerImpl::visitXor().
|
static |
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 206 of file InstCombineAndOrXor.cpp.
References AMask_AllOnes, AMask_Mixed, AMask_NotAllOnes, AMask_NotMixed, BMask_AllOnes, BMask_Mixed, BMask_NotAllOnes, BMask_NotMixed, llvm::BitmaskEnumDetail::Mask(), Mask_AllZeros, and Mask_NotAllZeros.
Referenced by foldLogOpOfMaskedICmps(), and foldLogOpOfMaskedICmpsAsymmetric().
|
static |
Definition at line 220 of file InstCombineAndOrXor.cpp.
References llvm::decomposeBitTestICmp(), llvm::ConstantInt::get(), LHS, llvm::BitmaskEnumDetail::Mask(), RHS, X, and Y.
|
static |
Materialize an extraction of bits from an integer in IR.
Definition at line 1037 of file InstCombineAndOrXor.cpp.
References Builder, llvm::Value::getType(), llvm::Type::getWithNewBitWidth(), and P.
Value* foldAndOrOfICmpEqZeroAndICmp | ( | ICmpInst * | LHS, |
ICmpInst * | RHS, | ||
bool | IsAnd, | ||
IRBuilderBase & | Builder | ||
) |
Definition at line 2486 of file InstCombineAndOrXor.cpp.
References Builder, llvm::Constant::getAllOnesValue(), llvm::Value::getType(), llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::Type::isIntOrIntVectorTy(), LHS, llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), Other, and RHS.
|
static |
Reduce logic-of-compares with equality to a constant by substituting a common operand with the constant.
Callers are expected to call this with Cmp0/Cmp1 switched to handle logic op commutativity.
Definition at line 1096 of file InstCombineAndOrXor.cpp.
References Builder, llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::isGuaranteedNotToBeUndefOrPoison(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::simplifyICmpInst(), X, and Y.
|
static |
Definition at line 1476 of file InstCombineAndOrXor.cpp.
References assert(), B, Builder, llvm::BinaryOperator::CreateNot(), llvm::Value::hasOneUse(), I, llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombinerImpl::visitAnd().
|
static |
Try folding relatively complex patterns for both And and Or operations with all And and Or swapped.
Definition at line 1586 of file InstCombineAndOrXor.cpp.
References assert(), B, Builder, llvm::BinaryOperator::Create(), llvm::BinaryOperator::CreateNot(), llvm::NVPTXISD::Dummy, llvm::Value::hasOneUse(), I, llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Or, X, llvm::Xor, and Y.
Referenced by llvm::InstCombinerImpl::visitAnd(), and llvm::InstCombinerImpl::visitOr().
|
static |
Reduce a pair of compares that check if a value has exactly 1 bit set.
Also used for logical and/or, must be poison safe.
Definition at line 905 of file InstCombineAndOrXor.cpp.
References Builder, llvm::ConstantInt::get(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZeroInt(), llvm::PatternMatch::match(), std::swap(), and X.
|
static |
Fold (icmp eq ctpop(X) 1) | (icmp eq X 0) into (icmp ult ctpop(X) 2) and fold (icmp ne ctpop(X) 1) & (icmp ne X 0) into (icmp ugt ctpop(X) 1).
Also used for logical and/or, must be poison safe.
Definition at line 885 of file InstCombineAndOrXor.cpp.
References Builder, llvm::ConstantInt::get(), llvm::User::getOperand(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZeroInt(), llvm::PatternMatch::match(), and X.
|
static |
Fold {and,or,xor} (cast X), C.
Definition at line 1371 of file InstCombineAndOrXor.cpp.
References Builder, llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::ConstantExpr::getSExt(), llvm::CastInst::getSrcTy(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), llvm::ConstantExpr::getZExt(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_SExt(), 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 524 of file InstCombineAndOrXor.cpp.
References AMask_AllOnes, AMask_NotAllOnes, assert(), B, BMask_AllOnes, BMask_Mixed, BMask_NotAllOnes, Builder, conjugateICmpMask(), D, E, foldLogOpOfMaskedICmpsAsymmetric(), llvm::ConstantInt::get(), getMaskedTypeForICmpPair(), llvm::Constant::getNullValue(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::ICmpInst::isEquality(), llvm::isGuaranteedNotToBeUndefOrPoison(), llvm::SystemZII::IsLogical, LHS, llvm::PatternMatch::m_APInt(), llvm::BitmaskEnumDetail::Mask(), Mask_AllZeros, Mask_NotAllZeros, llvm::PatternMatch::match(), and RHS.
|
static |
Try to fold (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) into a single (icmp(A & X) ==/!= Y), where the left-hand side is of type Mask_NotAllZeros and the right hand side is of type BMask_Mixed.
For example, (icmp (A & 12) != 0) & (icmp (A & 15) == 8) -> (icmp (A & 15) == 8). Also used for logical and/or, must be poison safe.
Definition at line 369 of file InstCombineAndOrXor.cpp.
References assert(), B, Builder, C1, D, E, llvm::ConstantInt::get(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, LHS, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::match(), and RHS.
Referenced by foldLogOpOfMaskedICmpsAsymmetric().
|
static |
Try to fold (icmp(A & B) ==/!= 0) &/| (icmp(A & D) ==/!= E) into a single (icmp(A & X) ==/!= Y), where the left-hand side and the right hand side aren't of the common mask pattern type.
Also used for logical and/or, must be poison safe.
Definition at line 491 of file InstCombineAndOrXor.cpp.
References assert(), B, BMask_Mixed, Builder, conjugateICmpMask(), D, E, foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed(), llvm::ICmpInst::isEquality(), LHS, Mask_NotAllZeros, and RHS.
Referenced by foldLogOpOfMaskedICmps().
|
static |
Definition at line 1502 of file InstCombineAndOrXor.cpp.
References assert(), B, Builder, llvm::BinaryOperator::CreateNot(), llvm::Value::hasOneUse(), I, llvm::PatternMatch::m_And(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombinerImpl::visitOr().
|
static |
General pattern: X & Y.
Where Y is checking that all the high bits (covered by a mask 4294967168) are uniform, i.e. arg & 4294967168 can be either 4294967168 or 0 Pattern can be one of: t = add i32 arg, 128 r = icmp ult i32 t, 256 Or t0 = shl i32 arg, 24 t1 = ashr i32 t0, 24 r = icmp eq i32 t1, arg Or t0 = trunc i32 arg to i8 t1 = sext i8 t0 to i32 r = icmp eq i32 t1, arg This pattern is a signed truncation check.
And X is checking that some bit in that same mask is zero. I.e. can be one of: r = icmp sgt i32 arg, -1 Or t = and i32 arg, 2147483648 r = icmp eq i32 t, 0
Since we are checking that all the bits in that mask are the same, and a particular bit is zero, what we are really checking is that all the masked bits are zero. So this should be transformed to: r = icmp ult i32 arg, 128
Definition at line 788 of file InstCombineAndOrXor.cpp.
References assert(), Builder, llvm::decomposeBitTestICmp(), llvm::ConstantInt::get(), llvm::Value::getName(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), I1, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_ULT, llvm::APInt::intersects(), llvm::APInt::isPowerOf2(), llvm::APInt::isSubsetOf(), llvm::APInt::isZero(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::BitmaskEnumDetail::Mask(), llvm::PatternMatch::match(), llvm::APInt::shl(), llvm::APIntOps::umin(), X, and llvm::APInt::zext().
|
static |
Commuted variants are assumed to be handled by calling this function again with the parameters swapped.
Definition at line 936 of file InstCombineAndOrXor.cpp.
References llvm::SimplifyQuery::AC, B, llvm::sampleprof::Base, Builder, llvm::SimplifyQuery::CxtI, llvm::SimplifyQuery::DL, llvm::SimplifyQuery::DT, llvm::Value::hasOneUse(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::ICmpInst::isEquality(), llvm::isKnownNonZero(), llvm::CmpInst::isUnsigned(), llvm::PatternMatch::m_c_Add(), llvm::PatternMatch::m_c_ICmp(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), Other, and std::swap().
|
static |
A ^ B can be specified using other logic ops in a variety of patterns.
We can fold these early and efficiently by morphing an existing instruction.
Definition at line 3128 of file InstCombineAndOrXor.cpp.
References assert(), B, Builder, llvm::BinaryOperator::CreateNot(), llvm::Value::hasOneUse(), I, llvm::PatternMatch::m_And(), llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Or(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombinerImpl::visitXor().
|
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 41 of file InstCombineAndOrXor.cpp.
References Builder, llvm::getPredForFCmpCode(), llvm::Value::getType(), LHS, and RHS.
|
static |
Return the set of patterns (from MaskedICmpType) that (icmp SCC (A & B), C) satisfies.
Definition at line 156 of file InstCombineAndOrXor.cpp.
References AMask_AllOnes, AMask_Mixed, AMask_NotAllOnes, AMask_NotMixed, B, BMask_AllOnes, BMask_Mixed, BMask_NotAllOnes, BMask_NotMixed, llvm::CmpInst::ICMP_EQ, llvm::APInt::isPowerOf2(), llvm::APInt::isSubsetOf(), llvm::PatternMatch::m_APInt(), Mask_AllZeros, Mask_NotAllZeros, and llvm::PatternMatch::match().
Referenced by getMaskedTypeForICmpPair().
|
static |
Handle (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E).
Return the pattern classes (from MaskedICmpType) for the left hand side and the right hand side as a pair. LHS and RHS are the left hand side and the right hand side ICmps and PredL and PredR are their predicates, respectively.
Definition at line 238 of file InstCombineAndOrXor.cpp.
References assert(), B, D, llvm::decomposeBitTestICmp(), E, llvm::Constant::getAllOnesValue(), getMaskedICmpType(), llvm::Value::getType(), llvm::ICmpInst::isEquality(), llvm::Type::isIntOrIntVectorTy(), L2, LHS, llvm::PatternMatch::m_And(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::None, R2, and RHS.
Referenced by foldLogOpOfMaskedICmps().
|
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 31 of file InstCombineAndOrXor.cpp.
References Builder, llvm::getPredForICmpCode(), llvm::Value::getType(), LHS, and RHS.
|
static |
Match variations of De Morgan's Laws: (~A & ~B) == (~(A | B)) (~A | ~B) == (~(A & B))
Definition at line 1318 of file InstCombineAndOrXor.cpp.
References assert(), B, Builder, llvm::BinaryOperator::Create(), llvm::BinaryOperator::CreateNot(), I, llvm::InstCombiner::isFreeToInvert(), llvm::PatternMatch::m_c_BinOp(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombinerImpl::visitAnd(), and llvm::InstCombinerImpl::visitOr().
|
static |
Match UB-safe variants of the funnel shift intrinsic.
Definition at line 2203 of file InstCombineAndOrXor.cpp.
References assert(), llvm::InstCombinerImpl::computeKnownBits(), llvm::CallInst::Create(), F, llvm::ConstantInt::get(), llvm::ConstantExpr::getAdd(), llvm::Intrinsic::getDeclaration(), llvm::KnownBits::getMaxValue(), llvm::BinaryOperator::getOpcode(), llvm::Value::getType(), llvm::CmpInst::ICMP_ULT, llvm::isPowerOf2_32(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APIntAllowUndef(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_LogicalShift(), llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_SpecificIntAllowUndef(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::BitmaskEnumDetail::Mask(), llvm::PatternMatch::match(), llvm::Constant::mergeUndefsWith(), llvm::Or, std::swap(), llvm::APInt::ult(), and X.
Referenced by foldGuardedFunnelShift(), and llvm::InstCombinerImpl::visitOr().
Match an extraction of bits from an integer.
Definition at line 1019 of file InstCombineAndOrXor.cpp.
References llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::None, Shift, X, and Y.
|
static |
Attempt to combine or(zext(x),shl(zext(y),bw/2) concat packing patterns.
Definition at line 2305 of file InstCombineAndOrXor.cpp.
References assert(), Builder, F, llvm::Intrinsic::getDeclaration(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_BitReverse(), llvm::PatternMatch::m_BSwap(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), llvm::Or, and std::swap().
Referenced by llvm::InstCombinerImpl::visitOr().
|
static |
This a limited reassociation for a special case (see above) where we are checking if two values are either both NAN (unordered) or not-NAN (ordered).
This could be handled more generally in '-reassociation', but it seems like an unlikely pattern for a large number of logic ops and fcmps.
Definition at line 1273 of file InstCombineAndOrXor.cpp.
References assert(), Builder, llvm::BinaryOperator::Create(), llvm::CmpInst::FCMP_ORD, llvm::CmpInst::FCMP_UNO, llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::PatternMatch::m_AnyZeroFP(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_FCmp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), std::swap(), X, and Y.
Referenced by llvm::InstCombinerImpl::visitAnd(), and llvm::InstCombinerImpl::visitOr().
|
static |
Transform BITWISE_OP(BSWAP(A),BSWAP(B)) or BITWISE_OP(BSWAP(A), Constant) to BSWAP(BITWISE_OP(A, B))
I | Binary operator to transform. |
Definition at line 54 of file InstCombineAndOrXor.cpp.
References assert(), Builder, F, llvm::ConstantInt::get(), llvm::Intrinsic::getDeclaration(), llvm::Value::hasOneUse(), I, llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_BSwap(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombinerImpl::visitAnd(), llvm::InstCombinerImpl::visitOr(), and llvm::InstCombinerImpl::visitXor().
|
static |
Definition at line 3327 of file InstCombineAndOrXor.cpp.
References Builder, I, llvm::InstCombiner::isFreeToInvert(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::match(), std::swap(), X, and Y.
|
static |
If we have a masked merge, in the canonical form of: (assuming that A only has one use.) | A | |B| ((x ^ y) & M) ^ y | D |.
Definition at line 3288 of file InstCombineAndOrXor.cpp.
References B, Builder, D, llvm::Constant::getAllOnesValue(), llvm::Type::getScalarType(), I, LHS, M, llvm::PatternMatch::m_c_And(), llvm::PatternMatch::m_c_Xor(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Constant::replaceUndefsWith(), RHS, and X.
Referenced by llvm::InstCombinerImpl::visitXor().