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) {
93 if (!SrcTy->isIntegerTy()) {
96 : ConstantExpr::getBitCast(
C, IntTy);
98 if (DestTy->isIntegerTy())
101 : ConstantExpr::getBitCast(AsInt, DestTy);
107 auto *LaneTy = VecTy->getScalarType();
113 "Chain contains a constant which cannot be converted or split");
117 SmallVector<Constant *, 4> ConstantElements;
118 for (Constant *COp : Constants) {
123 for (
Value *Elm : AggrCOp->operands())
127 ConstantElements.push_back(SeqCOp->getElementAsConstant(ElmIdx));
129 auto *ZeroElm =
Zero->getSequentialElement();
130 for ([[maybe_unused]]
auto Cnt :
132 ConstantElements.push_back(ZeroElm);
135 for ([[maybe_unused]]
auto Cnt :
139 ConstantElements.push_back(Elm);
142 for ([[maybe_unused]]
auto Cnt :
146 ConstantElements.push_back(Elm);
150 for ([[maybe_unused]]
auto Cnt :
154 ConstantElements.push_back(Elm);
159 ConstantElements.push_back(COp);
170 LaneTyConstants.reserve(ConstantElements.size());
171 for (Constant *
C : ConstantElements) {
173 if (Bits == LaneBits) {
174 Constant *Lane = getEquivalentConstantWithType(
C, LaneTy);
177 LaneTyConstants.push_back(Lane);
178 }
else if (Bits > LaneBits) {
187 Val = CI->getValue();
189 Val = CFP->getValue().bitcastToAPInt();
192 unsigned NumSlices =
Bits / LaneBits;
194 unsigned EndianAwareSlice =
195 DL->isLittleEndian() ? SliceIdx : NumSlices - 1 - SliceIdx;
199 *Ctx, Val.extractBits(LaneBits, EndianAwareSlice * LaneBits));
200 Constant *SliceC = getEquivalentConstantWithType(SliceCInt, LaneTy);
201 if (SliceC ==
nullptr)
203 LaneTyConstants.push_back(SliceC);
213 if (!canVectorize(Stores))
217 for (
auto *
I : Stores) {
230 if (LI->getParent() != BB)
232 if (LI->hasNUsesOrMore(2))
238 if (!AllLoads && !AllConstants)
244 Value *VecOp =
nullptr;
245 SmallVector<Instruction *, 8> Loads;
250 if (!canVectorize(Loads)) {
254 VecOp = createVectorLoad(Loads);
255 assert(VecOp !=
nullptr &&
"Expected vector value!");
256 }
else if (AllConstants) {
261 VecOp = createConstantVector(Constants);
262 if (VecOp ==
nullptr) {
275 DeadInstrMorgue.collectPotentiallyDeadInstrs(Stores);
277 DeadInstrMorgue.collectPotentiallyDeadInstrs<
Instruction>(Loads);
278 DeadInstrMorgue.tryEraseDeadInstrs();
280 return acceptOrRevert();
285 auto VecTy = canVectorize(Loads);
298 auto *
VecLoad = createVectorLoad(Loads);
299 assert(VecLoad !=
nullptr &&
"Expected vector load");
304 if (OrigLoad->hasNUses(0))
308 OrigLoad->replaceAllUsesWith(Unpacked);
311 DeadInstrMorgue.collectPotentiallyDeadInstrs(Loads);
312 DeadInstrMorgue.tryEraseDeadInstrs();
314 if (!acceptOrRevert())
323 Function &
F = *Bndl[0]->getParent()->getParent();
324 DL = &
F.getParent()->getDataLayout();
325 Ctx = &
F.getContext();
328 Legality = std::make_unique<LegalityAnalysis>(
329 A->getAA(), A->getScalarEvolution(),
F.getParent()->getDataLayout(),
332 auto Opc = Bndl[0]->getOpcode();
335 "Expected a homogeneous seed slice!");
339 case Instruction::Opcode::Load:
340 Changed = vectorizeLoads(Bndl, Rgn) !=
nullptr;
342 case Instruction::Opcode::Store:
343 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.