LLVM API Documentation
#include "InstCombine.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/IR/PatternMatch.h"
Go to the source code of this file.
Defines | |
#define | DEBUG_TYPE "instcombine" |
Functions | |
static SelectPatternFlavor | MatchSelectPattern (Value *V, Value *&LHS, Value *&RHS) |
static unsigned | GetSelectFoldableOperands (Instruction *I) |
static Constant * | GetSelectFoldableConstant (Instruction *I) |
static bool | isSelect01 (Constant *C1, Constant *C2) |
static Value * | SimplifyWithOpReplaced (Value *V, Value *Op, Value *RepOp, const DataLayout *TD, const TargetLibraryInfo *TLI, DominatorTree *DT, AssumptionTracker *AT) |
static Value * | foldSelectICmpAndOr (SelectInst &SI, Value *TrueVal, Value *FalseVal, InstCombiner::BuilderTy *Builder) |
static bool | CanSelectOperandBeMappingIntoPredBlock (const Value *V, const SelectInst &SI) |
static Value * | foldSelectICmpAnd (const SelectInst &SI, ConstantInt *TrueVal, ConstantInt *FalseVal, InstCombiner::BuilderTy *Builder) |
#define DEBUG_TYPE "instcombine" |
Definition at line 21 of file InstCombineSelect.cpp.
static bool CanSelectOperandBeMappingIntoPredBlock | ( | const Value * | V, |
const SelectInst & | SI | ||
) | [static] |
CanSelectOperandBeMappingIntoPredBlock - SI is a select whose condition is a PHI node (but the two may be in different blocks). See if the true/false values (V) are live in all of the predecessor blocks of the PHI. For example, cases like this cannot be mapped:
X = phi [ C1, BB1], [C2, BB2] Y = add Z = select X, Y, 0
because Y is not live in BB1/BB2.
Definition at line 665 of file InstCombineSelect.cpp.
References llvm::dyn_cast(), llvm::SelectInst::getCondition(), llvm::Instruction::getParent(), and I.
Referenced by llvm::InstCombiner::visitSelectInst().
static Value* foldSelectICmpAnd | ( | const SelectInst & | SI, |
ConstantInt * | TrueVal, | ||
ConstantInt * | FalseVal, | ||
InstCombiner::BuilderTy * | Builder | ||
) | [static] |
foldSelectICmpAnd - If one of the constants is zero (we know they can't both be) and we have an icmp instruction with zero, and we have an 'and' with the non-constant value and a power of two we can turn the select into a shift on the result of the 'and'.
Definition at line 762 of file InstCombineSelect.cpp.
References llvm::IRBuilder< preserveNames, T, Inserter >::CreateAdd(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateLShr(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateShl(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateXor(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateZExtOrTrunc(), llvm::dyn_cast(), llvm::ConstantInt::get(), llvm::ConstantInt::getBitWidth(), llvm::SelectInst::getCondition(), llvm::IRBuilderBase::getContext(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::CmpInst::ICMP_NE, llvm::ICmpInst::isEquality(), llvm::Type::isIntegerTy(), llvm::APInt::isPowerOf2(), llvm::ConstantInt::isZero(), llvm::APInt::logBase2(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombiner::visitSelectInst().
static Value* foldSelectICmpAndOr | ( | SelectInst & | SI, |
Value * | TrueVal, | ||
Value * | FalseVal, | ||
InstCombiner::BuilderTy * | Builder | ||
) | [static] |
foldSelectICmpAndOr - We want to turn: (select (icmp eq (and X, C1), 0), Y, (or Y, C2)) into: (or (shl (and X, C1), C3), y) iff: C1 and C2 are both powers of 2 where: C3 = Log(C2) - Log(C1)
This transform handles cases where: 1. The icmp predicate is inverted 2. The select operands are reversed 3. The magnitude of C2 and C1 are flipped
This also tries to turn --- Single bit tests: if ((x & C) == 0) x |= C to x |= C if ((x & C) != 0) x ^= C to x &= ~C if ((x & C) == 0) x ^= C to x |= C if ((x & C) != 0) x &= ~C to x &= ~C if ((x & C) == 0) x &= ~C to nothing
Definition at line 400 of file InstCombineSelect.cpp.
References llvm::IRBuilder< preserveNames, T, Inserter >::CreateAnd(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateLShr(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateOr(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateShl(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateXor(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateZExtOrTrunc(), llvm::dyn_cast(), llvm::SelectInst::getCondition(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::ICmpInst::isEquality(), llvm::Type::isIntegerTy(), llvm::APInt::logBase2(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Or(), llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Xor(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::X, and Y.
Referenced by llvm::InstCombiner::visitSelectInstWithICmp().
static Constant* GetSelectFoldableConstant | ( | Instruction * | I | ) | [static] |
GetSelectFoldableConstant - For the same transformation as the previous function, return the identity constant that goes into the select.
Definition at line 128 of file InstCombineSelect.cpp.
References llvm::APIntOps::And(), llvm::ConstantInt::get(), llvm::Constant::getAllOnesValue(), llvm::Constant::getNullValue(), llvm::Instruction::getOpcode(), llvm::Value::getType(), llvm_unreachable, llvm::LShr, llvm::APIntOps::Or(), and llvm::APIntOps::Xor().
Referenced by llvm::InstCombiner::FoldSelectIntoOp().
static unsigned GetSelectFoldableOperands | ( | Instruction * | I | ) | [static] |
GetSelectFoldableOperands - We want to turn code that looks like this: C = or A, B D = select cond, C, A into: C = select cond, B, 0 D = or A, C
Assuming that the specified instruction is an operand to the select, return a bitmask indicating which operands of this instruction are foldable if they equal the other incoming value of the select.
Definition at line 108 of file InstCombineSelect.cpp.
References llvm::APIntOps::And(), llvm::Instruction::getOpcode(), llvm::LShr, llvm::APIntOps::Or(), and llvm::APIntOps::Xor().
Referenced by llvm::InstCombiner::FoldSelectIntoOp().
static bool isSelect01 | ( | Constant * | C1, |
Constant * | C2 | ||
) | [static] |
Definition at line 220 of file InstCombineSelect.cpp.
References llvm::dyn_cast(), llvm::Constant::isAllOnesValue(), llvm::ConstantInt::isOne(), and llvm::ConstantInt::isZero().
Referenced by llvm::InstCombiner::FoldSelectIntoOp().
static SelectPatternFlavor MatchSelectPattern | ( | Value * | V, |
Value *& | LHS, | ||
Value *& | RHS | ||
) | [static] |
MatchSelectPattern - Pattern match integer [SU]MIN, [SU]MAX, and ABS idioms, returning the kind and providing the out parameter results if we successfully match.
Definition at line 27 of file InstCombineSelect.cpp.
References llvm::dyn_cast(), llvm::SelectInst::getCondition(), llvm::SelectInst::getFalseValue(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::SelectInst::getTrueValue(), llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::PatternMatch::m_Neg(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::match(), llvm::SPF_ABS, llvm::SPF_NABS, llvm::SPF_SMAX, llvm::SPF_SMIN, llvm::SPF_UMAX, llvm::SPF_UMIN, and llvm::SPF_UNKNOWN.
Referenced by llvm::InstCombiner::visitSelectInst().
static Value* SimplifyWithOpReplaced | ( | Value * | V, |
Value * | Op, | ||
Value * | RepOp, | ||
const DataLayout * | TD, | ||
const TargetLibraryInfo * | TLI, | ||
DominatorTree * | DT, | ||
AssumptionTracker * | AT | ||
) | [static] |
SimplifyWithOpReplaced - See if V simplifies when its operand Op is replaced with RepOp.
Definition at line 314 of file InstCombineSelect.cpp.
References llvm::CallingConv::C, llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldInstOperands(), llvm::ConstantFoldLoadFromConstPtr(), llvm::dyn_cast(), llvm::User::getNumOperands(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), I, LI, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::SimplifyBinOp(), llvm::SimplifyCmpInst(), and llvm::SmallVectorTemplateCommon< T >::size().
Referenced by llvm::InstCombiner::visitSelectInstWithICmp().