23 STATISTIC(NumDeadStore,
"Number of dead stores eliminated");
24 STATISTIC(NumGlobalCopies,
"Number of allocas copied from constant global");
31 return GV->isConstant();
33 if (CE->getOpcode() == Instruction::BitCast ||
34 CE->getOpcode() == Instruction::GetElementPtr)
49 bool IsOffset =
false) {
55 User *U = cast<Instruction>(*UI);
59 if (!
LI->isSimple())
return false;
73 GEP, TheCopy, ToDelete, IsOffset || !GEP->hasAllZeroIndices()))
87 unsigned ArgNo = CS.getArgumentNo(UI);
88 if (CS.onlyReadsMemory() &&
89 (CS.getInstruction()->use_empty() || CS.doesNotCapture(ArgNo)))
94 if (CS.isByValArgument(ArgNo))
102 assert(II->use_empty() &&
"Lifetime markers have no result to use!");
116 if (UI.getOperandNo() == 1) {
122 if (TheCopy)
return false;
126 if (IsOffset)
return false;
129 if (UI.getOperandNo() != 0)
return false;
178 while (isa<AllocaInst>(*It) || isa<DbgInfoIntrinsic>(*It)) ++It;
187 Value *Idx[2] = { NullIdx, NullIdx };
220 if (FirstInst != &AI) {
261 DEBUG(
dbgs() <<
"Found alloca equal to global: " << AI <<
'\n');
262 DEBUG(
dbgs() <<
" memcpy = " << *Copy <<
'\n');
263 for (
unsigned i = 0, e = ToDelete.
size(); i != e; ++i)
265 Constant *TheSrc = cast<Constant>(Copy->getSource());
290 if (
PointerType *SrcTy = dyn_cast<PointerType>(CastOp->getType())) {
296 Type *SrcPTy = SrcTy->getElementType();
298 if (DestPTy->isIntegerTy() || DestPTy->isPointerTy() ||
299 DestPTy->isVectorTy()) {
303 if (
ArrayType *ASrcTy = dyn_cast<ArrayType>(SrcPTy))
304 if (
Constant *CSrc = dyn_cast<Constant>(CastOp))
305 if (ASrcTy->getNumElements() != 0) {
310 Value *Idxs[2] = { Idx, Idx };
312 SrcTy = cast<PointerType>(CastOp->getType());
313 SrcPTy = SrcTy->getElementType();
346 unsigned KnownAlign =
349 unsigned EffectiveLoadAlign = LoadAlign != 0 ? LoadAlign :
352 if (KnownAlign > EffectiveLoadAlign)
354 else if (LoadAlign == 0)
359 if (isa<CastInst>(Op))
376 const Value *GEPI0 = GEPI->getOperand(0);
378 if (isa<ConstantPointerNull>(GEPI0) && GEPI->getPointerAddressSpace() == 0){
391 if (isa<UndefValue>(Op) ||
418 if (
SelectInst *SI = dyn_cast<SelectInst>(Op)) {
424 SI->getOperand(1)->getName()+
".val");
426 SI->getOperand(2)->getName()+
".val");
433 if (
Constant *
C = dyn_cast<Constant>(SI->getOperand(1)))
434 if (
C->isNullValue()) {
440 if (
Constant *
C = dyn_cast<Constant>(SI->getOperand(2)))
441 if (
C->isNullValue()) {
457 Type *DestPTy = cast<PointerType>(CI->
getType())->getElementType();
459 if (SrcTy == 0)
return 0;
481 if (
StructType *STy = dyn_cast<StructType>(SrcPTy)) {
482 if (!STy->getNumElements())
485 SrcPTy = STy->getElementType(0);
486 }
else if (
ArrayType *ATy = dyn_cast<ArrayType>(SrcPTy)) {
488 SrcPTy = ATy->getElementType();
504 cast<PointerType>(CI->
getType())->getAddressSpace() ||
516 Type* CastDstTy = SrcPTy;
519 opcode = Instruction::IntToPtr;
522 opcode = Instruction::PtrToInt;
527 if (!NewGEPIndices.
empty())
547 if (A == B)
return true;
554 if (isa<BinaryOperator>(A) ||
557 isa<GetElementPtrInst>(A))
559 if (cast<Instruction>(A)->isIdenticalToWhenDefined(BI))
572 unsigned KnownAlign =
576 unsigned EffectiveStoreAlign = StoreAlign != 0 ? StoreAlign :
579 if (KnownAlign > EffectiveStoreAlign)
581 else if (StoreAlign == 0)
592 if (isa<AllocaInst>(Ptr))
595 if (isa<AllocaInst>(GEP->getOperand(0))) {
596 if (GEP->getOperand(0)->hasOneUse())
606 for (
unsigned ScanInsts = 6; BBI != SI.
getParent()->
begin() && ScanInsts;
611 if (isa<DbgInfoIntrinsic>(BBI) ||
612 (isa<BitCastInst>(BBI) && BBI->getType()->isPointerTy())) {
617 if (
StoreInst *PrevSI = dyn_cast<StoreInst>(BBI)) {
643 if (BBI->mayWriteToMemory() || BBI->mayReadFromMemory())
649 if (!isa<UndefValue>(Val)) {
658 if (isa<UndefValue>(Val))
663 if (isa<CastInst>(Ptr))
678 }
while (isa<DbgInfoIntrinsic>(BBI) ||
679 (isa<BitCastInst>(BBI) && BBI->getType()->isPointerTy()));
680 if (
BranchInst *BI = dyn_cast<BranchInst>(BBI))
681 if (BI->isUnconditional())
682 if (SimplifyStoreAtEndOfBlock(SI))
696 bool InstCombiner::SimplifyStoreAtEndOfBlock(
StoreInst &SI) {
727 if (StoreBB == DestBB || OtherBB == DestBB)
733 if (!OtherBr || BBI == OtherBB->
begin())
742 while (isa<DbgInfoIntrinsic>(BBI) ||
743 (isa<BitCastInst>(BBI) && BBI->getType()->isPointerTy())) {
744 if (BBI==OtherBB->
begin())
766 if ((OtherStore = dyn_cast<StoreInst>(BBI))) {
774 if (BBI->mayReadFromMemory() || BBI->mayWriteToMemory() ||
775 BBI == OtherBB->
begin())
784 if (
I->mayReadFromMemory() ||
I->mayWriteToMemory())
void push_back(const T &Elt)
STATISTIC(NumDeadStore,"Number of dead stores eliminated")
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
LoadInst * CreateLoad(Value *Ptr, const char *Name)
void addIncoming(Value *V, BasicBlock *BB)
SynchronizationScope getSynchScope() const
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
void setAlignment(unsigned Align)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=0)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getPrefTypeAlignment(Type *Ty) const
static Constant * getGetElementPtr(Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
bool isPtrOrPtrVectorTy() const
const Function * getParent() const
Return the enclosing method, or null if none.
MDNode - a tuple of other values.
const Instruction & front() const
bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom, unsigned Align, const DataLayout *TD=0)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static bool pointsToConstantGlobal(Value *V)
static IntegerType * getInt64Ty(LLVMContext &C)
void setDebugLoc(const DebugLoc &Loc)
setDebugLoc - Set the debug location information for this instruction.
LoopInfoBase< BlockT, LoopT > * LI
static Constant * getNullValue(Type *Ty)
StringRef getName() const
bool isArrayAllocation() const
Instruction * getFirstNonPHIOrDbg()
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
bool isUnconditional() const
DataLayout * getDataLayout() const
InstCombiner - The -instcombine pass.
Type * getAllocatedType() const
AllocaInst * CreateAlloca(Type *Ty, Value *ArraySize=0, const Twine &Name="")
SynchronizationScope getSynchScope() const
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
void setAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope=CrossThread)
static Instruction * InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI)
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
BasicBlock * getSuccessor(unsigned i) const
This class represents a no-op cast from one type to another.
Type * getElementType() const
static bool equivalentAddressValues(Value *A, Value *B)
unsigned getAlignment() const
LLVM Basic Block Representation.
BasicBlock * getSuccessor(unsigned idx) const
LLVM Constant Representation.
PointerType * getType() const
Instruction * ReplaceInstUsesWith(Instruction &I, Value *V)
unsigned getAlignment() const
Interval::pred_iterator pred_begin(Interval *I)
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=0)
Instruction * visitAllocaInst(AllocaInst &AI)
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
InstCombineWorklist Worklist
Worklist - All of the instructions that need to be simplified.
void setAlignment(unsigned Align)
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
Methods for metadata merging.
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
static UndefValue * get(Type *T)
static Instruction * InstCombineLoadCast(InstCombiner &IC, LoadInst &LI, const DataLayout *TD)
InstCombineLoadCast - Fold 'load (cast P)' -> cast (load P)' when possible.
LLVMContext & getContext() const
All values hold a context through their type.
void setMetadata(unsigned KindID, MDNode *Node)
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
unsigned getABITypeAlignment(Type *Ty) const
static Constant * getBitCast(Constant *C, Type *Ty)
AtomicOrdering getOrdering() const
Returns the ordering effect of this store.
Class for constant integers.
Value * FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan=6, AliasAnalysis *AA=0, MDNode **TBAATag=0)
uint64_t getTypeAllocSize(Type *Ty) const
MDNode * getMetadata(unsigned KindID) const
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
const BasicBlock & getEntryBlock() const
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
Value * getSource() const
unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign, const DataLayout *TD=0)
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned getAlignment() const
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static bool isOnlyCopiedFromConstantGlobal(Value *V, MemTransferInst *&TheCopy, SmallVectorImpl< Instruction * > &ToDelete, bool IsOffset=false)
static ArrayType * get(Type *ElementType, uint64_t NumElements)
Instruction * InsertNewInstBefore(Instruction *New, Instruction &Old)
Instruction * visitLoadInst(LoadInst &LI)
LLVM Value Representation.
void setAlignment(unsigned Align)
Instruction * visitStoreInst(StoreInst &SI)
const Value * getArraySize() const
Instruction * EraseInstFromFunction(Instruction &I)
void moveBefore(Instruction *MovePos)
uint64_t getTypeSizeInBits(Type *Ty) const
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const
Determine if one instruction is the same operation as another.
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=0)
iterator getFirstInsertionPt()
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Instruction * visitAllocSite(Instruction &FI)
const BasicBlock * getParent() const
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD