LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

InstructionCombining.cpp File Reference

#include "llvm/Transforms/Scalar.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/Pass.h"
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Support/CallSite.h"
#include "llvm/Support/ConstantRange.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/InstVisitor.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/PatternMatch.h"
#include "llvm/Support/Compiler.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/STLExtras.h"
#include <algorithm>
#include <climits>
#include <sstream>

Include dependency graph for InstructionCombining.cpp:

Include dependency graph

Go to the source code of this file.

Classes

class  InstCombiner
struct  AddRHS
struct  AddMaskingAnd
struct  FoldICmpLogical
struct  XorSelf

Defines

#define DEBUG_TYPE   "instcombine"

Functions

 STATISTIC (NumCombined,"Number of insts combined")
 STATISTIC (NumConstProp,"Number of constant folds")
 STATISTIC (NumDeadInst,"Number of dead inst eliminated")
 STATISTIC (NumDeadStore,"Number of dead stores eliminated")
 STATISTIC (NumSunkInst,"Number of instructions sunk")
unsigned getComplexity (Value *V)
bool isOnlyUse (Value *V)
const TypegetPromotedType (const Type *Ty)
ValuegetBitCastOperand (Value *V)
Instruction::CastOps isEliminableCastPair (const CastInst *CI, unsigned opcode, const Type *DstTy, TargetData *TD)
bool ValueRequiresCast (Instruction::CastOps opcode, const Value *V, const Type *Ty, TargetData *TD)
Valuedyn_castNegVal (Value *V)
Valuedyn_castNotVal (Value *V)
Valuedyn_castFoldableMul (Value *V, ConstantInt *&CST)
Userdyn_castGetElementPtr (Value *V)
unsigned getOpcode (const Value *V)
ConstantIntAddOne (ConstantInt *C)
 AddOne - Add one to a ConstantInt.
ConstantIntSubOne (ConstantInt *C)
 SubOne - Subtract one from a ConstantInt.
ConstantIntAdd (ConstantInt *C1, ConstantInt *C2)
 Add - Add two ConstantInts together.
ConstantIntAnd (ConstantInt *C1, ConstantInt *C2)
 And - Bitwise AND two ConstantInts together.
ConstantIntSubtract (ConstantInt *C1, ConstantInt *C2)
 Subtract - Subtract one ConstantInt from another.
ConstantIntMultiply (ConstantInt *C1, ConstantInt *C2)
 Multiply - Multiply two ConstantInts together.
bool MultiplyOverflows (ConstantInt *C1, ConstantInt *C2, bool sign)
bool ShrinkDemandedConstant (Instruction *I, unsigned OpNo, APInt Demanded)
void ComputeSignedMinMaxValuesFromKnownBits (const Type *Ty, const APInt &KnownZero, const APInt &KnownOne, APInt &Min, APInt &Max)
void ComputeUnsignedMinMaxValuesFromKnownBits (const Type *Ty, const APInt &KnownZero, const APInt &KnownOne, APInt &Min, APInt &Max)
template<typename Functor>
InstructionAssociativeOpt (BinaryOperator &Root, const Functor &F)
ValueFoldOperationIntoSelectOperand (Instruction &I, Value *SO, InstCombiner *IC)
InstructionFoldOpIntoSelect (Instruction &Op, SelectInst *SI, InstCombiner *IC)
bool isSignBitCheck (ICmpInst::Predicate pred, ConstantInt *RHS, bool &TrueIfSigned)
bool isOneBitSet (const ConstantInt *CI)
bool isHighOnes (const ConstantInt *CI)
unsigned getICmpCode (const ICmpInst *ICI)
ValuegetICmpValue (bool sign, unsigned code, Value *LHS, Value *RHS)
bool PredicatesFoldable (ICmpInst::Predicate p1, ICmpInst::Predicate p2)
bool isRunOfOnes (ConstantInt *Val, uint32_t &MB, uint32_t &ME)
bool CollectBSwapParts (Value *V, SmallVector< Value *, 8 > &ByteValues)
bool AddWithOverflow (ConstantInt *&Result, ConstantInt *In1, ConstantInt *In2, bool IsSigned=false)
ValueEmitGEPOffset (User *GEP, Instruction &I, InstCombiner &IC)
ValueEvaluateGEPOffsetExpression (User *GEP, Instruction &I, InstCombiner &IC)
ValueDecomposeSimpleLinearExpr (Value *Val, unsigned &Scale, int &Offset)
ConstantFitsInFPType (ConstantFP *CFP, const fltSemantics &Sem)
ValueLookThroughFPExtensions (Value *V)
unsigned GetSelectFoldableOperands (Instruction *I)
ConstantGetSelectFoldableConstant (Instruction *I)
unsigned EnforceKnownAlignment (Value *V, unsigned Align, unsigned PrefAlign)
bool isSafeToEliminateVarargsCast (const CallSite CS, const CastInst *const CI, const TargetData *const TD, const int ix)
bool isSafeToSinkLoad (LoadInst *L)
bool DeadPHICycle (PHINode *PN, SmallPtrSet< PHINode *, 16 > &PotentiallyDeadPHIs)
bool PHIsEqualValue (PHINode *PN, Value *NonPhiInVal, SmallPtrSet< PHINode *, 16 > &ValueEqualPHIs)
ValueInsertCastToIntPtrTy (Value *V, const Type *DTy, Instruction *InsertPoint, InstCombiner *IC)
InstructionInstCombineLoadCast (InstCombiner &IC, LoadInst &LI, const TargetData *TD)
 InstCombineLoadCast - Fold 'load (cast P)' -> cast (load P)' when possible.
