LLVM  8.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/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.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/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <utility>
#include <vector>

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 ValuesimplifyX86AddsSubs (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 
static ValuesimplifyX86immShift (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 
static ValuesimplifyX86varShift (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 
static ValuesimplifyX86pack (IntrinsicInst &II, bool IsSigned)
 
static ValuesimplifyX86round (IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 
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 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 InstructionsimplifyInvariantGroupIntrinsic (IntrinsicInst &II, InstCombiner &IC)
 This function transforms launder.invariant.group and strip.invariant.group like: launder(launder(x)) -> launder(x) (the result is not the argument) launder(strip(x)) -> launder(x) strip(strip(x)) -> strip(x) (the result is not the argument) strip(launder(x)) -> strip(x) This is legal because it preserves the most recent information about the presence or absence of invariant.group. More...
 
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 ValuesimplifyNeonTbl1 (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 Convert a table lookup to shufflevector if the mask is constant. More...
 
static ValuesimplifyNeonVld1 (const IntrinsicInst &II, unsigned MemAlign, InstCombiner::BuilderTy &Builder)
 Convert a vector load intrinsic into a simple llvm load instruction. More...
 
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< unsignedGuardWideningWindow ("instcombine-guard-widening-window", cl::init(3), cl::desc("How wide an instruction window to bypass looking for " "another guard"))
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "instcombine"

Definition at line 72 of file InstCombineCalls.cpp.

Function Documentation

◆ findInitTrampoline()

static IntrinsicInst* findInitTrampoline ( Value Callee)
static

Definition at line 4032 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, assert(), llvm::AMDGPU::HSAMD::Kernel::Key::Attrs, Callee, llvm::CallInst::Create(), llvm::InvokeInst::Create(), llvm::CastInst::CreateBitOrPointerCast(), llvm::dbgs(), 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::CallBase< InstTy >::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::Instruction::getFunction(), 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::CallBase< InstTy >::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(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::isMustTailCall(), isSafeToEliminateVarargsCast(), llvm::Type::isSized(), llvm::Type::isStructTy(), llvm::FunctionType::isVarArg(), llvm::Type::isVoidTy(), IT, LLVM_DEBUG, NC, llvm::NullPointerIsDefined(), 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::SmallVectorBase::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

◆ 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 84 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 1197 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

◆ simplifyInvariantGroupIntrinsic()

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

This function transforms launder.invariant.group and strip.invariant.group like: launder(launder(x)) -> launder(x) (the result is not the argument) launder(strip(x)) -> launder(x) strip(strip(x)) -> strip(x) (the result is not the argument) strip(launder(x)) -> strip(x) This is legal because it preserves the most recent information about the presence or absence of invariant.group.

Definition at line 1262 of file InstCombineCalls.cpp.

References Arg, llvm::InstCombiner::Builder, llvm::IRBuilder< T, Inserter >::CreateAddrSpaceCast(), llvm::IRBuilder< T, Inserter >::CreateBitCast(), llvm::IRBuilder< T, Inserter >::CreateLaunderInvariantGroup(), llvm::IRBuilder< T, Inserter >::CreateStripInvariantGroup(), llvm::CallBase< InstTy >::getArgOperand(), llvm::IntrinsicInst::getIntrinsicID(), llvm::Type::getPointerAddressSpace(), llvm::Value::getType(), llvm_unreachable, Result, llvm::Value::stripPointerCasts(), and llvm::Value::stripPointerCastsAndInvariantGroups().

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

◆ 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

◆ simplifyNeonTbl1()

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

Convert a table lookup to shufflevector if the mask is constant.

This could benefit tbl1 if the mask is { 7,6,5,4,3,2,1,0 }, in which case we could lower the shufflevector with rev64 instructions as it's actually a byte reverse.

Definition at line 1482 of file InstCombineCalls.cpp.

References C, llvm::IRBuilder< T, Inserter >::CreateShuffleVector(), llvm::dyn_cast(), llvm::ConstantDataVector::get(), llvm::CallBase< InstTy >::getArgOperand(), llvm::Value::getContext(), llvm::Constant::getNullValue(), llvm::Value::getType(), I, llvm::makeArrayRef(), and llvm::NVPTX::PTXLdStInstCode::V2.

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

◆ simplifyNeonVld1()

static Value* simplifyNeonVld1 ( const IntrinsicInst II,
unsigned  MemAlign,
InstCombiner::BuilderTy Builder 
)
static

Convert a vector load intrinsic into a simple llvm load instruction.

This is beneficial when the underlying object being addressed comes from a constant, since we get constant-folding for free.

Definition at line 1521 of file InstCombineCalls.cpp.

References llvm::IRBuilder< T, Inserter >::CreateAlignedLoad(), llvm::IRBuilder< T, Inserter >::CreateBitCast(), llvm::dyn_cast(), llvm::PointerType::get(), llvm::CallBase< InstTy >::getArgOperand(), llvm::ConstantInt::getLimitedValue(), llvm::Value::getType(), and llvm::isPowerOf2_32().

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

◆ SimplifyNVVMIntrinsic()

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

◆ simplifyX86AddsSubs()

static Value* simplifyX86AddsSubs ( const IntrinsicInst II,
InstCombiner::BuilderTy Builder 
)
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

Attempt to simplify SSE4A INSERTQ/INSERTQI instructions using constant folding or conversion to a shuffle vector.

Definition at line 930 of file InstCombineCalls.cpp.

References llvm::APInt::getZExtValue(), and llvm::APInt::zextOrTrunc().

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

◆ 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

◆ simplifyX86pack()

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

◆ simplifyX86pshufb()

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

◆ simplifyX86round()

static Value* simplifyX86round ( 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

◆ GuardWideningWindow

cl::opt<unsigned> GuardWideningWindow("instcombine-guard-widening-window", cl::init(3), cl::desc("How wide an instruction window to bypass looking for " "another guard"))
static