28#define DEBUG_PREFIX_LOCAL DEBUG_PREFIX "LoadStoreVec: "
33 const auto &LegalityRes = Legality->canVectorizeLSV(Bndl);
41void LoadStoreVec::saveIR(
Region &R) {
44 CostBefore = SB.getAfterCost() - SB.getBeforeCost();
45 Rgn->getContext().save();
48bool LoadStoreVec::acceptOrRevert() {
53 <<
" (After=" << CostAfter <<
" Before=" << CostBefore
56 if (CostGain > Opts.sbvec_cost_threshold) {
68 Loads, A->getScalarEvolution(), *DL))
70 if (!canVectorize(Loads))
83 if (DestTy->isPointerTy())
84 assert(!DL->isNonIntegralAddressSpace(DestTy->getPointerAddressSpace()) &&
85 "DestTy has no fixed size");
86 Type *SrcTy =
C->getType();
91 if (!SrcTy->isIntegerTy()) {
94 : ConstantExpr::getBitCast(
C, IntTy);
96 if (DestTy->isIntegerTy())
99 : ConstantExpr::getBitCast(AsInt, DestTy);
105 auto *LaneTy = VecTy->getScalarType();
111 "Chain contains a constant which cannot be converted or split");
115 SmallVector<Constant *, 4> ConstantElements;
116 for (Constant *COp : Constants) {
121 for (
Value *Elm : AggrCOp->operands())
125 ConstantElements.push_back(SeqCOp->getElementAsConstant(ElmIdx));
127 auto *ZeroElm =
Zero->getSequentialElement();
128 for ([[maybe_unused]]
auto Cnt :
130 ConstantElements.push_back(ZeroElm);
133 for ([[maybe_unused]]
auto Cnt :
137 ConstantElements.push_back(Elm);
140 for ([[maybe_unused]]
auto Cnt :
144 ConstantElements.push_back(Elm);
148 for ([[maybe_unused]]
auto Cnt :
152 ConstantElements.push_back(Elm);
157 ConstantElements.push_back(COp);
168 LaneTyConstants.reserve(ConstantElements.size());
169 for (Constant *
C : ConstantElements) {
171 if (Bits == LaneBits) {
172 Constant *Lane = getEquivalentConstantWithType(
C, LaneTy);
175 LaneTyConstants.push_back(Lane);
176 }
else if (Bits > LaneBits) {
185 Val = CI->getValue();
187 Val = CFP->getValue().bitcastToAPInt();
190 unsigned NumSlices =
Bits / LaneBits;
192 unsigned EndianAwareSlice =
193 DL->isLittleEndian() ? SliceIdx : NumSlices - 1 - SliceIdx;
197 *Ctx, Val.extractBits(LaneBits, EndianAwareSlice * LaneBits));
198 Constant *SliceC = getEquivalentConstantWithType(SliceCInt, LaneTy);
199 if (SliceC ==
nullptr)
201 LaneTyConstants.push_back(SliceC);
212 Stores, A->getScalarEvolution(), *DL))
214 if (!canVectorize(Stores))
218 for (
auto *
I : Stores) {
231 if (LI->getParent() != BB)
233 if (LI->hasNUsesOrMore(2))
239 if (!AllLoads && !AllConstants)
245 Value *VecOp =
nullptr;
246 SmallVector<Instruction *, 8> Loads;
251 VecOp = createVectorLoad(Loads);
252 if (VecOp ==
nullptr) {
256 }
else if (AllConstants) {
261 VecOp = createConstantVector(Constants);
262 if (VecOp ==
nullptr) {
274 DeadInstrMorgue.collectPotentiallyDeadInstrs(Stores);
276 DeadInstrMorgue.collectPotentiallyDeadInstrs<
Instruction>(Loads);
277 DeadInstrMorgue.tryEraseDeadInstrs();
279 return acceptOrRevert();
285 Loads, A->getScalarEvolution(), *DL))
287 auto VecTy = canVectorize(Loads);
300 auto *
VecLoad = createVectorLoad(Loads);
301 if (VecLoad ==
nullptr) {
309 if (OrigLoad->hasNUses(0))
313 OrigLoad->replaceAllUsesWith(Unpacked);
316 DeadInstrMorgue.collectPotentiallyDeadInstrs(Loads);
317 DeadInstrMorgue.tryEraseDeadInstrs();
319 if (!acceptOrRevert())
328 Function &
F = *Bndl[0]->getParent()->getParent();
329 DL = &
F.getParent()->getDataLayout();
330 Ctx = &
F.getContext();
333 Legality = std::make_unique<LegalityAnalysis>(
334 A->getAA(), A->getScalarEvolution(),
F.getParent()->getDataLayout(),
337 auto Opc = Bndl[0]->getOpcode();
340 "Expected a homogeneous seed slice!");
344 case Instruction::Opcode::Load:
345 Changed = vectorizeLoads(Bndl, Rgn) !=
nullptr;
347 case Instruction::Opcode::Store:
348 Changed = vectorizeStores(Bndl, Rgn);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file defines the DenseSet and SmallDenseSet classes.
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
static constexpr Value * getValue(Ty &ValueOrUse)
#define DEBUG_PREFIX_LOCAL
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
InstListType::iterator iterator
Instruction iterators...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An ArrayRef of Values or Instructions that we can print/dump for debugging.
static LLVM_ABI Constant * getPtrToInt(Constant *C, Type *Ty)
static LLVM_ABI Constant * getIntToPtr(Constant *C, Type *Ty)
static LLVM_ABI Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
static LLVM_ABI Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
Maps the original instructions to the vectorized instrs and the reverse.
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
static LLVM_ABI IntegerType * get(Context &C, unsigned NumBits)
static LLVM_ABI LoadInst * create(Type *Ty, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx, const Twine &Name="")
bool runOnRegion(Region &Rgn, const Analyses &A) final
\Returns true if it modifies R.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
static LLVM_ABI StoreInst * create(Value *V, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx)
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
static unsigned getNumBits(Type *Ty, const DataLayout &DL)
\Returns the number of bits of Ty.
static Instruction * getLowest(ArrayRef< Instruction * > Instrs)
\Returns the instruction in Instrs that is lowest in the BB.
static Value * unpack(Value *FromVec, Type *ExtrTy, unsigned Lane, BasicBlock::iterator WhereIt)
Emits the necessary instruction sequence to extract element of type ExtrTy at Lane from FromVec.
static LLVM_DUMP_METHOD void dump(ArrayRef< Value * > Bndl)
Helper dump function for debugging.
static auto enumerateLanes(const ValueContainerT &Range)
Helper for creating LaneValueEnumerator ranges.
static bool areConsecutive(LoadOrStoreT *I1, LoadOrStoreT *I2, ScalarEvolution &SE, const DataLayout &DL)
\Returns true if I1 and I2 are load/stores accessing consecutive memory addresses.
static Type * getElementType(Type *Ty)
Returns Ty if scalar or its element type if vector.
static Align getVecAlignment(AlignRangeT AlignRange, TypeRangeT TypeRange)
Given the alignments of the instructions before vectorization, this returns the alignment of the vect...
static Type * getCombinedVectorTypeFor(BndlRef< T * > Bndl, const DataLayout &DL)
\Returns the combined vector type for Bndl, even when the element types differ.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
BndlRef(const T &OneElt) -> BndlRef< T >
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
DWARFExpression::Operation Op
const VectorizeOptions & getVectorizeOptions(const LLVMContext &C)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.