bool isSafeToLoadUnconditionally (Value *V, Instruction *ScanFrom)
ValueGetUnderlyingObject (Value *Ptr)
InstructionInstCombineStoreToCast (InstCombiner &IC, StoreInst &SI)
bool CheapToScalarize (Value *V, bool isConstant)
std::vector< unsigned > getShuffleMask (const ShuffleVectorInst *SVI)
ValueFindScalarElement (Value *V, unsigned EltNo)
bool CollectSingleShuffleElements (Value *V, Value *LHS, Value *RHS, std::vector< Constant * > &Mask)
ValueCollectShuffleElements (Value *V, std::vector< Constant * > &Mask, Value *&RHS)
bool TryToSinkInstruction (Instruction *I, BasicBlock *DestBlock)
void AddReachableCodeToWorklist (BasicBlock *BB, SmallPtrSet< BasicBlock *, 64 > &Visited, InstCombiner &IC, const TargetData *TD)

Variables

RegisterPass< InstCombinerX ("instcombine","Combine redundant instructions")


Define Documentation

#define DEBUG_TYPE   "instcombine"
 

Definition at line 36 of file InstructionCombining.cpp.


Function Documentation

ConstantInt* Add ConstantInt C1,
ConstantInt C2
[static]
 

Add - Add two ConstantInts together.

Definition at line 639 of file InstructionCombining.cpp.

References llvm::ConstantInt::getValue().

Referenced by AddWithOverflow(), AddMaskingAnd::apply(), AddRHS::apply(), InstCombiner::visitAdd(), InstCombiner::visitAnd(), InstCombiner::visitMul(), InstCombiner::visitOr(), and InstCombiner::visitURem().

ConstantInt* AddOne ConstantInt C  )  [static]
 

AddOne - Add one to a ConstantInt.

Definition at line 629 of file InstructionCombining.cpp.

References llvm::ConstantInt::getValue().

Referenced by InstCombiner::FoldICmpDivCst(), InstCombiner::visitAdd(), InstCombiner::visitAnd(), InstCombiner::visitICmpInst(), InstCombiner::visitICmpInstWithInstAndIntCst(), InstCombiner::visitOr(), and InstCombiner::visitSub().

void AddReachableCodeToWorklist BasicBlock BB,
SmallPtrSet< BasicBlock *, 64 > &  Visited,
InstCombiner IC,
const TargetData TD
[static]
 

AddReachableCodeToWorklist - Walk the function in depth-first order, adding all reachable code to the worklist.

This has a couple of tricks to make the code faster and more powerful. In particular, we constant fold and DCE instructions as we go, to avoid adding them to the worklist (this significantly speeds up instcombine on code where many instructions are dead or constant). Additionally, if we find a branch whose condition is a known constant, we only visit the reachable successors.

