LLVM API Documentation

Defines | Functions
InstCombineLoadStoreAlloca.cpp File Reference
#include "InstCombine.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
Include dependency graph for InstCombineLoadStoreAlloca.cpp:

Go to the source code of this file.


#define DEBUG_TYPE   "instcombine"


 STATISTIC (NumDeadStore,"Number of dead stores eliminated")
 STATISTIC (NumGlobalCopies,"Number of allocas copied from constant global")
static bool pointsToConstantGlobal (Value *V)
static bool isOnlyCopiedFromConstantGlobal (Value *V, MemTransferInst *&TheCopy, SmallVectorImpl< Instruction * > &ToDelete)
static MemTransferInstisOnlyCopiedFromConstantGlobal (AllocaInst *AI, SmallVectorImpl< Instruction * > &ToDelete)
static LoadInstcombineLoadToNewType (InstCombiner &IC, LoadInst &LI, Type *NewTy)
 Helper to combine a load to a new type.
static InstructioncombineLoadToOperationType (InstCombiner &IC, LoadInst &LI)
 Combine loads to match the type of value their uses after looking through intervening bitcasts.
static InstructionInstCombineStoreToCast (InstCombiner &IC, StoreInst &SI)
static bool equivalentAddressValues (Value *A, Value *B)

Define Documentation

#define DEBUG_TYPE   "instcombine"

Definition at line 24 of file InstCombineLoadStoreAlloca.cpp.

Function Documentation

static LoadInst* combineLoadToNewType ( InstCombiner IC,
LoadInst LI,
Type NewTy 
) [static]
static Instruction* combineLoadToOperationType ( InstCombiner IC,
LoadInst LI 
) [static]

Combine loads to match the type of value their uses after looking through intervening bitcasts.

The core idea here is that if the result of a load is used in an operation, we should load the type most conducive to that operation. For example, when loading an integer and converting that immediately to a pointer, we should instead directly load a pointer.

However, this routine must never change the width of a load or the number of loads as that would introduce a semantic change. This combine is expected to be a semantic no-op which just allows loads to more closely model the types of their consuming operations.

Currently, we also refuse to change the precise type used for an atomic load or a volatile load. This is debatable, and might be reasonable to change later. However, it is risky in case some backend or other part of LLVM is relying on the exact type loaded to select appropriate atomic operations.

Definition at line 365 of file InstCombineLoadStoreAlloca.cpp.

References combineLoadToNewType(), llvm::InstCombiner::EraseInstFromFunction(), llvm::Value::hasOneUse(), llvm::LoadInst::isSimple(), LI, llvm::Value::replaceAllUsesWith(), llvm::Value::use_empty(), and llvm::Instruction::user_back().

Referenced by llvm::InstCombiner::visitLoadInst().

static bool equivalentAddressValues ( Value A,
Value B 
) [static]

equivalentAddressValues - Test if A and B will obviously have the same value. This includes recognizing that t0 and t1 will have the same value in code like this: t0 = getelementptr @a, 0, 3 store i32 0, i32* t0 t1 = getelementptr @a, 0, 3 t2 = load i32* t1

Definition at line 599 of file InstCombineLoadStoreAlloca.cpp.

Referenced by llvm::InstCombiner::visitStoreInst().

static Instruction* InstCombineStoreToCast ( InstCombiner IC,
StoreInst SI 
) [static]
static bool isOnlyCopiedFromConstantGlobal ( Value V,
MemTransferInst *&  TheCopy,
SmallVectorImpl< Instruction * > &  ToDelete 
) [static]

isOnlyCopiedFromConstantGlobal - Recursively walk the uses of a (derived) pointer to an alloca. Ignore any reads of the pointer, return false if we see any stores or other unknown uses. If we see pointer arithmetic, keep track of whether it moves the pointer (with IsOffset) but otherwise traverse the uses. If we see a memcpy/memmove that targets an unoffseted pointer to the alloca, and if the source pointer is a pointer to a constant global, we can optimize this.

Definition at line 53 of file InstCombineLoadStoreAlloca.cpp.

References llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::MemTransferInst::getSource(), I, llvm::MemIntrinsic::isVolatile(), LI, llvm::AArch64CC::MI, pointsToConstantGlobal(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), and llvm::SmallVectorTemplateBase< T, isPodLike >::push_back().

Referenced by isOnlyCopiedFromConstantGlobal(), and llvm::InstCombiner::visitAllocaInst().

static MemTransferInst* isOnlyCopiedFromConstantGlobal ( AllocaInst AI,
SmallVectorImpl< Instruction * > &  ToDelete 
) [static]

isOnlyCopiedFromConstantGlobal - Return true if the specified alloca is only modified by a copy from a constant global. If we can prove this, we can replace any uses of the alloca with uses of the global directly.

Definition at line 158 of file InstCombineLoadStoreAlloca.cpp.

References isOnlyCopiedFromConstantGlobal().

static bool pointsToConstantGlobal ( Value V) [static]

pointsToConstantGlobal - Return true if V (possibly indirectly) points to some part of a constant global variable. This intentionally only accepts constant expressions because we can't rewrite arbitrary instructions.

Definition at line 32 of file InstCombineLoadStoreAlloca.cpp.

References llvm::AddrSpaceCast, and llvm::WinEH::CE.

Referenced by isOnlyCopiedFromConstantGlobal().

STATISTIC ( NumDeadStore  ,
"Number of dead stores eliminated"   
STATISTIC ( NumGlobalCopies  ,
"Number of allocas copied from constant global"