28#define DEBUG_PREFIX_LOCAL DEBUG_PREFIX "LoadStoreVec: "
41 const auto &LegalityRes = Legality->canVectorizeLSV(Bndl);
49void LoadStoreVec::saveIR(Region &R) {
52 CostBefore = SB.getAfterCost() - SB.getBeforeCost();
56bool LoadStoreVec::acceptOrRevert() {
61 <<
" (After=" << CostAfter <<
" Before=" << CostBefore
64 if (CostGain > Opts.sbvec_cost_threshold) {
75 if (!canVectorize(Loads))
98 if (!SrcTy->isIntegerTy()) {
101 : ConstantExpr::getBitCast(
C, IntTy);
103 if (DestTy->isIntegerTy())
106 : ConstantExpr::getBitCast(AsInt, DestTy);
112 auto *LaneTy = VecTy->getScalarType();
118 "Chain contains a constant which cannot be converted or split");
122 SmallVector<Constant *, 4> ConstantElements;
123 for (Constant *COp : Constants) {
128 for (
Value *Elm : AggrCOp->operands())
132 ConstantElements.push_back(SeqCOp->getElementAsConstant(ElmIdx));
134 auto *ZeroElm =
Zero->getSequentialElement();
135 for ([[maybe_unused]]
auto Cnt :
137 ConstantElements.push_back(ZeroElm);
140 for ([[maybe_unused]]
auto Cnt :
144 ConstantElements.push_back(Elm);
147 for ([[maybe_unused]]
auto Cnt :
151 ConstantElements.push_back(Elm);
155 for ([[maybe_unused]]
auto Cnt :
159 ConstantElements.push_back(Elm);
164 ConstantElements.push_back(COp);
175 LaneTyConstants.reserve(ConstantElements.size());
176 for (Constant *
C : ConstantElements) {
178 if (Bits == LaneBits) {
179 Constant *Lane = getEquivalentConstantWithType(
C, LaneTy);
182 LaneTyConstants.push_back(Lane);
183 }
else if (Bits > LaneBits) {
192 Val = CI->getValue();
194 Val = CFP->getValue().bitcastToAPInt();
197 unsigned NumSlices =
Bits / LaneBits;
199 unsigned EndianAwareSlice =
200 DL->isLittleEndian() ? SliceIdx : NumSlices - 1 - SliceIdx;
204 *Ctx, Val.extractBits(LaneBits, EndianAwareSlice * LaneBits));
205 Constant *SliceC = getEquivalentConstantWithType(SliceCInt, LaneTy);
206 if (SliceC ==
nullptr)
208 LaneTyConstants.push_back(SliceC);
218 if (!canVectorize(Stores))
222 for (
auto *
I : Stores) {
235 if (LI->getParent() != BB)
237 if (LI->hasNUsesOrMore(2))
243 if (!AllLoads && !AllConstants)
249 Value *VecOp =
nullptr;
250 SmallVector<Instruction *, 8> Loads;
255 VecOp = createVectorLoad(Loads);
256 if (VecOp ==
nullptr) {
260 }
else if (AllConstants) {
265 VecOp = createConstantVector(Constants);
266 if (VecOp ==
nullptr) {
279 DeadInstrMorgue.collectPotentiallyDeadInstrs(Stores);
281 DeadInstrMorgue.collectPotentiallyDeadInstrs<
Instruction>(Loads);
282 DeadInstrMorgue.tryEraseDeadInstrs();
284 return acceptOrRevert();
289 auto VecTy = canVectorize(Loads);
302 auto *
VecLoad = createVectorLoad(Loads);
303 if (VecLoad ==
nullptr) {
311 if (OrigLoad->hasNUses(0))
315 OrigLoad->replaceAllUsesWith(Unpacked);
318 DeadInstrMorgue.collectPotentiallyDeadInstrs(Loads);
319 DeadInstrMorgue.tryEraseDeadInstrs();
321 if (!acceptOrRevert())
330 Function &
F = *Bndl[0]->getParent()->getParent();
331 DL = &
F.getParent()->getDataLayout();
332 Ctx = &
F.getContext();
335 Legality = std::make_unique<LegalityAnalysis>(
336 A->getAA(), A->getScalarEvolution(),
F.getParent()->getDataLayout(),
339 auto Opc = Bndl[0]->getOpcode();
342 "Expected a homogeneous seed slice!");
346 case Instruction::Opcode::Load:
347 Changed = vectorizeLoads(Bndl, Rgn) !=
nullptr;
349 case Instruction::Opcode::Store:
350 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...
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.