Definition at line 11387 of file InstructionCombining.cpp.

References InstCombiner::AddToWorkList(), llvm::SmallVectorImpl< T >::back(), llvm::BasicBlock::begin(), llvm::ConstantFoldInstruction(), DOUT, llvm::SmallVectorImpl< T >::empty(), llvm::BasicBlock::end(), llvm::Instruction::eraseFromParent(), llvm::SwitchInst::getCaseValue(), llvm::SwitchInst::getCondition(), llvm::BranchInst::getCondition(), llvm::TerminatorInst::getNumSuccessors(), llvm::SwitchInst::getNumSuccessors(), llvm::TerminatorInst::getSuccessor(), llvm::SwitchInst::getSuccessor(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::SmallPtrSet< PtrType, SmallSize >::insert(), llvm::BranchInst::isConditional(), llvm::isInstructionTriviallyDead(), llvm::SmallVectorImpl< T >::pop_back(), llvm::SmallVectorImpl< T >::push_back(), and llvm::Value::replaceAllUsesWith().

Referenced by InstCombiner::DoOneIteration().

bool AddWithOverflow ConstantInt *&  Result,
ConstantInt In1,
ConstantInt In2,
bool  IsSigned = false
[static]
 

AddWithOverflow - Compute Result = In1+In2, returning true if the result overflowed for this type.

Definition at line 4619 of file InstructionCombining.cpp.

References Add(), llvm::ConstantInt::getValue(), llvm::APInt::isNegative(), llvm::APInt::sgt(), llvm::APInt::slt(), and llvm::APInt::ult().

Referenced by InstCombiner::FoldICmpDivCst().

ConstantInt* And ConstantInt C1,
ConstantInt C2
[static]
 

And - Bitwise AND two ConstantInts together.

Definition at line 643 of file InstructionCombining.cpp.

References llvm::ConstantInt::getValue().

Referenced by InstCombiner::visitAdd(), and InstCombiner::visitXor().

template<typename Functor>
Instruction* AssociativeOpt BinaryOperator Root,
const Functor &  F
[static]
 

AssociativeOpt - Perform an optimization on an associative operator. This function is designed to check a chain of associative operators for a potential to apply a certain optimization. Since the optimization may be applicable if the expression was reassociated, this checks the chain, then reassociates the expression as necessary to expose the optimization opportunity. This makes use of a special Functor, which must define 'shouldApply' and 'apply' methods.

Definition at line 1621 of file InstructionCombining.cpp.

References llvm::Instruction::getOpcode(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Value::hasOneUse(), llvm::Instruction::moveBefore(), llvm::Value::replaceAllUsesWith(), and llvm::User::setOperand().

Referenced by InstCombiner::visitAdd(), InstCombiner::visitAnd(), InstCombiner::visitOr(), and InstCombiner::visitXor().

bool CheapToScalarize Value V,
bool  isConstant
[static]
 

CheapToScalarize - Return true if the value is cheaper to scalarize than it is to leave as a vector operation.

Definition at line 10789 of file InstructionCombining.cpp.

References llvm::User::getNumOperands(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Constant::getOperand(), and llvm::Value::hasOneUse().

Referenced by InstCombiner::visitExtractElementInst().

bool CollectBSwapParts Value V,
SmallVector< Value *, 8 > &  ByteValues
[static]
 

CollectBSwapParts - Look to see if the specified value defines a single byte in the result. If it does, and if the specified byte hasn't been filled in yet, fill it in and return false.

Definition at line 3826 of file InstructionCombining.cpp.

References llvm::APInt::getActiveBits(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::ConstantInt::getZExtValue(), llvm::Instruction::isShift(), llvm::PatternMatch::m_And(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Shift(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and llvm::SmallVectorImpl< T >::size().

Value* CollectShuffleElements Value V,
std::vector< Constant * > &  Mask,
Value *&  RHS
[static]
 

CollectShuffleElements - We are building a shuffle of V, using RHS as the RHS of the shuffle instruction, if it is not null. Return a shuffle mask that computes V and the LHS value of the shuffle.

Definition at line 11087 of file InstructionCombining.cpp.

References CollectSingleShuffleElements(), llvm::User::getOperand(), and llvm::Value::getType().

Referenced by InstCombiner::visitInsertElementInst().

bool CollectSingleShuffleElements Value V,
Value LHS,
Value RHS,
std::vector< Constant * > &  Mask
[static]
 

CollectSingleShuffleElements - If V is a shuffle of values that ONLY returns elements from either LHS or RHS, return the shuffle mask and true. Otherwise, return false.

Definition at line 11017 of file InstructionCombining.cpp.

References llvm::User::getOperand(), and llvm::Value::getType().

Referenced by CollectShuffleElements().

void ComputeSignedMinMaxValuesFromKnownBits const Type Ty,
const APInt KnownZero,
const APInt KnownOne,
APInt Min,
APInt Max
[static]
 

Definition at line 706 of file InstructionCombining.cpp.

References llvm::APInt::clear(), llvm::APInt::getBitWidth(), and llvm::APInt::set().

Referenced by InstCombiner::visitICmpInst().

void ComputeUnsignedMinMaxValuesFromKnownBits const Type Ty,
const APInt KnownZero,
const APInt KnownOne,
APInt Min,
APInt Max
[static]
 

Definition at line 732 of file InstructionCombining.cpp.

References llvm::APInt::getBitWidth().

Referenced by InstCombiner::visitICmpInst().

bool DeadPHICycle PHINode PN,
SmallPtrSet< PHINode *, 16 > &  PotentiallyDeadPHIs
[static]
 

DeadPHICycle - Return true if this PHI node is only used by a PHI node cycle that is dead.

Definition at line 9539 of file InstructionCombining.cpp.

References llvm::Value::hasOneUse(), llvm::SmallPtrSet< PtrType, SmallSize >::insert(), llvm::SmallPtrSetImpl::size(), llvm::Instruction::use_back(), and llvm::Value::use_empty().

Referenced by InstCombiner::visitPHINode().

Value* DecomposeSimpleLinearExpr Value Val,
unsigned &  Scale,
int &  Offset
[static]
 

DecomposeSimpleLinearExpr - Analyze 'Val', seeing if it is a simple linear expression. If so, decompose it, returning some value X, such that Val is X*Scale+Offset.

Definition at line 6777 of file InstructionCombining.cpp.

References llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), and llvm::ConstantInt::getZExtValue().

Value* dyn_castFoldableMul Value V,
ConstantInt *&  CST
[inline, static]
 

Definition at line 589 of file InstructionCombining.cpp.

References llvm::ConstantInt::getLimitedValue(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::Value::hasOneUse(), llvm::Type::isInteger(), and llvm::APIntOps::shl().

Referenced by InstCombiner::visitAdd(), and InstCombiner::visitSub().

User* dyn_castGetElementPtr Value V  )  [static]
 

dyn_castGetElementPtr - If this is a getelementptr instruction or constant expression, return it.

Definition at line 609 of file InstructionCombining.cpp.

References llvm::ConstantExpr::getOpcode().

Referenced by InstCombiner::FoldGEPICmp(), InstCombiner::visitGetElementPtrInst(), and InstCombiner::visitICmpInst().

Value* dyn_castNegVal Value V  )  [inline, static]
 

Definition at line 559 of file InstructionCombining.cpp.

References llvm::SequentialType::getElementType(), llvm::ConstantVector::getType(), and llvm::Type::isInteger().

Referenced by InstCombiner::visitAdd(), InstCombiner::visitICmpInstWithInstAndIntCst(), InstCombiner::visitMul(), InstCombiner::visitSDiv(), InstCombiner::visitSRem(), and InstCombiner::visitSub().

Value* dyn_castNotVal Value V  )  [inline, static]
 

Definition at line 574 of file InstructionCombining.cpp.

References llvm::ConstantInt::getValue().

Referenced by InstCombiner::visitAdd(), InstCombiner::visitAnd(), and InstCombiner::visitXor().

Value* EmitGEPOffset User GEP,
Instruction I,
InstCombiner IC
[static]
 

EmitGEPOffset - Given a getelementptr instruction/constantexpr, emit the code necessary to compute the offset from the base pointer (without adding in the base pointer). Return the result as a signed integer of intptr size.

Definition at line 4635 of file InstructionCombining.cpp.

References llvm::gep_type_begin(), llvm::gep_type_iterator, llvm::TargetData::getABITypeSize(), llvm::StructLayout::getElementOffset(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::TargetData::getIntPtrType(), llvm::Value::getName(), llvm::TargetData::getPointerSizeInBits(), llvm::TargetData::getStructLayout(), InstCombiner::getTargetData(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::ConstantInt::getZExtValue(), InstCombiner::InsertNewInstBefore(), llvm::ConstantInt::isZero(), llvm::User::op_begin(), llvm::User::op_end(), and llvm::User::op_iterator.

Referenced by InstCombiner::commonPointerCastTransforms(), and InstCombiner::FoldGEPICmp().

unsigned EnforceKnownAlignment Value V,
unsigned  Align,
unsigned  PrefAlign
[static]
 

EnforceKnownAlignment - If the specified pointer points to an object that we control, modify the object's alignment to PrefAlign. This isn't often possible though. If alignment is important, a more reliable approach is to simply align all global variables and allocation instructions to their preferred alignment from the beginning.

Definition at line 8419 of file InstructionCombining.cpp.

References getOpcode(), llvm::User::getOperand(), llvm::GlobalValue::isDeclaration(), llvm::User::op_begin(), llvm::User::op_end(), llvm::User::op_iterator, llvm::AllocationInst::setAlignment(), and llvm::GlobalValue::setAlignment().

Value* EvaluateGEPOffsetExpression User GEP,
Instruction I,
InstCombiner IC
[static]
 

EvaluateGEPOffsetExpression - Return an value that can be used to compare of the *offset* implied by GEP to zero. For example, if we have &A[i], we want to return 'i' for "icmp ne i, 0". Note that, in general, indices can be complex, and scales are involved. The above expression would also be legal to codegen as "icmp ne (i*4), 0" (assuming A is a pointer to i32). This later form is less amenable to optimization though, and we are allowed to generate the first by knowing that pointer arithmetic doesn't overflow.

If we can't emit an optimized form for this expression, this returns null.

Definition at line 4718 of file InstructionCombining.cpp.

References llvm::gep_type_begin(), llvm::gep_type_iterator, llvm::TargetData::getABITypeSize(), llvm::StructLayout::getElementOffset(), llvm::generic_gep_type_iterator< ItTy >::getIndexedType(), llvm::TargetData::getIntPtrType(), llvm::Value::getNameStart(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::TargetData::getPointerSizeInBits(), llvm::Type::getPrimitiveSizeInBits(), llvm::ConstantInt::getSExtValue(), llvm::TargetData::getStructLayout(), InstCombiner::getTargetData(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), and llvm::ConstantInt::isZero().

Referenced by InstCombiner::FoldGEPICmp().

Value* FindScalarElement Value V,
unsigned  EltNo
[static]
 

FindScalarElement - Given a vector and an element number, see if the scalar value is already around as a register, for example if it were inserted then extracted from the vector.

Definition at line 10849 of file InstructionCombining.cpp.

References llvm::SequentialType::getElementType(), llvm::VectorType::getNumElements(), llvm::User::getOperand(), llvm::Constant::getOperand(), getShuffleMask(), and llvm::Value::getType().

Referenced by InstCombiner::visitExtractElementInst().

Constant* FitsInFPType ConstantFP CFP,
const fltSemantics Sem
[static]
 

FitsInFPType - Return a Constant* for the specified FP constant if it fits in the specified FP type without changing its value.

Definition at line 7711 of file InstructionCombining.cpp.

References llvm::APFloat::convert(), and llvm::ConstantFP::getValueAPF().

Referenced by LookThroughFPExtensions().

Value* FoldOperationIntoSelectOperand Instruction I,
Value SO,
InstCombiner IC
[static]
 

Definition at line 1718 of file InstructionCombining.cpp.

References llvm::Value::getName(), llvm::CmpInst::getOpcode(), llvm::BinaryOperator::getOpcode(), llvm::Instruction::getOpcode(), llvm::CastInst::getOpcode(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::Value::getType(), InstCombiner::InsertNewInstBefore(), and std::swap().

Referenced by FoldOpIntoSelect().

Instruction* FoldOpIntoSelect Instruction Op,
SelectInst SI,
InstCombiner IC
[static]
 

Definition at line 1758 of file InstructionCombining.cpp.

References FoldOperationIntoSelectOperand(), llvm::SelectInst::getCondition(), llvm::User::getOperand(), llvm::Value::getType(), and llvm::Value::hasOneUse().

Referenced by InstCombiner::commonCastTransforms(), InstCombiner::commonIDivTransforms(), InstCombiner::commonIRemTransforms(), InstCombiner::commonShiftTransforms(), InstCombiner::FoldShiftByConstant(), InstCombiner::visitAdd(), InstCombiner::visitAnd(), InstCombiner::visitMul(), InstCombiner::visitOr(), InstCombiner::visitSub(), and InstCombiner::visitXor().

Value* getBitCastOperand Value V  )  [static]
 

getBitCastOperand - If the specified operand is a CastInst or a constant expression bitcast, return the operand value, otherwise return null.

Definition at line 440 of file InstructionCombining.cpp.

References llvm::ConstantExpr::getOpcode(), llvm::Constant::getOperand(), and llvm::User::getOperand().

Referenced by InstCombiner::visitGetElementPtrInst().

unsigned getComplexity Value V  )  [static]
 

Definition at line 412 of file InstructionCombining.cpp.

unsigned getICmpCode const ICmpInst ICI  )  [static]
 

getICmpCode - Encode a icmp predicate into a three bit mask. These bits are carefully arranged to allow folding of expressions such as:

(A < B) | (A > B) --> (A != B)

Note that this is only valid if the first and second predicates have the same sign. Is illegal to do: (A u< B) | (A s> B)

Three bits are used to represent the condition, as follows: 0 A > B 1 A == B 2 A < B

<=> Value Definition 000 0 Always false 001 1 A > B 010 2 A == B 011 3 A >= B 100 4 A < B 101 5 A != B 110 6 A <= B 111 7 Always true

Definition at line 3012 of file InstructionCombining.cpp.

References llvm::CmpInst::getPredicate().

Referenced by FoldICmpLogical::apply().

Value* getICmpValue bool  sign,
unsigned  code,
Value LHS,
Value RHS
[static]
 

getICmpValue - 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 new icmp instructions.

Definition at line 3036 of file InstructionCombining.cpp.

Referenced by FoldICmpLogical::apply().

unsigned getOpcode const Value V  )  [static]
 

getOpcode - If this is an Instruction or a ConstantExpr, return the opcode value. Otherwise return UserOp1.

Definition at line 619 of file InstructionCombining.cpp.

References llvm::ConstantExpr::getOpcode(), and llvm::Instruction::getOpcode().

Referenced by InstCombiner::commonIntCastTransforms(), llvm::ComputeMaskedBits(), llvm::ComputeNumSignBits(), EnforceKnownAlignment(), llvm::SelectInst::getOpcode(), llvm::Instruction::getOpcodeName(), llvm::Instruction::isArithmeticShift(), llvm::Instruction::isAssociative(), llvm::Instruction::isBinaryOp(), llvm::Instruction::isCast(), llvm::Instruction::isCommutative(), llvm::MachineInstr::isIdenticalTo(), llvm::Instruction::isLogicalShift(), llvm::Instruction::isShift(), llvm::Instruction::isTerminator(), llvm::Instruction::isTrapping(), SRAGlobal(), InstCombiner::visitAnd(), and InstCombiner::visitSExt().

const Type* getPromotedType const Type Ty  )  [static]
 

Definition at line 430 of file InstructionCombining.cpp.

References llvm::IntegerType::getBitWidth().

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 8014 of file InstructionCombining.cpp.

References llvm::Instruction::getOpcode(), and llvm::Value::getType().

Referenced by InstCombiner::visitSelectInst().

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 7994 of file InstructionCombining.cpp.

References llvm::Instruction::getOpcode().

Referenced by InstCombiner::visitSelectInst().

std::vector<unsigned> getShuffleMask const ShuffleVectorInst SVI  )  [static]
 

Read and decode a shufflevector mask.

It turns undef elements into values that are larger than the number of elements in the input.

Definition at line 10829 of file InstructionCombining.cpp.

References llvm::User::const_op_iterator, llvm::VectorType::getNumElements(), llvm::User::getOperand(), llvm::ShuffleVectorInst::getType(), llvm::User::op_begin(), and llvm::User::op_end().

Referenced by FindScalarElement(), InstCombiner::visitExtractElementInst(), and InstCombiner::visitShuffleVectorInst().

Value* GetUnderlyingObject Value Ptr  )  [static]
 

