LLVM  6.0.0svn
Macros | Functions | Variables
InstCombineCalls.cpp File Reference
#include "InstCombineInternal.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Statepoint.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <vector>
Include dependency graph for InstCombineCalls.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "instcombine"
 

Functions

 STATISTIC (NumSimplified, "Number of library calls simplified")
 
static TypegetPromotedType (Type *Ty)
 Return the specified type promoted as it would be to pass though a va_arg area. More...
 
static ConstantgetNegativeIsTrueBoolVec (ConstantDataVector *V)
 Return a constant boolean vector that has true elements in all positions where the input constant data vector has an element with the sign bit set. More...
 
static ValuesimplifyX86immShift (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 
static ValuesimplifyX86varShift (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 
static ValuesimplifyX86muldq (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 
static ValuesimplifyX86pack (IntrinsicInst &II, bool IsSigned)
 
static ValuesimplifyX86movmsk (const IntrinsicInst &II)
 
static ValuesimplifyX86insertps (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 
static ValuesimplifyX86extrq (IntrinsicInst &II, Value *Op0, ConstantInt *CILength, ConstantInt *CIIndex, InstCombiner::BuilderTy &Builder)
 Attempt to simplify SSE4A EXTRQ/EXTRQI instructions using constant folding or conversion to a shuffle vector. More...
 
static ValuesimplifyX86insertq (IntrinsicInst &II, Value *Op0, Value *Op1, APInt APLength, APInt APIndex, InstCombiner::BuilderTy &Builder)
 Attempt to simplify SSE4A INSERTQ/INSERTQI instructions using constant folding or conversion to a shuffle vector. More...
 
static ValuesimplifyX86pshufb (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 Attempt to convert pshufb* to shufflevector if the mask is constant. More...
 
static ValuesimplifyX86vpermilvar (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 Attempt to convert vpermilvar* to shufflevector if the mask is constant. More...
 
static ValuesimplifyX86vpermv (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 Attempt to convert vpermd/vpermps to shufflevector if the mask is constant. More...
 
static ValuesimplifyX86vpcom (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder, bool IsSigned)
 Decode XOP integer vector comparison intrinsics. More...
 
static ValueemitX86MaskSelect (Value *Mask, Value *Op0, Value *Op1, InstCombiner::BuilderTy &Builder)
 
static ValuesimplifyMinnumMaxnum (const IntrinsicInst &II)
 
static bool maskIsAllOneOrUndef (Value *Mask)
 
static ValuesimplifyMaskedLoad (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 
static InstructionsimplifyMaskedStore (IntrinsicInst &II, InstCombiner &IC)
 
static InstructionsimplifyMaskedGather (IntrinsicInst &II, InstCombiner &IC)
 
static InstructionsimplifyMaskedScatter (IntrinsicInst &II, InstCombiner &IC)
 
static InstructionfoldCttzCtlz (IntrinsicInst &II, InstCombiner &IC)
 
static InstructionfoldCtpop (IntrinsicInst &II, InstCombiner &IC)
 
static InstructionsimplifyX86MaskedLoad (IntrinsicInst &II, InstCombiner &IC)
 
static bool simplifyX86MaskedStore (IntrinsicInst &II, InstCombiner &IC)
 
static APFloat fmed3AMDGCN (const APFloat &Src0, const APFloat &Src1, const APFloat &Src2)
 
static bool haveSameOperands (const IntrinsicInst &I, const IntrinsicInst &E, unsigned NumOperands)
 
static bool removeTriviallyEmptyRange (IntrinsicInst &I, unsigned StartID, unsigned EndID, InstCombiner &IC)
 
static InstructionSimplifyNVVMIntrinsic (IntrinsicInst *II, InstCombiner &IC)
 
static bool isSafeToEliminateVarargsCast (const CallSite CS, const DataLayout &DL, const CastInst *const CI, const int ix)
 If this cast does not affect the value passed through the varargs area, we can eliminate the use of the cast. More...
 
static IntrinsicInstfindInitTrampolineFromAlloca (Value *TrampMem)
 
static IntrinsicInstfindInitTrampolineFromBB (IntrinsicInst *AdjustTramp, Value *TrampMem)
 
static IntrinsicInstfindInitTrampoline (Value *Callee)
 

Variables

static cl::opt< unsignedUnfoldElementAtomicMemcpyMaxElements ("unfold-element-atomic-memcpy-max-elements", cl::init(16), cl::desc("Maximum number of elements in atomic memcpy the optimizer is " "allowed to unfold"))
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "instcombine"

Definition at line 60 of file InstCombineCalls.cpp.

Function Documentation

◆ emitX86MaskSelect()

static Value* emitX86MaskSelect ( Value Mask,
Value Op0,
Value Op1,
InstCombiner::BuilderTy Builder 
)
static

◆ findInitTrampoline()

static IntrinsicInst* findInitTrampoline ( Value Callee)
static

Definition at line 3829 of file InstCombineCalls.cpp.

References llvm::AttributeList::addParamAttribute(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_begin(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_end(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_size(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::args(), llvm::AMDGPU::HSAMD::Kernel::Key::Args, AS, assert(), llvm::AMDGPU::HSAMD::Kernel::Key::Attrs, Callee, llvm::CallInst::Create(), llvm::InvokeInst::Create(), llvm::CastInst::CreateBitOrPointerCast(), llvm::dbgs(), DEBUG, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::doesNotThrow(), llvm::dyn_cast(), E, llvm::SmallVectorBase::empty(), llvm::Instruction::extractProfTotalWeight(), findInitTrampolineFromAlloca(), findInitTrampolineFromBB(), llvm::Attribute::get(), llvm::FunctionType::get(), llvm::AttributeSet::get(), llvm::AttributeList::get(), llvm::UndefValue::get(), llvm::CallInst::getArgOperand(), llvm::Function::getAttributes(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getAttributes(), llvm::ConstantExpr::getBitCast(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledValue(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCallingConv(), llvm::CastInst::getCastOpcode(), llvm::Value::getContext(), llvm::Instruction::getDebugLoc(), llvm::PointerType::getElementType(), llvm::AttributeList::getFnAttributes(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), llvm::Type::getInt1PtrTy(), llvm::IntrinsicInst::getIntrinsicID(), llvm::Constant::getNullValue(), llvm::FunctionType::getNumParams(), llvm::User::getOperand(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getOperandBundlesAsDefs(), llvm::AttributeList::getParamAttributes(), llvm::FunctionType::getParamType(), llvm::Type::getPointerElementType(), getPromotedType(), llvm::FunctionType::getReturnType(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::GlobalValue::getType(), llvm::PointerType::getUnqual(), llvm::GlobalValue::getValueType(), llvm::AttributeSet::hasAttribute(), llvm::AttributeList::hasAttrSomewhere(), llvm::AttributeList::hasParamAttribute(), llvm::Value::hasValueHandle(), I, llvm::isAllocLikeFn(), llvm::CastInst::isBitOrNoopPointerCastable(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::isConvergent(), llvm::AttributeList::isEmpty(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::isInAllocaArgument(), llvm::isKnownNonZero(), isSafeToEliminateVarargsCast(), llvm::Type::isSized(), llvm::Type::isStructTy(), llvm::FunctionType::isVarArg(), llvm::Type::isVoidTy(), IT, NC, llvm::AttrBuilder::overlaps(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::paramHasAttr(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), llvm::AttrBuilder::remove(), llvm::SmallVectorImpl< T >::reserve(), llvm::AttributeList::ReturnIndex, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setAttributes(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setCalledFunction(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setCallingConv(), llvm::Instruction::setDebugLoc(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setDoesNotThrow(), llvm::Value::setName(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setNotConvergent(), llvm::SmallVectorTemplateCommon< T >::size(), llvm::Value::stripPointerCasts(), llvm::AttributeFuncs::typeIncompatible(), llvm::Value::use_empty(), llvm::Value::users(), llvm::ValueHandleBase::ValueIsDeleted(), llvm::ValueHandleBase::ValueIsRAUWd(), and llvm::RISCVFenceField::W.

◆ findInitTrampolineFromAlloca()

static IntrinsicInst* findInitTrampolineFromAlloca ( Value TrampMem)
static

◆ findInitTrampolineFromBB()

static IntrinsicInst* findInitTrampolineFromBB ( IntrinsicInst AdjustTramp,
Value TrampMem 
)
static

◆ fmed3AMDGCN()

static APFloat fmed3AMDGCN ( const APFloat Src0,
const APFloat Src1,
const APFloat Src2 
)
static

◆ foldCtpop()

static Instruction* foldCtpop ( IntrinsicInst II,
InstCombiner IC 
)
static

◆ foldCttzCtlz()

static Instruction* foldCttzCtlz ( IntrinsicInst II,
InstCombiner IC 
)
static

◆ getNegativeIsTrueBoolVec()

static Constant* getNegativeIsTrueBoolVec ( ConstantDataVector V)
static

Return a constant boolean vector that has true elements in all positions where the input constant data vector has an element with the sign bit set.

Definition at line 82 of file InstCombineCalls.cpp.

References assert(), llvm::dyn_cast(), E, llvm::IntegerType::get(), llvm::ConstantInt::get(), llvm::PointerType::get(), llvm::ConstantVector::get(), llvm::CallInst::getArgOperand(), llvm::Value::getContext(), llvm::Instruction::getDebugLoc(), llvm::MemIntrinsic::getDest(), llvm::ConstantDataSequential::getElementAsConstant(), llvm::ElementUnorderedAtomicMemCpyInst::getElementSizeInBytes(), llvm::ConstantDataSequential::getElementType(), llvm::Type::getInt1Ty(), llvm::Type::getIntNPtrTy(), llvm::getKnownAlignment(), llvm::ElementUnorderedAtomicMemCpyInst::getLength(), llvm::ConstantInt::getLimitedValue(), llvm::Constant::getNullValue(), llvm::ConstantDataSequential::getNumElements(), llvm::CallInst::getParamAlignment(), llvm::Type::getPointerAddressSpace(), llvm::ElementUnorderedAtomicMemCpyInst::getRawDest(), llvm::ElementUnorderedAtomicMemCpyInst::getRawSource(), llvm::ConstantInt::getType(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), I, llvm::Type::isIntegerTy(), llvm::isPowerOf2_32(), isZero(), llvm::SPII::Load, llvm::max(), llvm::LLVMContext::MD_mem_parallel_loop_access, llvm::LLVMContext::MD_tbaa, llvm::LLVMContext::MD_tbaa_struct, MI, llvm::MinAlign(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::LoadInst::setAlignment(), llvm::StoreInst::setAlignment(), llvm::Instruction::setDebugLoc(), llvm::ElementUnorderedAtomicMemCpyInst::setLength(), llvm::Instruction::setMetadata(), llvm::LoadInst::setOrdering(), llvm::StoreInst::setOrdering(), llvm::AMDGPU::HSAMD::Kernel::Arg::Key::Size, llvm::SPII::Store, UnfoldElementAtomicMemcpyMaxElements, and llvm::Unordered.

Referenced by simplifyX86MaskedLoad(), simplifyX86MaskedStore(), and llvm::InstCombiner::visitCallInst().

◆ getPromotedType()

static Type* getPromotedType ( Type Ty)
static

Return the specified type promoted as it would be to pass though a va_arg area.

Definition at line 72 of file InstCombineCalls.cpp.

References llvm::Type::getContext(), and llvm::Type::getInt32Ty().

Referenced by findInitTrampoline().

◆ haveSameOperands()

static bool haveSameOperands ( const IntrinsicInst I,
const IntrinsicInst E,
unsigned  NumOperands 
)
static

◆ isSafeToEliminateVarargsCast()

static bool isSafeToEliminateVarargsCast ( const CallSite  CS,
const DataLayout DL,
const CastInst *const  CI,
const int  ix 
)
static

◆ maskIsAllOneOrUndef()

static bool maskIsAllOneOrUndef ( Value Mask)
static

Definition at line 1242 of file InstCombineCalls.cpp.

References llvm::dyn_cast(), E, I, and llvm::BitmaskEnumDetail::Mask().

Referenced by simplifyMaskedLoad().

◆ removeTriviallyEmptyRange()

static bool removeTriviallyEmptyRange ( IntrinsicInst I,
unsigned  StartID,
unsigned  EndID,
InstCombiner IC 
)
static

◆ simplifyMaskedGather()

static Instruction* simplifyMaskedGather ( IntrinsicInst II,
InstCombiner IC 
)
static

◆ simplifyMaskedLoad()

static Value* simplifyMaskedLoad ( const IntrinsicInst II,
InstCombiner::BuilderTy Builder 
)
static

◆ simplifyMaskedScatter()

static Instruction* simplifyMaskedScatter ( IntrinsicInst II,
InstCombiner IC 
)
static

◆ simplifyMaskedStore()

static Instruction* simplifyMaskedStore ( IntrinsicInst II,
InstCombiner IC 
)
static

◆ simplifyMinnumMaxnum()

static Value* simplifyMinnumMaxnum ( const IntrinsicInst II)
static

◆ SimplifyNVVMIntrinsic()

static Instruction* SimplifyNVVMIntrinsic ( IntrinsicInst II,
InstCombiner IC 
)
static

◆ simplifyX86extrq()

static Value* simplifyX86extrq ( IntrinsicInst II,
Value Op0,
ConstantInt CILength,
ConstantInt CIIndex,
InstCombiner::BuilderTy Builder 
)
static

◆ simplifyX86immShift()

static Value* simplifyX86immShift ( const IntrinsicInst II,
InstCombiner::BuilderTy Builder 
)
static

◆ simplifyX86insertps()

static Value* simplifyX86insertps ( const IntrinsicInst II,
InstCombiner::BuilderTy Builder 
)
static

◆ simplifyX86insertq()

static Value* simplifyX86insertq ( IntrinsicInst II,
Value Op0,
Value Op1,
APInt  APLength,
APInt  APIndex,
InstCombiner::BuilderTy Builder 
)
static

◆ simplifyX86MaskedLoad()

static Instruction* simplifyX86MaskedLoad ( IntrinsicInst II,
InstCombiner IC 
)
static

◆ simplifyX86MaskedStore()

static bool simplifyX86MaskedStore ( IntrinsicInst II,
InstCombiner IC 
)
static

◆ simplifyX86movmsk()

static Value* simplifyX86movmsk ( const IntrinsicInst II)
static

◆ simplifyX86muldq()

static Value* simplifyX86muldq ( const IntrinsicInst II,
InstCombiner::BuilderTy Builder 
)
static

◆ simplifyX86pack()

static Value* simplifyX86pack ( IntrinsicInst II,
bool  IsSigned 
)
static

◆ simplifyX86pshufb()

static Value* simplifyX86pshufb ( const IntrinsicInst II,
InstCombiner::BuilderTy Builder 
)
static

◆ simplifyX86varShift()

static Value* simplifyX86varShift ( const IntrinsicInst II,
InstCombiner::BuilderTy Builder 
)
static

◆ simplifyX86vpcom()

static Value* simplifyX86vpcom ( const IntrinsicInst II,
InstCombiner::BuilderTy Builder,
bool  IsSigned 
)
static

◆ simplifyX86vpermilvar()

static Value* simplifyX86vpermilvar ( const IntrinsicInst II,
InstCombiner::BuilderTy Builder 
)
static

◆ simplifyX86vpermv()

static Value* simplifyX86vpermv ( const IntrinsicInst II,
InstCombiner::BuilderTy Builder 
)
static

◆ STATISTIC()

STATISTIC ( NumSimplified  ,
"Number of library calls simplified"   
)

Variable Documentation

◆ UnfoldElementAtomicMemcpyMaxElements

cl::opt<unsigned> UnfoldElementAtomicMemcpyMaxElements("unfold-element-atomic-memcpy-max-elements", cl::init(16), cl::desc("Maximum number of elements in atomic memcpy the optimizer is " "allowed to unfold"))
static