29 using namespace llvm::PatternMatch;
43 case Intrinsic::log10:
48 case Intrinsic::copysign:
49 case Intrinsic::floor:
51 case Intrinsic::trunc:
53 case Intrinsic::nearbyint:
55 case Intrinsic::bswap:
56 case Intrinsic::bitreverse:
57 case Intrinsic::ctpop:
60 case Intrinsic::fmuladd:
73 unsigned ScalarOpdIdx) {
78 return (ScalarOpdIdx == 1);
94 ID == Intrinsic::lifetime_end || ID == Intrinsic::assume)
111 std::advance(GEPTI, LastOperand - 2);
136 if (i != InductionOperand &&
144 Value *UniqueCast =
nullptr;
147 if (CI && CI->
getType() == Ty) {
161 if (!PtrTy || PtrTy->isAggregateType())
170 int64_t PtrAccessSize = 1;
190 if (OrigPtr == Ptr) {
191 if (
const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(V)) {
192 if (M->getOperand(0)->getSCEVType() !=
scConstant)
195 const APInt &APStepVal = cast<SCEVConstant>(M->getOperand(0))->getAPInt();
202 if (PtrAccessSize != StepVal)
204 V = M->getOperand(1);
209 Type *StripedOffRecurrenceCast =
nullptr;
211 StripedOffRecurrenceCast =
C->getType();
226 if (StripedOffRecurrenceCast)
243 return C->getAggregateElement(EltNo);
247 if (!isa<ConstantInt>(III->getOperand(2)))
249 unsigned IIElt = cast<ConstantInt>(III->getOperand(2))->getZExtValue();
254 return III->getOperand(1);
263 int InEl = SVI->getMaskValue(EltNo);
266 if (InEl < (
int)LHSWidth)
275 if (Elt->isNullValue())
289 if (
auto *
C = dyn_cast<Constant>(V))
290 if (isa<VectorType>(V->
getType()))
291 return C->getSplatValue();
297 for (
int MaskElt : ShuffleInst->getShuffleMask())
298 if (MaskElt != 0 && MaskElt != -1)
301 auto *InsertEltInst =
303 if (!InsertEltInst || !isa<ConstantInt>(InsertEltInst->getOperand(2)) ||
304 !cast<ConstantInt>(InsertEltInst->getOperand(2))->
isZero())
326 bool SeenExtFromIllegalType =
false;
327 for (
auto *BB : Blocks)
328 for (
auto &
I : *BB) {
331 if (TTI && (isa<ZExtInst>(&
I) || isa<SExtInst>(&
I)) &&
333 SeenExtFromIllegalType =
true;
336 if ((isa<TruncInst>(&
I) || isa<ICmpInst>(&
I)) &&
337 !
I.getType()->isVectorTy() &&
338 I.getOperand(0)->getType()->getScalarSizeInBits() <= 64) {
341 if (TTI && isa<TruncInst>(&
I) && TTI->
isTypeLegal(
I.getType()))
349 if (Worklist.
empty() || (TTI && !SeenExtFromIllegalType))
353 while (!Worklist.
empty()) {
357 if (Visited.
count(Val))
362 if (!isa<Instruction>(Val))
377 if (isa<SExtInst>(I) || isa<ZExtInst>(I) || isa<LoadInst>(I) ||
378 !InstructionSet.
count(I))
384 if (isa<BitCastInst>(I) || isa<PtrToIntInst>(
I) || isa<IntToPtrInst>(I) ||
386 DBits[Leader] |= ~0ULL;
396 if (DBits[Leader] == ~0ULL)
400 for (
Value *O : cast<User>(I)->operands()) {
409 for (
auto &
I : DBits)
410 for (
auto *U :
I.first->users())
411 if (U->getType()->isIntegerTy() && DBits.count(U) == 0)
415 uint64_t LeaderDemandedBits = 0;
417 LeaderDemandedBits |= DBits[*
MI];
419 uint64_t MinBW = (
sizeof(LeaderDemandedBits) * 8) -
431 if (isa<PHINode>(*
MI) && MinBW < (*MI)->getType()->getScalarSizeInBits()) {
439 if (!isa<Instruction>(*
MI))
441 Type *Ty = (*MI)->getType();
443 Ty = cast<Instruction>(*MI)->getOperand(0)->getType();
444 if (MinBW < Ty->getScalarSizeInBits())
445 MinBWs[cast<Instruction>(*MI)] = MinBW;
464 for (
int J = 1,
E = VL.
size(); MD && J !=
E; ++J) {
496 for (
unsigned i = 0; i < VF; i++)
497 for (
unsigned j = 0; j < NumVecs; j++)
504 unsigned Stride,
unsigned VF) {
506 for (
unsigned i = 0; i < VF; i++)
513 unsigned NumInts,
unsigned NumUndefs) {
515 for (
unsigned i = 0; i < NumInts; i++)
519 for (
unsigned i = 0; i < NumUndefs; i++)
532 assert(VecTy1 && VecTy2 &&
534 "Expect two vectors with the same element type");
537 unsigned NumElts2 = VecTy2->getNumElements();
538 assert(NumElts1 >= NumElts2 &&
"Unexpect the first vector has less elements");
540 if (NumElts1 > NumElts2) {
552 unsigned NumVecs = Vecs.
size();
553 assert(NumVecs > 1 &&
"Should be at least two vectors");
559 for (
unsigned i = 0; i < NumVecs - 1; i += 2) {
560 Value *V0 = ResList[i], *V1 = ResList[i + 1];
561 assert((V0->
getType() == V1->getType() || i == NumVecs - 2) &&
562 "Only the last vector may have a different type");
568 if (NumVecs % 2 != 0)
572 NumVecs = ResList.
size();
573 }
while (NumVecs > 1);
Value * getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp)
Get the stride of a pointer access in a loop.
void push_back(const T &Elt)
Value * stripGetElementPtr(Value *Ptr, ScalarEvolution *SE, Loop *Lp)
If the argument is a GEP, then returns the operand identified by getGEPInductionOperand.
A parsed version of the target data layout string in and methods for querying it. ...
Type * getIndexedType() const
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
uint64_t getZExtValue() const
Get zero extended value.
Value * findScalarElement(Value *V, unsigned EltNo)
Given a vector and an element number, see if the scalar value is already around as a register...
match_zero m_Zero()
Match an arbitrary zero/null constant.
const Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
unsigned getNumOperands() const
The main scalar evolution driver.
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
This class represents a function call, abstracting a target machine's calling convention.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
static uint64_t round(uint64_t Acc, uint64_t Input)
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
This instruction constructs a fixed permutation of two input vectors.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
This class implements a map that also provides access to all stored values in a deterministic order...
bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
member_iterator unionSets(const ElemTy &V1, const ElemTy &V2)
union - Merge the two equivalence sets for the specified values, inserting them if they do not alread...
member_iterator member_begin(iterator I) const
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
This is the base class for unary cast operator classes.
Intrinsic::ID getVectorIntrinsicIDForCall(const CallInst *CI, const TargetLibraryInfo *TLI)
Returns intrinsic ID for call.
Intrinsic::ID getIntrinsicForCallSite(ImmutableCallSite ICS, const TargetLibraryInfo *TLI)
Map a call instruction to an intrinsic ID.
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
bool match(Val *V, const Pattern &P)
This is the base class for all instructions that perform data casts.
static Value * concatenateTwoVectors(IRBuilder<> &Builder, Value *V1, Value *V2)
A helper function for concatenating vectors.
member_iterator member_end() const
static Constant * get(ArrayRef< Constant * > V)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
This node represents multiplication of some number of SCEVs.
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
LLVM_NODISCARD bool empty() const
Constant * createSequentialMask(IRBuilder<> &Builder, unsigned Start, unsigned NumInts, unsigned NumUndefs)
Create a sequential shuffle mask.
Value * concatenateVectors(IRBuilder<> &Builder, ArrayRef< Value * > Vecs)
Concatenate a list of vectors.
This node represents a polynomial recurrence on the trip count of the specified loop.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static MDNode * intersect(MDNode *A, MDNode *B)
size_t size() const
size - Get the array size.
Class to represent pointers.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
This instruction inserts a single (scalar) element into a VectorType value.
The instances of the Type class are immutable: once they are created, they are never changed...
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
bool isVectorTy() const
True if this is an instance of VectorType.
This is an important base class in LLVM.
int64_t getSExtValue() const
Get sign extended value.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
MapVector< Instruction *, uint64_t > computeMinimumValueSizes(ArrayRef< BasicBlock * > Blocks, DemandedBits &DB, const TargetTransformInfo *TTI=nullptr)
Compute a map of integer instructions to their minimum legal type size.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
EquivalenceClasses - This represents a collection of equivalence classes and supports three efficient...
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
unsigned getBitWidth() const
Return the number of bits in the APInt.
uint64_t getNumElements() const
Value * getOperand(unsigned i) const
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
const ElemTy & getOrInsertLeaderValue(const ElemTy &V)
getOrInsertLeaderValue - Return the leader for the specified value that is in the set...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
LLVM_NODISCARD T pop_back_val()
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
bool hasVectorInstrinsicScalarOpd(Intrinsic::ID ID, unsigned ScalarOpdIdx)
Identifies if the intrinsic has a scalar operand.
APInt getDemandedBits(Instruction *I)
Return the bits demanded from instruction I.
Class to represent vector types.
Class for arbitrary precision integers.
bool isIntegerTy() const
True if this is an instance of IntegerType.
iterator_range< user_iterator > users()
unsigned getVectorNumElements() const
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Value * getUniqueCastUse(Value *Ptr, Loop *Lp, Type *Ty)
If a value has only one user that is a CastInst, return it.
llvm_unreachable("Unknown RegBank!")
Constant * createStrideMask(IRBuilder<> &Builder, unsigned Start, unsigned Stride, unsigned VF)
Create a stride shuffle mask.
unsigned getGEPInductionOperand(const GetElementPtrInst *Gep)
Find the operand of the GEP that should be checked for consecutive stores.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This class represents an analyzed expression in the program.
Represents a single loop in the control flow graph.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Constant * createInterleaveMask(IRBuilder<> &Builder, unsigned VF, unsigned NumVecs)
Create an interleave shuffle mask.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
Type * getResultElementType() const
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
Instruction * propagateMetadata(Instruction *I, ArrayRef< Value * > VL)
Specifically, let Kinds = [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath, MD_nontemporal].
gep_type_iterator gep_type_begin(const User *GEP)
bool isTriviallyVectorizable(Intrinsic::ID ID)
Identify if the intrinsic is trivially vectorizable.