GetUnderlyingObject - Trace through a series of getelementptrs and bitcasts until we find the underlying object a pointer is referring to or something we don't understand. Note that the returned pointer may be offset from the input, because we ignore GEP indices.

Definition at line 10186 of file InstructionCombining.cpp.

References llvm::ConstantExpr::getOpcode(), llvm::User::getOperand(), and llvm::Constant::getOperand().

Referenced by InstCombiner::visitLoadInst().

Value* InsertCastToIntPtrTy Value V,
const Type DTy,
Instruction InsertPoint,
InstCombiner IC
[static]
 

Definition at line 9664 of file InstructionCombining.cpp.

References llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), and InstCombiner::InsertCastBefore().

Referenced by InstCombiner::visitGetElementPtrInst().

Instruction* InstCombineLoadCast InstCombiner IC,
LoadInst LI,
const TargetData TD
[static]
 

InstCombineLoadCast - Fold 'load (cast P)' -> cast (load P)' when possible.

Definition at line 10066 of file InstructionCombining.cpp.

References llvm::GetConstantStringInfo(), llvm::SequentialType::getElementType(), llvm::Value::getName(), llvm::ArrayType::getNumElements(), llvm::Constant::getOperand(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), InstCombiner::getTargetData(), llvm::Value::getType(), llvm::TargetData::getTypeSizeInBits(), InstCombiner::InsertNewInstBefore(), llvm::Type::isInteger(), llvm::TargetData::isLittleEndian(), llvm::LoadInst::isVolatile(), and InstCombiner::ReplaceInstUsesWith().

