LLVM  13.0.0git
Macros | Functions | Variables
InstCombineCalls.cpp File Reference
#include "InstCombineInternal.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/FloatingPointMode.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/AliasAnalysis.h"
#include "llvm/Analysis/AssumeBundleQueries.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.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/IntrinsicsAArch64.h"
#include "llvm/IR/IntrinsicsAMDGPU.h"
#include "llvm/IR/IntrinsicsARM.h"
#include "llvm/IR/IntrinsicsHexagon.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/InstCombine/InstCombiner.h"
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
#include "llvm/Transforms/Utils/Local.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 InstructionsimplifyInvariantGroupIntrinsic (IntrinsicInst &II, InstCombinerImpl &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 InstructionfoldCttzCtlz (IntrinsicInst &II, InstCombinerImpl &IC)
 
static InstructionfoldCtpop (IntrinsicInst &II, InstCombinerImpl &IC)
 
static ValuesimplifyNeonTbl1 (const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
 Convert a table lookup to shufflevector if the mask is constant. More...
 
static bool haveSameOperands (const IntrinsicInst &I, const IntrinsicInst &E, unsigned NumOperands)
 
static bool removeTriviallyEmptyRange (IntrinsicInst &EndI, InstCombinerImpl &IC, std::function< bool(const IntrinsicInst &)> IsStart)
 
static CallInstcanonicalizeConstantArg0ToArg1 (CallInst &Call)
 
static InstructioncreateOverflowTuple (IntrinsicInst *II, Value *Result, Constant *Overflow)
 Creates a result tuple for an overflow intrinsic II with a given Result and a constant Overflow value. More...
 
static Optional< bool > getKnownSign (Value *Op, Instruction *CxtI, const DataLayout &DL, AssumptionCache *AC, DominatorTree *DT)
 
static InstructionfoldClampRangeOfTwo (IntrinsicInst *II, InstCombiner::BuilderTy &Builder)
 If we have a clamp pattern like max (min X, 42), 41 – where the output can only be one of two possible constant values – turn that into a select of constants. More...
 
static bool isSafeToEliminateVarargsCast (const CallBase &Call, 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< unsigned > GuardWideningWindow ("instcombine-guard-widening-window", cl::init(3), cl::desc("How wide an instruction window to bypass looking for " "another guard"))
 
cl::opt< bool > EnableKnowledgeRetention
 enable preservation of attributes in assume like: call void @llvm.assume(i1 true) [ "nonnull"(i32* PTR) ] More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "instcombine"

Definition at line 83 of file InstCombineCalls.cpp.

Function Documentation

◆ canonicalizeConstantArg0ToArg1()

static CallInst* canonicalizeConstantArg0ToArg1 ( CallInst Call)
static

Definition at line 688 of file InstCombineCalls.cpp.

References assert().

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

◆ createOverflowTuple()

static Instruction* createOverflowTuple ( IntrinsicInst II,
Value Result,
Constant Overflow 
)
static

Creates a result tuple for an overflow intrinsic II with a given Result and a constant Overflow value.

Definition at line 701 of file InstCombineCalls.cpp.

References llvm::InsertValueInst::Create(), llvm::ConstantStruct::get(), llvm::UndefValue::get(), llvm::Value::getType(), and llvm::ARM_MB::ST.

◆ findInitTrampoline()

static IntrinsicInst* findInitTrampoline ( Value Callee)
static

◆ findInitTrampolineFromAlloca()

static IntrinsicInst* findInitTrampolineFromAlloca ( Value TrampMem)
static

◆ findInitTrampolineFromBB()

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

◆ foldClampRangeOfTwo()

static Instruction* foldClampRangeOfTwo ( IntrinsicInst II,
InstCombiner::BuilderTy Builder 
)
static

◆ foldCtpop()

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

◆ foldCttzCtlz()

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

◆ getKnownSign()

static Optional<bool> getKnownSign ( Value Op,
Instruction CxtI,
const DataLayout DL,
AssumptionCache AC,
DominatorTree DT 
)
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 99 of file InstCombineCalls.cpp.

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

◆ haveSameOperands()

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

Definition at line 633 of file InstCombineCalls.cpp.

References assert(), E, i, and I.

Referenced by removeTriviallyEmptyRange().

◆ isSafeToEliminateVarargsCast()

static bool isSafeToEliminateVarargsCast ( const CallBase Call,
const DataLayout DL,
const CastInst *const  CI,
const int  ix 
)
static

If this cast does not affect the value passed through the varargs area, we can eliminate the use of the cast.

Definition at line 2005 of file InstCombineCalls.cpp.

References DL, llvm::User::getOperand(), llvm::Value::getType(), llvm::CastInst::isLosslessCast(), and llvm::Type::isSized().

◆ removeTriviallyEmptyRange()

static bool removeTriviallyEmptyRange ( IntrinsicInst EndI,
InstCombinerImpl IC,
std::function< bool(const IntrinsicInst &)>  IsStart 
)
static

◆ simplifyInvariantGroupIntrinsic()

static Instruction* simplifyInvariantGroupIntrinsic ( IntrinsicInst II,
InstCombinerImpl 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 396 of file InstCombineCalls.cpp.

References Arg, llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateAddrSpaceCast(), llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateLaunderInvariantGroup(), llvm::IRBuilderBase::CreateStripInvariantGroup(), llvm::CallBase::getArgOperand(), llvm::IntrinsicInst::getIntrinsicID(), llvm::Type::getPointerAddressSpace(), llvm::Value::getType(), Intr, and llvm_unreachable.

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

◆ 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 597 of file InstCombineCalls.cpp.

References Builder, llvm::Constant::getAggregateElement(), llvm::CallBase::getArgOperand(), llvm::Constant::getNullValue(), llvm::Value::getType(), I, llvm::makeArrayRef(), and llvm::NVPTX::PTXLdStInstCode::V2.

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

◆ STATISTIC()

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

Variable Documentation

◆ EnableKnowledgeRetention

cl::opt<bool> EnableKnowledgeRetention

enable preservation of attributes in assume like: call void @llvm.assume(i1 true) [ "nonnull"(i32* PTR) ]

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

◆ 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