26#define DEBUG_PREFIX_LOCAL DEBUG_PREFIX "LoadStoreVec: "
39 const auto &LegalityRes = Legality->canVectorizeLSV(Bndl);
47void LoadStoreVec::saveIR(Region &R) {
50 CostBefore = SB.getAfterCost() - SB.getBeforeCost();
54bool LoadStoreVec::acceptOrRevert() {
59 <<
" (After=" << CostAfter <<
" Before=" << CostBefore
62 if (CostGain > Opts.sbvec_cost_threshold) {
73 if (!canVectorize(Loads))
96 if (!SrcTy->isIntegerTy()) {
99 : ConstantExpr::getBitCast(
C, IntTy);
101 if (DestTy->isIntegerTy())
104 : ConstantExpr::getBitCast(AsInt, DestTy);
110 auto *LaneTy = VecTy->getScalarType();
116 "Chain contains a constant which cannot be converted or split");
120 SmallVector<Constant *, 4> ConstantElements;
121 for (Constant *COp : Constants) {
126 for (
Value *Elm : AggrCOp->operands())
130 ConstantElements.push_back(SeqCOp->getElementAsConstant(ElmIdx));
132 auto *ZeroElm =
Zero->getSequentialElement();
133 for ([[maybe_unused]]
auto Cnt :
135 ConstantElements.push_back(ZeroElm);
138 for ([[maybe_unused]]
auto Cnt :
142 ConstantElements.push_back(Elm);
145 for ([[maybe_unused]]
auto Cnt :
149 ConstantElements.push_back(Elm);
153 for ([[maybe_unused]]
auto Cnt :
157 ConstantElements.push_back(Elm);
162 ConstantElements.push_back(COp);
173 LaneTyConstants.reserve(ConstantElements.size());
174 for (Constant *
C : ConstantElements) {
176 if (Bits == LaneBits) {
177 Constant *Lane = getEquivalentConstantWithType(
C, LaneTy);
180 LaneTyConstants.push_back(Lane);
181 }
else if (Bits > LaneBits) {
190 Val = CI->getValue();
192 Val = CFP->getValue().bitcastToAPInt();
195 unsigned NumSlices =
Bits / LaneBits;
197 unsigned EndianAwareSlice =
198 DL->isLittleEndian() ? SliceIdx : NumSlices - 1 - SliceIdx;
202 *Ctx, Val.extractBits(LaneBits, EndianAwareSlice * LaneBits));
203 Constant *SliceC = getEquivalentConstantWithType(SliceCInt, LaneTy);
204 if (SliceC ==
nullptr)
206 LaneTyConstants.push_back(SliceC);
216 if (!canVectorize(Stores))
220 for (
auto *
I : Stores) {
233 if (LI->getParent() != BB)
235 if (LI->hasNUsesOrMore(2))
241 if (!AllLoads && !AllConstants)
247 Value *VecOp =
nullptr;
248 SmallVector<Instruction *, 8> Loads;
253 VecOp = createVectorLoad(Loads);
254 if (VecOp ==
nullptr) {
258 }
else if (AllConstants) {
263 VecOp = createConstantVector(Constants);
264 if (VecOp ==
nullptr) {
277 DeadInstrMorgue.collectPotentiallyDeadInstrs(Stores);
279 DeadInstrMorgue.collectPotentiallyDeadInstrs<
Instruction>(Loads);
280 DeadInstrMorgue.tryEraseDeadInstrs();
282 return acceptOrRevert();
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 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...
A parsed version of the target data layout string in and methods for querying it.
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)
void save()
Convenience function for getTracker().save()
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.
Context & getContext() const
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 ...
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVM_ABI Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isPointerTy() const
True if this is an instance of PointerType.
static void propagateMetadata(Instruction *I, const ValueRangeT &VL)
static unsigned getNumBits(Type *Ty, const DataLayout &DL)
\Returns the number of bits of Ty.
LLVM_ABI Type * getType() const
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 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.
static bool isNonIntegralPtr(Type *Ty, const DataLayout &DL)
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.