32std::optional<ResultReason>
33LegalityAnalysis::notVectorizableBasedOnOpcodesAndTypes(
35 auto *I0 = cast<Instruction>(Bndl[0]);
36 auto Opcode = I0->getOpcode();
39 return cast<Instruction>(V)->getOpcode() != Opcode;
54 if (isa<FPMathOperator>(I0)) {
55 FastMathFlags FMF0 = cast<Instruction>(Bndl[0])->getFastMathFlags();
57 return cast<Instruction>(V)->getFastMathFlags() != FMF0;
64 bool CanHaveWrapFlags =
65 isa<OverflowingBinaryOperator>(I0) || isa<TruncInst>(I0);
66 if (CanHaveWrapFlags) {
67 bool NUW0 = I0->hasNoUnsignedWrap();
68 bool NSW0 = I0->hasNoSignedWrap();
70 return cast<Instruction>(V)->hasNoUnsignedWrap() != NUW0 ||
71 cast<Instruction>(V)->hasNoSignedWrap() != NSW0;
79 case Instruction::Opcode::ZExt:
80 case Instruction::Opcode::SExt:
81 case Instruction::Opcode::FPToUI:
82 case Instruction::Opcode::FPToSI:
83 case Instruction::Opcode::FPExt:
84 case Instruction::Opcode::PtrToAddr:
85 case Instruction::Opcode::PtrToInt:
86 case Instruction::Opcode::IntToPtr:
87 case Instruction::Opcode::SIToFP:
88 case Instruction::Opcode::UIToFP:
89 case Instruction::Opcode::Trunc:
90 case Instruction::Opcode::FPTrunc:
91 case Instruction::Opcode::BitCast: {
95 return cast<Instruction>(V)->getOpcode() == Opcode;
97 "Different opcodes, should have early returned!");
107 case Instruction::Opcode::FCmp:
108 case Instruction::Opcode::ICmp: {
110 auto Pred0 = cast<CmpInst>(I0)->getPredicate();
112 return cast<CmpInst>(V)->getPredicate() == Pred0;
118 case Instruction::Opcode::Select: {
119 auto *Sel0 = cast<SelectInst>(Bndl[0]);
120 auto *Cond0 = Sel0->getCondition();
127 case Instruction::Opcode::FNeg:
128 case Instruction::Opcode::Add:
129 case Instruction::Opcode::FAdd:
130 case Instruction::Opcode::Sub:
131 case Instruction::Opcode::FSub:
132 case Instruction::Opcode::Mul:
133 case Instruction::Opcode::FMul:
134 case Instruction::Opcode::FRem:
135 case Instruction::Opcode::UDiv:
136 case Instruction::Opcode::SDiv:
137 case Instruction::Opcode::FDiv:
138 case Instruction::Opcode::URem:
139 case Instruction::Opcode::SRem:
140 case Instruction::Opcode::Shl:
141 case Instruction::Opcode::LShr:
142 case Instruction::Opcode::AShr:
143 case Instruction::Opcode::And:
144 case Instruction::Opcode::Or:
145 case Instruction::Opcode::Xor:
147 case Instruction::Opcode::Load:
148 if (VecUtils::areConsecutive<LoadInst>(Bndl, SE, DL))
151 case Instruction::Opcode::Store:
152 if (VecUtils::areConsecutive<StoreInst>(Bndl, SE, DL))
155 case Instruction::Opcode::PHI:
157 case Instruction::Opcode::Opaque:
159 case Instruction::Opcode::Br:
160 case Instruction::Opcode::Ret:
161 case Instruction::Opcode::AddrSpaceCast:
162 case Instruction::Opcode::InsertElement:
163 case Instruction::Opcode::InsertValue:
164 case Instruction::Opcode::ExtractElement:
165 case Instruction::Opcode::ExtractValue:
166 case Instruction::Opcode::ShuffleVector:
167 case Instruction::Opcode::Call:
168 case Instruction::Opcode::GetElementPtr:
169 case Instruction::Opcode::Switch:
171 case Instruction::Opcode::VAArg:
172 case Instruction::Opcode::Freeze:
173 case Instruction::Opcode::Fence:
174 case Instruction::Opcode::Invoke:
175 case Instruction::Opcode::CallBr:
176 case Instruction::Opcode::LandingPad:
177 case Instruction::Opcode::CatchPad:
178 case Instruction::Opcode::CleanupPad:
179 case Instruction::Opcode::CatchRet:
180 case Instruction::Opcode::CleanupRet:
181 case Instruction::Opcode::Resume:
182 case Instruction::Opcode::CatchSwitch:
183 case Instruction::Opcode::AtomicRMW:
184 case Instruction::Opcode::AtomicCmpXchg:
185 case Instruction::Opcode::Alloca:
186 case Instruction::Opcode::Unreachable:
194LegalityAnalysis::getHowToCollectValues(ArrayRef<Value *> Bndl)
const {
195 SmallVector<CollectDescr::ExtractElementDescr, 4> Vec;
196 Vec.reserve(Bndl.size());
200 std::optional<int> ExtractIdxOpt = IMaps.
getOrigLane(VecOp, V);
204 Vec.emplace_back(VecOp, ExtractIdxOpt ? *ExtractIdxOpt + Ln : -1);
209 return CollectDescr(std::move(Vec));
213 bool SkipScheduling) {
215 if (
any_of(Bndl, [](
auto *V) {
return !isa<Instruction>(V); }))
218 auto *BB = cast<Instruction>(Bndl[0])->getParent();
220 [BB](
auto *V) {
return cast<Instruction>(V)->getParent() != BB; }))
227 auto CollectDescrs = getHowToCollectValues(Bndl);
228 if (CollectDescrs.hasVectorInputs()) {
229 if (
auto ValueShuffleOpt = CollectDescrs.getSingleInput()) {
230 auto [Vec, Mask] = *ValueShuffleOpt;
231 if (Mask.isIdentity())
232 return createLegalityResult<DiamondReuse>(Vec);
233 return createLegalityResult<DiamondReuseWithShuffle>(Vec, Mask);
235 return createLegalityResult<DiamondReuseMultiInput>(
236 std::move(CollectDescrs));
239 if (
auto ReasonOpt = notVectorizableBasedOnOpcodesAndTypes(Bndl))
240 return createLegalityResult<Pack>(*ReasonOpt);
242 if (!SkipScheduling) {
252 return createLegalityResult<Widen>();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
std::optional< unsigned > getOrigLane(Action *Vec, Value *Orig) const
\Returns the lane of Orig before it got vectorized into Vec, or nullopt if not found.
Action * getVectorForOrig(Value *Orig) const
\Returns the vector value that we got from vectorizing Orig, or nullptr if not found.
LLVM_ABI const LegalityResult & canVectorize(ArrayRef< Value * > Bndl, bool SkipScheduling=false)
Checks if it's legal to vectorize the instructions in Bndl.
The legality outcome is represented by a class rather than an enum class because in some cases the le...
LLVM_DUMP_METHOD void dump() const
virtual void print(raw_ostream &OS) const
LLVM_ABI bool trySchedule(ArrayRef< Instruction * > Instrs)
Tries to build a schedule that includes all of Instrs scheduled at the same scheduling cycle.
void clear()
Clear the scheduler's state, including the DAG.
void print(raw_ostream &OS) const
LLVM_DUMP_METHOD void dump() const
static Type * getExpectedType(const Value *V)
\Returns the expected type of Value V.
A SandboxIR Value has users. This is the base class.
static unsigned getNumLanes(Type *Ty)
\Returns the number of vector lanes of Ty or 1 if not a vector.
static Type * getElementType(Type *Ty)
Returns Ty if scalar or its element type if vector.
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
static SmallVector< Value *, 4 > getOperand(ArrayRef< Value * > Bndl, unsigned OpIdx)
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
constexpr from_range_t from_range
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.