Referenced by InstCombiner::visitLoadInst().

Instruction* InstCombineStoreToCast InstCombiner IC,
StoreInst SI
[static]
 

InstCombineStoreToCast - Fold store V, (cast P) -> store (cast V), P when possible.

Definition at line 10345 of file InstructionCombining.cpp.

References llvm::SequentialType::getElementType(), llvm::Value::getName(), llvm::ArrayType::getNumElements(), llvm::User::getOperand(), InstCombiner::getTargetData(), llvm::Value::getType(), llvm::TargetData::getTypeSizeInBits(), InstCombiner::InsertNewInstBefore(), and llvm::Type::isInteger().

Referenced by InstCombiner::visitStoreInst().

Instruction::CastOps isEliminableCastPair const CastInst CI,
unsigned  opcode,
const Type DstTy,
TargetData TD
[static]
 

This function is a wrapper around CastInst::isEliminableCastPair. It simply extracts arguments and returns what that function returns.

Parameters:
CI  The first cast instruction
opcode  The opcode of the second cast instruction
DstTy  The target type for the second cast instruction
TD  The target data for pointer size

Definition at line 452 of file InstructionCombining.cpp.

References llvm::TargetData::getIntPtrType(), llvm::CastInst::getOpcode(), llvm::User::getOperand(), and llvm::Value::getType().

Referenced by InstCombiner::commonCastTransforms(), foldConstantCastPair(), and ValueRequiresCast().

bool isHighOnes const ConstantInt CI  )  [static]
 

Definition at line 2985 of file InstructionCombining.cpp.

References llvm::ConstantInt::getValue(), and llvm::APInt::isPowerOf2().

Referenced by InstCombiner::visitICmpInstWithInstAndIntCst().

bool isOneBitSet const ConstantInt CI  )  [static]
 

Definition at line