LLVM 24.0.0git
SLPCompatibilityAnalysis.cpp
Go to the documentation of this file.
1//===- SLPCompatibilityAnalysis.cpp - SLP same-opcode helpers -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "SLPUtils.h"
11
12#include "llvm/ADT/APInt.h"
13#include "llvm/ADT/ArrayRef.h"
14#include "llvm/ADT/STLExtras.h"
15#include "llvm/ADT/SetVector.h"
19#include "llvm/ADT/bit.h"
23#include "llvm/IR/CFG.h"
24#include "llvm/IR/Constants.h"
26#include "llvm/IR/Dominators.h"
27#include "llvm/IR/InstrTypes.h"
28#include "llvm/IR/Instruction.h"
31#include "llvm/IR/Intrinsics.h"
33#include "llvm/IR/Value.h"
36
37#include <algorithm>
38#include <array>
39#include <cassert>
40#include <optional>
41#include <utility>
42
43using namespace llvm;
44using namespace llvm::PatternMatch;
45
46namespace llvm::slpvectorizer {
47
48bool isValidForAlternation(unsigned Opcode) {
49 return !Instruction::isIntDivRem(Opcode);
50}
51
52std::pair<Constant *, unsigned>
53BinOpSameOpcodeHelper::isBinOpWithConstant(const Instruction *I) {
54 [[maybe_unused]] unsigned Opcode = I->getOpcode();
55 assert(binary_search(SupportedOp, Opcode) && "Unsupported opcode.");
56 (void)SupportedOp;
57 auto *BinOp = cast<BinaryOperator>(I);
58 auto GetConstant = [](Value *V) -> Constant * {
59 if (auto *CI = dyn_cast<ConstantInt>(V))
60 return CI;
61 return dyn_cast<ConstantFP>(V);
62 };
63 if (Constant *C = GetConstant(BinOp->getOperand(1)))
64 return {C, 1};
65 if (!isCommutative(I))
66 return {nullptr, 0};
67 if (Constant *C = GetConstant(BinOp->getOperand(0)))
68 return {C, 0};
69 return {nullptr, 0};
70}
71
72bool BinOpSameOpcodeHelper::InterchangeableInfo::trySet(
73 MaskType OpcodeInMaskForm, MaskType InterchangeableMask) {
74 if (Mask & InterchangeableMask) {
75 SeenBefore |= OpcodeInMaskForm;
76 Mask &= InterchangeableMask;
77 return true;
78 }
79 return false;
80}
81
82unsigned BinOpSameOpcodeHelper::InterchangeableInfo::getOpcode() const {
83 MaskType Candidate = Mask & SeenBefore;
84 if (Candidate & MainOpBIT)
85 return I->getOpcode();
86 if (Candidate & ShlBIT)
87 return Instruction::Shl;
88 if (Candidate & AShrBIT)
89 return Instruction::AShr;
90 if (Candidate & MulBIT)
91 return Instruction::Mul;
92 if (Candidate & AddBIT)
93 return Instruction::Add;
94 if (Candidate & SubBIT)
95 return Instruction::Sub;
96 if (Candidate & FAddBIT)
97 return Instruction::FAdd;
98 if (Candidate & FSubBIT)
99 return Instruction::FSub;
100 if (Candidate & AndBIT)
101 return Instruction::And;
102 if (Candidate & OrBIT)
103 return Instruction::Or;
104 if (Candidate & XorBIT)
105 return Instruction::Xor;
106 llvm_unreachable("Cannot find interchangeable instruction.");
107}
108
109bool BinOpSameOpcodeHelper::InterchangeableInfo::hasCandidateOpcode(
110 unsigned Opcode) const {
111 MaskType Candidate = Mask & SeenBefore;
112 switch (Opcode) {
113 case Instruction::Shl:
114 return Candidate & ShlBIT;
115 case Instruction::AShr:
116 return Candidate & AShrBIT;
117 case Instruction::Mul:
118 return Candidate & MulBIT;
119 case Instruction::Add:
120 return Candidate & AddBIT;
121 case Instruction::Sub:
122 return Candidate & SubBIT;
123 case Instruction::And:
124 return Candidate & AndBIT;
125 case Instruction::Or:
126 return Candidate & OrBIT;
127 case Instruction::Xor:
128 return Candidate & XorBIT;
129 case Instruction::FAdd:
130 return Candidate & FAddBIT;
131 case Instruction::FSub:
132 return Candidate & FSubBIT;
133 case Instruction::LShr:
134 case Instruction::FMul:
135 case Instruction::SDiv:
136 case Instruction::UDiv:
137 case Instruction::FDiv:
138 case Instruction::SRem:
139 case Instruction::URem:
140 case Instruction::FRem:
141 return false;
142 default:
143 break;
144 }
145 llvm_unreachable("Cannot find interchangeable instruction.");
146}
147
148SmallVector<Value *> BinOpSameOpcodeHelper::InterchangeableInfo::getOperand(
149 const Instruction *To) const {
150 unsigned ToOpcode = To->getOpcode();
151 unsigned FromOpcode = I->getOpcode();
152 if (FromOpcode == ToOpcode)
153 return SmallVector<Value *>(I->operands());
154 assert(binary_search(SupportedOp, ToOpcode) && "Unsupported opcode.");
155 auto [C, Pos] = isBinOpWithConstant(I);
156 Type *RHSType = I->getOperand(Pos)->getType();
157 Constant *RHS;
158 if (auto *CFP = dyn_cast<ConstantFP>(C)) {
159 // fsub(x, c) == fadd(x, -c) for every FP constant c, since IEEE 754
160 // defines subtraction as addition of the negated operand.
161 assert(is_contained({Instruction::FAdd, Instruction::FSub}, ToOpcode) &&
162 "Cannot convert the instruction.");
163 RHS = ConstantFP::get(RHSType, -CFP->getValueAPF());
164 } else {
165 auto *CI = cast<ConstantInt>(C);
166 const APInt &FromCIValue = CI->getValue();
167 unsigned FromCIValueBitWidth = FromCIValue.getBitWidth();
168 switch (FromOpcode) {
169 case Instruction::Shl:
170 if (ToOpcode == Instruction::Add && FromCIValue.isOne())
171 return {I->getOperand(0), I->getOperand(0)};
172 if (ToOpcode == Instruction::Mul) {
173 RHS = ConstantInt::get(RHSType,
174 APInt::getOneBitSet(FromCIValueBitWidth,
175 FromCIValue.getZExtValue()));
176 } else {
177 assert(FromCIValue.isZero() && "Cannot convert the instruction.");
178 RHS = ConstantExpr::getBinOpIdentity(ToOpcode, RHSType,
179 /*AllowRHSConstant=*/true);
180 }
181 break;
182 case Instruction::Mul:
183 assert(FromCIValue.isPowerOf2() && "Cannot convert the instruction.");
184 if (ToOpcode == Instruction::Shl) {
185 RHS = ConstantInt::get(
186 RHSType, APInt(FromCIValueBitWidth, FromCIValue.logBase2()));
187 } else {
188 assert(FromCIValue.isOne() && "Cannot convert the instruction.");
189 RHS = ConstantExpr::getBinOpIdentity(ToOpcode, RHSType,
190 /*AllowRHSConstant=*/true);
191 }
192 break;
193 case Instruction::Add:
194 case Instruction::Sub:
195 if (FromCIValue.isZero()) {
196 RHS = ConstantExpr::getBinOpIdentity(ToOpcode, RHSType,
197 /*AllowRHSConstant=*/true);
198 } else {
199 assert(is_contained({Instruction::Add, Instruction::Sub}, ToOpcode) &&
200 "Cannot convert the instruction.");
201 APInt NegatedVal = APInt(FromCIValue);
202 NegatedVal.negate();
203 RHS = ConstantInt::get(RHSType, NegatedVal);
204 }
205 break;
206 case Instruction::And:
207 assert(FromCIValue.isAllOnes() && "Cannot convert the instruction.");
208 RHS = ConstantExpr::getBinOpIdentity(ToOpcode, RHSType,
209 /*AllowRHSConstant=*/true);
210 break;
211 default:
212 assert(FromCIValue.isZero() && "Cannot convert the instruction.");
213 RHS = ConstantExpr::getBinOpIdentity(ToOpcode, RHSType,
214 /*AllowRHSConstant=*/true);
215 break;
216 }
217 }
218 Value *LHS = I->getOperand(1 - Pos);
219 // If the target opcode is non-commutative (e.g., shl, sub),
220 // force the variable to the left and the constant to the right.
221 if (Pos == 1 || !Instruction::isCommutative(ToOpcode))
222 return SmallVector<Value *>({LHS, RHS});
223
224 return SmallVector<Value *>({RHS, LHS});
225}
226
227bool BinOpSameOpcodeHelper::isValidForAlternation(const Instruction *I) const {
228 return slpvectorizer::isValidForAlternation(MainOp.I->getOpcode()) &&
230}
231
232bool BinOpSameOpcodeHelper::initializeAltOp(const Instruction *I) {
233 if (AltOp.I)
234 return true;
235 if (!isValidForAlternation(I))
236 return false;
237 AltOp.I = I;
238 return true;
239}
240
243 "BinOpSameOpcodeHelper only accepts BinaryOperator.");
244 unsigned Opcode = I->getOpcode();
245 MaskType OpcodeInMaskForm;
246 // Prefer Shl, AShr, Mul, Add, Sub, And, Or, Xor, FAdd and FSub over
247 // MainOp.
248 switch (Opcode) {
249 case Instruction::Shl:
250 OpcodeInMaskForm = ShlBIT;
251 break;
252 case Instruction::AShr:
253 OpcodeInMaskForm = AShrBIT;
254 break;
255 case Instruction::Mul:
256 OpcodeInMaskForm = MulBIT;
257 break;
258 case Instruction::Add:
259 OpcodeInMaskForm = AddBIT;
260 break;
261 case Instruction::Sub:
262 OpcodeInMaskForm = SubBIT;
263 break;
264 case Instruction::And:
265 OpcodeInMaskForm = AndBIT;
266 break;
267 case Instruction::Or:
268 OpcodeInMaskForm = OrBIT;
269 break;
270 case Instruction::Xor:
271 OpcodeInMaskForm = XorBIT;
272 break;
273 case Instruction::FAdd:
274 OpcodeInMaskForm = FAddBIT;
275 break;
276 case Instruction::FSub:
277 OpcodeInMaskForm = FSubBIT;
278 break;
279 default:
280 return MainOp.equal(Opcode) || (initializeAltOp(I) && AltOp.equal(Opcode));
281 }
282 MaskType InterchangeableMask = OpcodeInMaskForm;
283 auto [C, Pos] = isBinOpWithConstant(I);
284 if (auto *CI = dyn_cast_if_present<ConstantInt>(C)) {
285 constexpr MaskType CanBeAll =
286 XorBIT | OrBIT | AndBIT | SubBIT | AddBIT | MulBIT | AShrBIT | ShlBIT;
287 const APInt &CIValue = CI->getValue();
288 switch (Opcode) {
289 case Instruction::Shl:
290 if (CIValue.ult(CIValue.getBitWidth()))
291 InterchangeableMask = CIValue.isZero() ? CanBeAll : MulBIT | ShlBIT;
292 if (CIValue.isOne())
293 InterchangeableMask |= AddBIT;
294 break;
295 case Instruction::Mul:
296 if (CIValue.isOne()) {
297 InterchangeableMask = CanBeAll;
298 break;
299 }
300 if (CIValue.isPowerOf2())
301 InterchangeableMask = MulBIT | ShlBIT;
302 break;
303 case Instruction::Add:
304 case Instruction::Sub:
305 InterchangeableMask = CIValue.isZero() ? CanBeAll : SubBIT | AddBIT;
306 break;
307 case Instruction::And:
308 if (CIValue.isAllOnes())
309 InterchangeableMask = CanBeAll;
310 break;
311 case Instruction::Xor:
312 if (CIValue.isZero())
313 InterchangeableMask = XorBIT | OrBIT | SubBIT | AddBIT;
314 break;
315 default:
316 if (CIValue.isZero())
317 InterchangeableMask = CanBeAll;
318 break;
319 }
320 } else if (C && Pos == 1) {
321 // FAdd/FSub with a constant RHS: negating the constant always
322 // converts one into the other, so no value check is needed. A
323 // constant LHS (Pos == 0, e.g. "0.0 - x") is excluded: unlike a
324 // constant RHS, it cannot be moved to the other opcode without also
325 // swapping the variable operand, which would misalign it against
326 // lanes that keep their native opcode (their variable operand stays
327 // on the other side).
328 InterchangeableMask = FSubBIT | FAddBIT;
329 }
330 return MainOp.trySet(OpcodeInMaskForm, InterchangeableMask) ||
331 (initializeAltOp(I) &&
332 AltOp.trySet(OpcodeInMaskForm, InterchangeableMask));
333}
334
335/// If the comparison (Pred, X, C) is a single-element or single-complement
336/// range check, returns its boundary family: false + K for the singleton
337/// {K} (eq forms), true + K for the complement of {K} (ne forms).
338static std::optional<std::pair<bool, APInt>>
340 const unsigned BW = C.getBitWidth();
341 const bool IsSigned = CmpInst::isSigned(Pred);
342 const APInt Min = IsSigned ? APInt::getSignedMinValue(BW) : APInt(BW, 0);
343 const APInt Max =
344 IsSigned ? APInt::getSignedMaxValue(BW) : APInt::getMaxValue(BW);
345 switch (Pred) {
346 case CmpInst::ICMP_EQ:
347 return std::make_pair(false, C);
348 case CmpInst::ICMP_NE:
349 return std::make_pair(true, C);
352 if (C == Min + 1)
353 return std::make_pair(false, Min);
354 if (C == Max)
355 return std::make_pair(true, C);
356 break;
359 if (C == Min)
360 return std::make_pair(false, C);
361 if (C == Max - 1)
362 return std::make_pair(true, Max);
363 break;
366 if (C == Min)
367 return std::make_pair(true, C);
368 if (C == Max - 1)
369 return std::make_pair(false, Max);
370 break;
373 if (C == Min + 1)
374 return std::make_pair(true, Min);
375 if (C == Max)
376 return std::make_pair(false, C);
377 break;
378 default:
379 break;
380 }
381 return std::nullopt;
382}
383
384CmpSamePredicateHelper::MaskType
385CmpSamePredicateHelper::getFormsMask(CmpInst::Predicate Pred, const APInt &C) {
386 MaskType M = getBit(Pred);
387 std::optional<std::pair<bool, APInt>> Family = getCmpBoundaryFamily(Pred, C);
388 if (!Family)
389 return M;
390 const auto &[IsComplement, K] = *Family;
391 // At each type boundary the two range checks covering exactly {K}; the
392 // complement family uses their inverses, covering everything but {K}.
393 const MaskType LoU = getBit(CmpInst::ICMP_ULT) | getBit(CmpInst::ICMP_ULE);
394 const MaskType HiU = getBit(CmpInst::ICMP_UGT) | getBit(CmpInst::ICMP_UGE);
395 const MaskType LoS = getBit(CmpInst::ICMP_SLT) | getBit(CmpInst::ICMP_SLE);
396 const MaskType HiS = getBit(CmpInst::ICMP_SGT) | getBit(CmpInst::ICMP_SGE);
397 if (K.isZero())
398 M |= IsComplement ? HiU : LoU;
399 if (K.isMaxValue())
400 M |= IsComplement ? LoU : HiU;
401 if (K.isMinSignedValue())
402 M |= IsComplement ? HiS : LoS;
403 if (K.isMaxSignedValue())
404 M |= IsComplement ? LoS : HiS;
405 return M | getBit(IsComplement ? CmpInst::ICMP_NE : CmpInst::ICMP_EQ);
406}
407
408APInt CmpSamePredicateHelper::getFamilyConstant(bool IsComplement,
409 const APInt &K,
412 return K;
413 // The complement form uses the singleton constant of the inverse
414 // predicate.
415 if (IsComplement)
417 switch (Pred) {
420 return K + 1;
423 return K - 1;
424 default:
425 return K;
426 }
427}
428
429/// Returns the predicate and the compared constant of the comparison lane
430/// \p I, treating trunc X to i1 as and X, 1 ne 0.
431static std::optional<std::pair<CmpInst::Predicate, APInt>>
433 if (auto *TI = dyn_cast<TruncInst>(I);
434 TI && TI->getType()->isIntOrIntVectorTy(1))
435 return std::make_pair(
437 APInt::getZero(TI->getSrcTy()->getScalarSizeInBits()));
438 const APInt *C;
439 if (auto *CI = dyn_cast<ICmpInst>(I);
440 CI && match(CI->getOperand(1), m_APInt(C)))
441 return std::make_pair(CI->getPredicate(), *C);
442 return std::nullopt;
443}
444
445CmpSamePredicateHelper::MaskType
446CmpSamePredicateHelper::getLaneMask(const Value *V) {
448 V->getType()->isIntegerTy(1))
449 return AllPreds;
450 auto *I = dyn_cast<Instruction>(V);
451 if (!I)
452 return 0;
453 if (std::optional<std::pair<CmpInst::Predicate, APInt>> Cmp =
455 MaskType M = getFormsMask(Cmp->first, Cmp->second);
456 // trunc X to i1 is also and X, 1 eq 1.
457 return isa<TruncInst>(I) ? M | getBit(CmpInst::ICMP_EQ) : M;
458 }
459 if (auto *CI = dyn_cast<ICmpInst>(I))
460 return getBit(CI->getPredicate());
461 return 0;
462}
463
465 if (auto *CI = dyn_cast<ICmpInst>(I);
466 CI && !match(CI->getOperand(0), m_OneUse(m_And(m_Value(), m_Value()))))
467 return false;
468 std::optional<std::pair<CmpInst::Predicate, APInt>> Cmp =
470 if (!Cmp)
471 return false;
472 std::optional<std::pair<bool, APInt>> Family =
473 getCmpBoundaryFamily(Cmp->first, Cmp->second);
474 return Family && Family->second.isZero();
475}
476
478 if (auto *CI = dyn_cast<ICmpInst>(V))
479 SeenBefore |= getBit(CI->getPredicate());
480 Mask &= getLaneMask(V);
481 return Mask != 0;
482}
483
486 MaskType Candidate = Mask & SeenBefore;
487 if (!Candidate)
489 if (Candidate & getBit(Preferred->getPredicate()))
490 return Preferred->getPredicate();
491 return static_cast<CmpInst::Predicate>(CmpInst::ICMP_EQ +
492 countr_zero(Candidate));
493}
494
497 const ICmpInst *Preferred) {
499 if (!all_of(VL,
500 [&](Value *V) { return isa<PoisonValue>(V) || Helper.add(V); }))
502 return Helper.getPredicate(Preferred);
503}
504
506 CmpInst::Predicate Pred) {
507 return CmpInst::isIntPredicate(Pred) && (getLaneMask(V) & getBit(Pred)) != 0;
508}
509
511 CmpInst::Predicate Pred) {
512 if (!canConvertTo(I, Pred))
513 return nullptr;
514 if (auto *CI = dyn_cast<ICmpInst>(I); CI && CI->getPredicate() == Pred)
515 return nullptr;
516 if (isa<TruncInst>(I) && Pred == CmpInst::ICMP_EQ)
517 return ConstantInt::get(I->getOperand(0)->getType(), 1);
518 auto [LanePred, C] = *getLaneConstantCmp(I);
519 std::optional<std::pair<bool, APInt>> Family =
520 getCmpBoundaryFamily(LanePred, C);
521 assert(Family && "Expected a boundary family for a convertible compare.");
522 const auto &[IsComplement, K] = *Family;
523 return ConstantInt::get(I->getOperand(0)->getType(),
524 getFamilyConstant(IsComplement, K, Pred));
525}
526
529 const ICmpInst *Cmp) {
530 const CmpInst::Predicate Pred = Cmp->getPredicate();
531 assert(isa<Constant>(V) && canConvertTo(V, Pred) &&
532 "Expected an i1 constant lane.");
533 Type *Ty = Cmp->getOperand(0)->getType();
534 const unsigned BW = Ty->getIntegerBitWidth();
535 // Any comparison of constants refines the undef lane.
536 auto *CI = dyn_cast<ConstantInt>(V);
537 for (auto [LHS, RHS] :
538 {std::make_pair(0, 0), std::make_pair(0, 1), std::make_pair(1, 0)})
539 if (!CI ||
540 ICmpInst::compare(APInt(BW, LHS), APInt(BW, RHS), Pred) == CI->isOne())
541 return {ConstantInt::get(Ty, LHS), ConstantInt::get(Ty, RHS)};
542 llvm_unreachable("Expected the comparison of constants for the lane.");
543}
544
549
551 const Instruction *Op) {
552 if (I->getOpcode() != Op->getOpcode())
553 return false;
554 const auto *II = dyn_cast<IntrinsicInst>(I);
555 const auto *IOp = dyn_cast<IntrinsicInst>(Op);
556 if (II || IOp)
557 return II && IOp &&
558 isEquivalentIntrinsicID(II->getIntrinsicID(),
559 IOp->getIntrinsicID()) !=
561 return true;
562}
563
565 assert(MainOp && "MainOp cannot be nullptr.");
566 if (isSameOperation(I, MainOp))
567 return MainOp;
568 if (MainOp->getOpcode() == Instruction::Select &&
569 I->getOpcode() == Instruction::ZExt && !isAltShuffle())
570 return MainOp;
571 if (MainOp->getOpcode() == Instruction::ICmp &&
572 I->getOpcode() == Instruction::Trunc && !isAltShuffle())
573 return MainOp;
574 // Prefer AltOp instead of interchangeable instruction of MainOp.
575 assert(AltOp && "AltOp cannot be nullptr.");
576 if (isSameOperation(I, AltOp))
577 return AltOp;
578 // BinOpSameOpcodeHelper handles only BinaryOperators; a call cannot match.
579 if (!I->isBinaryOp() || !MainOp->isBinaryOp())
580 return nullptr;
582 if (!Converter.add(I) || !Converter.add(MainOp))
583 return nullptr;
584 if (isAltShuffle() && !Converter.hasCandidateOpcode(MainOp->getOpcode())) {
585 BinOpSameOpcodeHelper AltConverter(AltOp);
586 if (AltConverter.add(I) && AltConverter.add(AltOp) &&
587 AltConverter.hasCandidateOpcode(AltOp->getOpcode()))
588 return AltOp;
589 }
590 if (Converter.hasAltOp() && !isAltShuffle())
591 return nullptr;
592 return Converter.hasAltOp() ? AltOp : MainOp;
593}
594
596 constexpr std::array<unsigned, 8> MulDiv = {
597 Instruction::Mul, Instruction::FMul, Instruction::SDiv,
598 Instruction::UDiv, Instruction::FDiv, Instruction::SRem,
599 Instruction::URem, Instruction::FRem};
600 return is_contained(MulDiv, getOpcode()) &&
601 is_contained(MulDiv, getAltOpcode());
602}
603
605 constexpr std::array<unsigned, 4> AddSub = {
606 Instruction::Add, Instruction::Sub, Instruction::FAdd, Instruction::FSub};
607 return is_contained(AddSub, getOpcode()) &&
608 is_contained(AddSub, getAltOpcode());
609}
610
612 return isAddSubLikeOp() || getOpcode() == Instruction::FNeg;
613}
614
616 assert(valid() && "InstructionsState is invalid.");
617 if (!HasCopyables)
618 return false;
619 if (isAltShuffle())
620 return false;
621 auto *I = dyn_cast<Instruction>(V);
622 // Copyable lanes of a cast node are limited to constants representable as
623 // the cast of a source-type constant.
624 if (isa<CastInst>(MainOp)) {
625 if (I || isa<PoisonValue>(V))
626 return false;
627 if (isa<UndefValue>(V))
628 return true;
629 auto *C = dyn_cast<ConstantInt>(V);
630 return C && C->getValue().getActiveBits() <=
631 cast<CastInst>(MainOp)->getSrcTy()->getIntegerBitWidth();
632 }
633 // Copyable lanes of an integer compare node are limited to the i1
634 // constants.
635 if (auto *Cmp = dyn_cast<ICmpInst>(MainOp))
636 return !I && CmpSamePredicateHelper::canConvertTo(V, Cmp->getPredicate());
637 if (!I)
638 return !isa<PoisonValue>(V);
639 // For a GEP main op only single-index GEPs with the same source element
640 // type can be matching lanes; GEPs with a different shape are copyable.
641 if (getOpcode() == Instruction::GetElementPtr)
642 if (auto *GEP = dyn_cast<GetElementPtrInst>(I);
643 GEP && (GEP->getNumOperands() != 2 ||
644 GEP->getSourceElementType() !=
645 cast<GetElementPtrInst>(MainOp)->getSourceElementType()))
646 return true;
647 if (!IsRegion && I->getParent() != MainOp->getParent() &&
650 return true;
651 if (isSameOperation(I, MainOp))
652 return false;
653 // BinOpSameOpcodeHelper handles only BinaryOperators; a call is copyable.
654 if (!I->isBinaryOp() || !MainOp->isBinaryOp())
655 return true;
657 return !Converter.add(I) || !Converter.add(MainOp) || Converter.hasAltOp() ||
658 !Converter.hasCandidateOpcode(getOpcode());
659}
660
662 auto *I = dyn_cast<Instruction>(V);
663 return I &&
664 (I->getOpcode() == Instruction::FMul ||
665 I->getOpcode() == Instruction::FAdd) &&
666 I->hasOneUse() && none_of(I->operands(), [&](Value *Op) {
667 return is_contained(VL, Op);
668 });
669}
670
672 auto *I = dyn_cast<Instruction>(V);
673 return I && S.isCopyableElement(I) &&
674 (I->getOpcode() == Instruction::FMul ||
675 I->getOpcode() == Instruction::FAdd) &&
676 I->hasOneUse();
677}
678
680 bool HasFMulOrFAdd = false;
681 for (Value *V :
682 make_filter_range(VL, [](Value *V) { return !isa<PoisonValue>(V); })) {
683 auto *I = dyn_cast<Instruction>(V);
685 continue;
686 if (!isAbsorbableFMulOrFAdd(VL, V))
687 return false;
688 HasFMulOrFAdd = true;
689 }
690 return HasFMulOrFAdd;
691}
692
694 assert(valid() && "InstructionsState is invalid.");
695 if (isCopyableElement(V))
696 return false;
697 auto *ExpandingOp = dyn_cast<Instruction>(V);
698 if (!ExpandingOp)
699 return false;
700 auto CheckForTransformedOpcode = [](const Instruction *RefOp,
701 const Instruction *ExpandingOp) {
702 switch (RefOp->getOpcode()) {
703 case Instruction::Add:
704 switch (ExpandingOp->getOpcode()) {
705 case Instruction::Shl:
706 return match(ExpandingOp, m_Shl(m_Value(), m_One()));
707 default:
708 break;
709 }
710 break;
711 default:
712 break;
713 }
714 return false;
715 };
716 // getMatchingMainOpOrAltOp() may legitimately return nullptr, e.g. for a
717 // split node, whose Scalars combine two unrelated operations (main/alt
718 // ops of the split state), so V is not required to match either of them.
719 Instruction *MainOp = getMatchingMainOpOrAltOp(ExpandingOp);
720 if (!MainOp)
721 return false;
722 return CheckForTransformedOpcode(MainOp, ExpandingOp);
723}
724
726 assert(isExpandedBinOp(I) && "Expected an expanded binop.");
727 switch (I->getOpcode()) {
728 case Instruction::Shl:
729 assert(match(I, m_Shl(m_Value(), m_One())) && "Expected shl x, 1 only.");
730 return Idx == 1;
731 default:
732 llvm_unreachable("Unexpected opcode for an expanded operand.");
733 }
734}
735
737 assert(valid() && "InstructionsState is invalid.");
738 auto *I = dyn_cast<Instruction>(V);
739 if (!HasCopyables)
742 // MainOp for copyables always schedulable to correctly identify
743 // non-schedulable copyables. The region nodes are not scheduled.
744 if (!IsRegion && getMainOp() == V)
745 return false;
746 if (isCopyableElement(V)) {
747 auto IsNonSchedulableCopyableElement = [this](Value *V) {
748 auto *I = dyn_cast<Instruction>(V);
749 return !I || isa<PHINode>(I) || I->getParent() != MainOp->getParent() ||
751 // If the copyable instructions comes after MainOp
752 // (non-schedulable, but used in the block) - cannot vectorize
753 // it, will possibly generate use before def.
754 !MainOp->comesBefore(I));
755 };
756
757 return IsNonSchedulableCopyableElement(V);
758 }
761}
762
763/// Find an instruction with a specific opcode in VL.
764/// \param VL Array of values to search through. Must contain only Instructions
765/// and PoisonValues.
766/// \param Opcode The instruction opcode to search for
767/// \returns
768/// - The first instruction found with matching opcode
769/// - nullptr if no matching instruction is found
771 unsigned Opcode) {
772 for (Value *V :
773 make_filter_range(VL, [](Value *V) { return !isa<PoisonValue>(V); })) {
774 assert(isa<Instruction>(V) && "Only accepts PoisonValue and Instruction.");
775 auto *Inst = cast<Instruction>(V);
776 if (Inst->getOpcode() == Opcode)
777 return Inst;
778 }
779 return nullptr;
780}
781
782/// Checks if the provided operands of 2 cmp instructions are compatible, i.e.
783/// compatible instructions or constants, or just some other regular values.
784static bool areCompatibleCmpOps(Value *BaseOp0, Value *BaseOp1, Value *Op0,
785 Value *Op1, const TargetLibraryInfo &TLI) {
786 return (isConstant(BaseOp0) && isConstant(Op0)) ||
787 (isConstant(BaseOp1) && isConstant(Op1)) ||
788 (!isa<Instruction>(BaseOp0) && !isa<Instruction>(Op0) &&
789 !isa<Instruction>(BaseOp1) && !isa<Instruction>(Op1)) ||
790 BaseOp0 == Op0 || BaseOp1 == Op1 ||
791 getSameOpcode({BaseOp0, Op0}, TLI) ||
792 getSameOpcode({BaseOp1, Op1}, TLI);
793}
794
795/// \returns true if a compare instruction \p CI has similar "look" and
796/// same predicate as \p BaseCI, "as is" or with its operands and predicate
797/// swapped, false otherwise.
798static bool isCmpSameOrSwapped(const CmpInst *BaseCI, const CmpInst *CI,
799 const TargetLibraryInfo &TLI) {
800 assert(BaseCI->getOperand(0)->getType() == CI->getOperand(0)->getType() &&
801 "Assessing comparisons of different types?");
802 CmpInst::Predicate BasePred = BaseCI->getPredicate();
803 CmpInst::Predicate Pred = CI->getPredicate();
805
806 Value *BaseOp0 = BaseCI->getOperand(0);
807 Value *BaseOp1 = BaseCI->getOperand(1);
808 Value *Op0 = CI->getOperand(0);
809 Value *Op1 = CI->getOperand(1);
810
811 return (BasePred == Pred &&
812 areCompatibleCmpOps(BaseOp0, BaseOp1, Op0, Op1, TLI)) ||
813 (BasePred == SwappedPred &&
814 areCompatibleCmpOps(BaseOp0, BaseOp1, Op1, Op0, TLI));
815}
816
818 const TargetLibraryInfo &TLI) {
819 // Make sure these are all Instructions.
822
823 auto *It = find_if(VL, IsaPred<Instruction>);
824 if (It == VL.end())
826
827 Instruction *MainOp = cast<Instruction>(*It);
828 unsigned InstCnt = std::count_if(It, VL.end(), IsaPred<Instruction>);
829 if ((VL.size() > 2 && !isa<PHINode>(MainOp) && InstCnt < VL.size() / 2) ||
830 (VL.size() == 2 && InstCnt < 2))
832
833 // Match trunc X to i1 lanes against the compares.
834 if (isa<TruncInst>(MainOp) && MainOp->getType()->isIntOrIntVectorTy(1))
835 if (auto *CmpIt = find_if(VL, IsaPred<ICmpInst>); CmpIt != VL.end())
836 MainOp = cast<Instruction>(*CmpIt);
837
838 bool IsCastOp = isa<CastInst>(MainOp);
839 bool IsBinOp = isa<BinaryOperator>(MainOp);
840 bool IsCmpOp = isa<CmpInst>(MainOp);
841 CmpInst::Predicate BasePred = IsCmpOp ? cast<CmpInst>(MainOp)->getPredicate()
843 Instruction *AltOp = MainOp;
844 unsigned Opcode = MainOp->getOpcode();
845 unsigned AltOpcode = Opcode;
846
847 BinOpSameOpcodeHelper BinOpHelper(MainOp);
848 bool SwappedPredsCompatible = IsCmpOp && [&]() {
849 SetVector<unsigned> UniquePreds, UniqueNonSwappedPreds;
850 UniquePreds.insert(BasePred);
851 UniqueNonSwappedPreds.insert(BasePred);
852 for (Value *V : VL) {
853 auto *I = dyn_cast<CmpInst>(V);
854 if (!I)
855 return false;
856 CmpInst::Predicate CurrentPred = I->getPredicate();
857 CmpInst::Predicate SwappedCurrentPred =
858 CmpInst::getSwappedPredicate(CurrentPred);
859 UniqueNonSwappedPreds.insert(CurrentPred);
860 if (!UniquePreds.contains(CurrentPred) &&
861 !UniquePreds.contains(SwappedCurrentPred))
862 UniquePreds.insert(CurrentPred);
863 }
864 // Total number of predicates > 2, but if consider swapped predicates
865 // compatible only 2, consider swappable predicates as compatible opcodes,
866 // not alternate.
867 return UniqueNonSwappedPreds.size() > 2 && UniquePreds.size() == 2;
868 }();
869 // Find the predicate the whole bundle can share, if any, treating
870 // boundary comparisons canonicalized to eq/ne as interchangeable.
872 if (IsCmpOp && isa<ICmpInst>(MainOp))
873 InterchangeablePred =
875 // Check for one alternate opcode from another BinaryOperator.
876 // TODO - generalize to support all operators (types, calls etc.).
877 Intrinsic::ID BaseID = 0;
878 SmallVector<VFInfo, 4> BaseMappings;
879 if (auto *CallBase = dyn_cast<CallInst>(MainOp)) {
881 BaseMappings = VFDatabase(*CallBase).getMappings(*CallBase);
882 if (!isTriviallyVectorizable(BaseID) && BaseMappings.empty())
884 }
885 bool AnyPoison = InstCnt != VL.size();
886 // Check MainOp too to be sure that it matches the requirements for the
887 // instructions.
888 for (Instruction *I :
890 // Cannot combine poison and divisions.
891 // TODO: do some smart analysis of the CallInsts to exclude divide-like
892 // intrinsics/functions only.
893 if (AnyPoison && (I->isIntDivRem() || I->isFPDivRem() || isa<CallInst>(I)))
895 unsigned InstOpcode = I->getOpcode();
896 if (IsBinOp && isa<BinaryOperator>(I)) {
897 if (BinOpHelper.add(I))
898 continue;
899 } else if (IsCastOp && isa<CastInst>(I)) {
900 Value *Op0 = MainOp->getOperand(0);
901 Type *Ty0 = Op0->getType();
902 Value *Op1 = I->getOperand(0);
903 Type *Ty1 = Op1->getType();
904 if (Ty0 == Ty1) {
905 if (InstOpcode == Opcode || InstOpcode == AltOpcode)
906 continue;
907 if (Opcode == AltOpcode) {
909 isValidForAlternation(InstOpcode) &&
910 "Cast isn't safe for alternation, logic needs to be updated!");
911 AltOpcode = InstOpcode;
912 AltOp = I;
913 continue;
914 }
915 }
916 } else if (auto *Inst = dyn_cast<CmpInst>(I); Inst && IsCmpOp) {
917 auto *BaseInst = cast<CmpInst>(MainOp);
918 Type *Ty0 = BaseInst->getOperand(0)->getType();
919 Type *Ty1 = Inst->getOperand(0)->getType();
920 if (Ty0 == Ty1) {
921 assert(InstOpcode == Opcode && "Expected same CmpInst opcode.");
922 assert(InstOpcode == AltOpcode &&
923 "Alternate instructions are only supported by BinaryOperator "
924 "and CastInst.");
925 // Check for compatible operands. If the corresponding operands are not
926 // compatible - need to perform alternate vectorization.
927 CmpInst::Predicate CurrentPred = Inst->getPredicate();
928 CmpInst::Predicate SwappedCurrentPred =
929 CmpInst::getSwappedPredicate(CurrentPred);
930
931 if ((VL.size() == 2 || SwappedPredsCompatible) &&
932 (BasePred == CurrentPred || BasePred == SwappedCurrentPred))
933 continue;
934
935 if (isCmpSameOrSwapped(BaseInst, Inst, TLI))
936 continue;
937 if (CmpSamePredicateHelper::canConvertTo(Inst, InterchangeablePred))
938 continue;
939 auto *AltInst = cast<CmpInst>(AltOp);
940 if (MainOp != AltOp) {
941 if (isCmpSameOrSwapped(AltInst, Inst, TLI))
942 continue;
943 } else if (BasePred != CurrentPred) {
944 assert(
945 isValidForAlternation(InstOpcode) &&
946 "CmpInst isn't safe for alternation, logic needs to be updated!");
947 AltOp = I;
948 continue;
949 }
950 CmpInst::Predicate AltPred = AltInst->getPredicate();
951 if (BasePred == CurrentPred || BasePred == SwappedCurrentPred ||
952 AltPred == CurrentPred || AltPred == SwappedCurrentPred)
953 continue;
954 }
955 } else if (auto *TI = dyn_cast<TruncInst>(I); TI && IsCmpOp) {
956 // trunc X to i1 is the bit test and X, 1 != 0 or and X, 1 == 1, so the
957 // whole list must be the bit tests of the same type sharing the
958 // predicate.
959 if (InterchangeablePred != CmpInst::BAD_ICMP_PREDICATE &&
960 TI->getSrcTy() == MainOp->getOperand(0)->getType() &&
961 all_of(VL, [](Value *V) {
962 auto *I = dyn_cast<Instruction>(V);
963 return isa<PoisonValue>(V) ||
965 }))
966 continue;
967 } else if (InstOpcode == Opcode) {
968 assert(InstOpcode == AltOpcode &&
969 "Alternate instructions are only supported by BinaryOperator and "
970 "CastInst.");
971 if (auto *Gep = dyn_cast<GetElementPtrInst>(I)) {
972 if (Gep->getNumOperands() != 2 ||
973 Gep->getOperand(0)->getType() != MainOp->getOperand(0)->getType())
975 } else if (auto *EI = dyn_cast<ExtractElementInst>(I)) {
978 } else if (auto *LI = dyn_cast<LoadInst>(I)) {
979 auto *BaseLI = cast<LoadInst>(MainOp);
980 if (!LI->isSimple() || !BaseLI->isSimple())
982 } else if (auto *Call = dyn_cast<CallInst>(I)) {
983 auto *CallBase = cast<CallInst>(MainOp);
985 Intrinsic::ID Equivalent = isEquivalentIntrinsicID(ID, BaseID);
986 if (Call->getCalledFunction() != CallBase->getCalledFunction() &&
987 isEquivalentIntrinsicID(Equivalent, Intrinsic::fmuladd) ==
990 if (Call->hasOperandBundles() &&
992 !std::equal(Call->op_begin() + Call->getBundleOperandsStartIndex(),
993 Call->op_begin() + Call->getBundleOperandsEndIndex(),
994 CallBase->op_begin() +
997 if (ID != BaseID && Equivalent == Intrinsic::not_intrinsic)
999 if (!ID) {
1000 SmallVector<VFInfo, 4> Mappings =
1001 VFDatabase(*Call).getMappings(*Call);
1002 if (Mappings.size() != BaseMappings.size() ||
1003 Mappings.front().ISA != BaseMappings.front().ISA ||
1004 Mappings.front().ScalarName != BaseMappings.front().ScalarName ||
1005 Mappings.front().VectorName != BaseMappings.front().VectorName ||
1006 Mappings.front().Shape.VF != BaseMappings.front().Shape.VF ||
1007 Mappings.front().Shape.Parameters !=
1008 BaseMappings.front().Shape.Parameters)
1010 }
1011 }
1012 continue;
1013 }
1015 }
1016
1017 if (IsBinOp) {
1018 if (!BinOpHelper.hasDefinedMainOpcode() ||
1019 !BinOpHelper.hasDefinedAltOpcode())
1021 MainOp = findInstructionWithOpcode(VL, BinOpHelper.getMainOpcode());
1022 assert(MainOp && "Cannot find MainOp with Opcode from BinOpHelper.");
1023 AltOp = findInstructionWithOpcode(VL, BinOpHelper.getAltOpcode());
1024 assert(AltOp && "Cannot find AltOp with Opcode from BinOpHelper.");
1025 } else if (auto *CB = dyn_cast<CallInst>(MainOp);
1026 CB &&
1027 getVectorIntrinsicIDForCall(CB, &TLI) == Intrinsic::fmuladd) {
1028 // fma and fmuladd share a single vector fma node; use the fma as the
1029 // representative so the fused form is not weakened to fmuladd.
1030 auto *It = find_if(VL, [&](Value *V) {
1031 auto *CI = dyn_cast<CallInst>(V);
1032 return CI && getVectorIntrinsicIDForCall(CI, &TLI) == Intrinsic::fma;
1033 });
1034 if (It != VL.end())
1035 MainOp = AltOp = cast<Instruction>(*It);
1036 }
1037 if (IsCmpOp && InterchangeablePred != CmpInst::BAD_ICMP_PREDICATE &&
1038 InterchangeablePred != BasePred) {
1039 // Every lane is convertible to the shared predicate, so the alternate
1040 // operation is never set for such bundles.
1041 auto *SharedIt = find_if(VL, [&](Value *V) {
1042 auto *CI = dyn_cast<ICmpInst>(V);
1043 return CI && CI->getPredicate() == InterchangeablePred;
1044 });
1045 assert(SharedIt != VL.end() &&
1046 "Expected an instruction with the shared predicate.");
1047 MainOp = AltOp = cast<Instruction>(*SharedIt);
1048 }
1049 assert((MainOp == AltOp || !allSameOpcode(VL)) &&
1050 "Incorrect implementation of allSameOpcode.");
1051 InstructionsState S(MainOp, AltOp);
1052 assert(all_of(VL,
1053 [&](Value *V) {
1054 return isa<PoisonValue>(V) ||
1056 }) &&
1057 "Invalid InstructionsState.");
1058 return S;
1059}
1060
1062 const LoopInfo &LI) {
1063 auto Insts = make_isa_range<Instruction>(VL);
1064 if (Insts.empty() || all_of(VL, isVectorLikeInstWithConstOps))
1065 return false;
1066 const Loop *L = LI.getLoopFor((*Insts.begin())->getParent());
1068 for (Instruction *I : Insts) {
1069 const BasicBlock *BB = I->getParent();
1070 if (Blocks.insert(BB).second &&
1071 (!DT.isReachableFromEntry(BB) || LI.getLoopFor(BB) != L))
1072 return false;
1073 }
1074 return Blocks.size() > 1;
1075}
1076
1077/// Checks if \p BB, dominated by \p Entry, is executed as often as \p Entry:
1078/// every path from \p Entry passes \p BB before it leaves the blocks, dominated
1079/// by \p Entry in the same loop (or out of loops), or returns to \p Entry. The
1080/// paths, ending with unreachable, never return and do not matter.
1082 const BasicBlock *BB,
1083 const DominatorTree &DT,
1084 const LoopInfo &LI) {
1085 assert(Entry != BB && "Expected a block other than the region entry.");
1086 const Loop *L = LI.getLoopFor(Entry);
1087 if (LI.getLoopFor(BB) != L)
1088 return false;
1089 // shortcut: the regions of more than 64 blocks are rejected and the lanes in
1090 // the irreducible cycles are not detected; cache the walk and use the cycle
1091 // info, if they matter.
1092 constexpr unsigned MaxBlocks = 64;
1095 while (!Worklist.empty()) {
1096 const BasicBlock *Succ = Worklist.pop_back_val();
1097 if (Succ == BB || !Visited.insert(Succ).second)
1098 continue;
1099 if (Succ == Entry || Visited.size() > MaxBlocks ||
1100 LI.getLoopFor(Succ) != L || !DT.dominates(Entry, Succ))
1101 return false;
1102 if (succ_empty(Succ) && !isa<UnreachableInst>(Succ->getTerminator()))
1103 return false;
1104 append_range(Worklist, successors(Succ));
1105 }
1106 return true;
1107}
1108
1110 const DominatorTree &DT, const LoopInfo &LI) {
1111 if (!S || S.isAltShuffle())
1112 return nullptr;
1113 // The non-schedulable instructions are safe to speculate, they can be moved
1114 // to any point dominated by their operands and dominating their users. The
1115 // copyable elements are kept as is, only the values and the PHIs of the
1116 // entry block are allowed.
1117 auto Insts = make_isa_range<Instruction>(VL);
1118 Instruction *InsertPt = nullptr;
1120 for (Instruction *I : Insts) {
1121 if (S.isCopyableElement(I)) {
1122 if (!isa<PHINode>(I))
1123 return nullptr;
1124 continue;
1125 }
1127 return nullptr;
1128 Blocks.insert(I->getParent());
1129 InsertPt = InsertPt ? DT.findNearestCommonDominator(InsertPt, I) : I;
1130 }
1131 // The vector code is emitted before the first scalar in the entry block, so
1132 // the entry must have such a scalar and the operands must be defined outside
1133 // of this block (or be its PHIs), the instructions of the block can be
1134 // reordered by the scheduler. The EH pads are not vectorized.
1135 BasicBlock *Entry = InsertPt->getParent();
1136 if (InsertPt->isTerminator() || Entry->isEHPad())
1137 return nullptr;
1138 if (!all_of(Insts, [&](Instruction *I) {
1139 if (S.isCopyableElement(I))
1140 return I->getParent() == Entry;
1141 // The operands dominate the scalars, so they dominate the entry if
1142 // their blocks do.
1143 auto Ops = make_isa_range<Instruction>(I->operands());
1144 return all_of(Ops, [&](Instruction *OpI) {
1145 return OpI->getParent() == Entry
1146 ? isa<PHINode>(OpI)
1147 : DT.dominates(OpI->getParent(), Entry);
1148 });
1149 }))
1150 return nullptr;
1151 // The scalars are executed as often as the vector code in the entry.
1152 if (any_of(Blocks, [&](const BasicBlock *BB) {
1153 return BB != Entry && !isControlEquivalentToEntry(Entry, BB, DT, LI);
1154 }))
1155 return nullptr;
1156 return Entry;
1157}
1158
1159std::pair<Instruction *, SmallVector<Value *>>
1161 Instruction *SelectedOp = S.getMatchingMainOpOrAltOp(I);
1162 assert(SelectedOp && "Cannot convert the instruction.");
1163 if (I->isBinaryOp()) {
1165 return std::make_pair(SelectedOp, Converter.getOperand(SelectedOp));
1166 }
1167 // Use args() to skip the trailing callee operand in CallInst::operands().
1168 if (auto *CI = dyn_cast<CallInst>(I))
1169 return std::make_pair(SelectedOp, SmallVector<Value *>(CI->args()));
1170 // A comparison lane interchangeable with the main operation (e.g. x == 0
1171 // in an x <u C bundle) is emitted with the main predicate and the
1172 // adjusted constant.
1173 if (auto *MainCI = dyn_cast<ICmpInst>(SelectedOp);
1174 MainCI && !S.isAltShuffle())
1176 I, MainCI->getPredicate()))
1177 return std::make_pair(SelectedOp,
1178 SmallVector<Value *>{I->getOperand(0), C});
1179 return std::make_pair(SelectedOp, SmallVector<Value *>(I->operands()));
1180}
1181
1183 Instruction *AltOp, const TargetLibraryInfo &TLI) {
1184 if (auto *MainCI = dyn_cast<CmpInst>(MainOp)) {
1185 auto *AltCI = cast<CmpInst>(AltOp);
1186 CmpInst::Predicate MainP = MainCI->getPredicate();
1187 [[maybe_unused]] CmpInst::Predicate AltP = AltCI->getPredicate();
1188 assert(MainP != AltP && "Expected different main/alternate predicates.");
1189 auto *CI = cast<CmpInst>(I);
1190 if (isCmpSameOrSwapped(MainCI, CI, TLI))
1191 return false;
1192 if (isCmpSameOrSwapped(AltCI, CI, TLI))
1193 return true;
1194 CmpInst::Predicate P = CI->getPredicate();
1196
1197 assert((MainP == P || AltP == P || MainP == SwappedP || AltP == SwappedP) &&
1198 "CmpInst expected to match either main or alternate predicate or "
1199 "their swap.");
1200 return MainP != P && MainP != SwappedP;
1201 }
1202 return InstructionsState(MainOp, AltOp).getMatchingMainOpOrAltOp(I) == AltOp;
1203}
1204
1206 const InstructionsState &S, const TargetLibraryInfo &TLI,
1208 SmallVectorImpl<Value *> &ReassocScalars, SmallBitVector &SubLanes) {
1209 assert(S.isAltShuffle() && "Expected an alternate node.");
1210 const unsigned NumLanes = VL.size();
1211 SmallVector<unsigned> LaneOpcodes =
1212 map_to_vector(seq<unsigned>(NumLanes), [&](unsigned Lane) {
1214 S.getMainOp(), S.getAltOp(), TLI)
1215 ? S.getAltOpcode()
1216 : S.getOpcode();
1217 });
1218 // A lane value peels only as a single-use chain link with the lane's own
1219 // opcode, keeping every combine level on the same main/alt pattern.
1220 auto GetChainLink = [&](unsigned Lane, Value *V) -> Instruction * {
1221 auto *I = dyn_cast<Instruction>(V);
1222 if (!I || !I->hasOneUse() || I->getOpcode() != LaneOpcodes[Lane] ||
1224 return nullptr;
1225 return I;
1226 };
1228 Columns.emplace_back(Op0.begin(), Op0.end());
1229 Columns.emplace_back(Op1.begin(), Op1.end());
1230 // The chain link of a commutative lane may sit in the second column;
1231 // normalize so every lane's link leads.
1232 for (unsigned Lane : seq<unsigned>(NumLanes)) {
1233 if (GetChainLink(Lane, Columns[0][Lane]))
1234 continue;
1235 Instruction *Link = GetChainLink(Lane, Columns[1][Lane]);
1236 if (!Link || !Link->isCommutative())
1237 return {};
1238 std::swap(Columns[0][Lane], Columns[1][Lane]);
1239 }
1240 // Peel the leading column while every lane stays a matching chain link.
1241 while (all_of(seq<unsigned>(NumLanes), [&](unsigned Lane) {
1242 return GetChainLink(Lane, Columns[0][Lane]) != nullptr;
1243 })) {
1244 SmallVector<Value *> NewColumn(NumLanes);
1245 for (unsigned Lane : seq<unsigned>(NumLanes)) {
1246 Instruction *Link = GetChainLink(Lane, Columns[0][Lane]);
1247 ReassocScalars.push_back(Link);
1248 // The chain of a commutative lane may continue in the second operand;
1249 // keep the chain link as the running value.
1250 unsigned RunningOp = Link->isCommutative() &&
1251 !GetChainLink(Lane, Link->getOperand(0)) &&
1252 GetChainLink(Lane, Link->getOperand(1))
1253 ? 1
1254 : 0;
1255 NewColumn[Lane] = Link->getOperand(1 - RunningOp);
1256 Columns[0][Lane] = Link->getOperand(RunningOp);
1257 }
1258 Columns.insert(std::next(Columns.begin()), std::move(NewColumn));
1259 }
1260 assert(!ReassocScalars.empty() &&
1261 "Normalization guarantees at least one peeled level.");
1262 SubLanes.resize(NumLanes);
1263 for (unsigned Lane : seq<unsigned>(NumLanes))
1264 if (LaneOpcodes[Lane] == Instruction::Sub ||
1265 LaneOpcodes[Lane] == Instruction::FSub)
1266 SubLanes.set(Lane);
1267 return Columns;
1268}
1269
1270std::pair<Instruction *, Instruction *>
1272 Instruction *MainOp = nullptr;
1273 Instruction *AltOp = nullptr;
1274 for (Value *V :
1275 make_filter_range(VL, [](Value *V) { return !isa<PoisonValue>(V); })) {
1276 auto *I = dyn_cast<Instruction>(V);
1277 if (!I)
1278 return {};
1279 if (!MainOp) {
1280 MainOp = I;
1281 continue;
1282 }
1283 if (MainOp->getOpcode() == I->getOpcode()) {
1284 if (I->getParent() != MainOp->getParent())
1285 return {};
1286 continue;
1287 }
1288 if (!AltOp) {
1289 AltOp = I;
1290 continue;
1291 }
1292 if (AltOp->getOpcode() == I->getOpcode()) {
1293 if (I->getParent() != AltOp->getParent())
1294 return {};
1295 continue;
1296 }
1297 return {};
1298 }
1299 if (!AltOp)
1300 return {};
1301 assert(MainOp && AltOp && MainOp->getOpcode() != AltOp->getOpcode() &&
1302 "Expected different main and alt instructions.");
1303 return std::make_pair(MainOp, AltOp);
1304}
1305
1307 const TargetLibraryInfo &TLI,
1309 SmallVectorImpl<Value *> &Calls) {
1310 assert(S && S.getOpcode() == Instruction::ExtractValue &&
1311 "Expected extractvalue instruction state.");
1313 return false;
1314 auto *VL0 = cast<ExtractValueInst>(S.getMainOp());
1315 ArrayRef<unsigned> VL0Indices = VL0->getIndices();
1317 for (Value *V : VL) {
1318 if (V == VL0) {
1319 Aggregates.push_back(VL0->getAggregateOperand());
1320 continue;
1321 }
1322 auto *IV = cast<ExtractValueInst>(V);
1323 if (IV->getIndices() != VL0Indices ||
1324 isa<ScalableVectorType>(IV->getType()))
1325 return false;
1326 Value *Agg = IV->getAggregateOperand();
1327 Aggregates.push_back(Agg);
1328 }
1329 const InstructionsState AggState = getSameOpcode(Aggregates, TLI);
1330 if (AggState && AggState.getOpcode() == Instruction::Call &&
1331 !AggState.isAltShuffle() &&
1332 isa<StructType>(AggState.getMainOp()->getType()) &&
1333 canVectorizeTy(AggState.getMainOp()->getType()) &&
1335 // The struct-returning call may have non-bundle users too. The external
1336 // extraction code rebuilds scalars by extractvalue + extractelement,
1337 // which only works when every user of the call is an ExtractValueInst.
1338 // Bail out if any aggregate has a different kind of user.
1339 for (Value *Agg : Aggregates) {
1340 if (!all_of(Agg->users(), IsaPred<ExtractValueInst>))
1341 return false;
1342 }
1343 Indices.assign(VL0Indices.begin(), VL0Indices.end());
1344 Calls.swap(Aggregates);
1345 return true;
1346 }
1347 return false;
1348}
1349
1350} // namespace llvm::slpvectorizer
const TargetLowering & TLI
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Early If Converter
Hexagon Common GEP
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
#define P(N)
Scalar Replacement Of Aggregates
Definition SROA.cpp:6722
This file contains some templates that are useful if you are working with the STL at all.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines less commonly used SmallVector utilities.
This file defines the SmallVector class.
Value * RHS
Value * LHS
This file implements the C++20 <bit> header.
static const uint32_t IV[8]
Definition blake3_impl.h:83
Class for arbitrary precision integers.
Definition APInt.h:78
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1560
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition APInt.h:202
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
Definition APInt.h:367
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition APInt.h:376
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1508
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Definition APInt.h:1115
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition APInt.h:205
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition APInt.h:215
unsigned logBase2() const
Definition APInt.h:1781
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
Definition APInt.h:436
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:196
bool isOne() const
Determine if this is a value of 1.
Definition APInt.h:385
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition APInt.h:235
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
iterator begin() const
Definition ArrayRef.h:129
LLVM Basic Block Representation.
Definition BasicBlock.h:61
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:236
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
unsigned getBundleOperandsStartIndex() const
Return the index of the first bundle operand in the Use array.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
This class is the base class for the comparison instructions.
Definition InstrTypes.h:728
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ ICMP_SLT
signed less than
Definition InstrTypes.h:769
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:770
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:764
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:767
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:768
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:766
bool isSigned() const
Definition InstrTypes.h:993
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Definition InstrTypes.h:890
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Definition InstrTypes.h:852
Predicate getPredicate() const
Return the predicate for this instruction.
Definition InstrTypes.h:828
bool isIntPredicate() const
Definition InstrTypes.h:846
static LLVM_ABI Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
This is an important base class in LLVM.
Definition Constant.h:44
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
LLVM_ABI bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
LLVM_ABI Instruction * findNearestCommonDominator(Instruction *I1, Instruction *I2) const
Find the nearest instruction I that dominates both I1 and I2, in the sense that a result produced bef...
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
This instruction compares its operands according to the predicate given to the constructor.
static LLVM_ABI bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
bool isTerminator() const
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool isIntDivRem() const
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
static bool isFMulAddIntrinsic(Instruction *I)
Returns true if the instruction is a call to the llvm.fmuladd intrinsic.
A vector that has set insertion semantics.
Definition SetVector.h:57
size_type size() const
Determine the number of elements in the SetVector.
Definition SetVector.h:103
bool contains(const_arg_type key) const
Check if the SetVector contains the given key.
Definition SetVector.h:258
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
SmallBitVector & set()
void resize(unsigned N, bool t=false)
Grow or shrink the bitvector.
size_type size() const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
reference emplace_back(ArgTypes &&... Args)
iterator insert(iterator I, T &&Elt)
void swap(SmallVectorImpl &RHS)
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:258
op_iterator op_begin()
Definition User.h:259
Value * getOperand(unsigned i) const
Definition User.h:207
The Vector Function Database.
Definition VectorUtils.h:35
static SmallVector< VFInfo, 8 > getMappings(const CallInst &CI)
Retrieve all the VFInfo instances associated to the CallInst CI.
Definition VectorUtils.h:76
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
const ParentTy * getParent() const
Definition ilist_node.h:34
Helper class that determines VL can use the same opcode.
bool hasCandidateOpcode(unsigned Opcode) const
Checks if the list of potential opcodes includes Opcode.
Helper class that determines whether a list of integer comparisons can share a single predicate.
static CmpInst::Predicate getSharedPredicate(ArrayRef< Value * > VL, const ICmpInst *Preferred)
Returns the predicate the whole list can share, or BAD_ICMP_PREDICATE when it cannot share a natively...
static SmallVector< Value * > getConstantLaneOperands(const Value *V, const ICmpInst *Cmp)
Returns the constant operands expressing the i1 constant lane V as the comparison Cmp.
static Constant * getAdjustedConstant(const Instruction *I, CmpInst::Predicate Pred)
Returns the adjusted constant operand expressing the comparison lane I with the predicate Pred,...
CmpInst::Predicate getPredicate(const ICmpInst *Preferred) const
Returns the shared predicate, preferring the predicate of Preferred when the whole list can use it,...
static bool isBitTest(const Instruction *I)
Checks if the comparison lane I is the bit test of the single use and A, B != 0 or and A,...
static bool canConvertTo(const Value *V, CmpInst::Predicate Pred)
Checks if the comparison lane V can be expressed with the predicate Pred by adjusting its constant op...
bool add(const Value *V)
Intersects the convertible predicate set of the comparison lane V (an icmp, a trunc to i1 or an i1 co...
Main data required for vectorization of instructions.
Instruction * getMatchingMainOpOrAltOp(Instruction *I) const
Checks if the instruction matches either the main or alternate opcode.
static bool isSameOperation(const Instruction *I, const Instruction *Op)
Checks if I is the same operation as Op, distinguishing calls by intrinsic ID (all calls share the Ca...
bool valid() const
Checks if the current state is valid, i.e. has non-null MainOp.
bool isExpandedBinOp(Value *V) const
Checks if the value V is a transformed instruction, compatible either with main or alternate ops.
bool isAddSubLikeOp() const
Checks if main/alt instructions are add/sub/fadd/fsub operations.
bool isExpandedOperand(Instruction *I, unsigned Idx) const
Checks if the operand at index Idx of instruction I is an expanded operand.
bool isCopyableElement(Value *V) const
Checks if the value is a copyable element.
bool isAltShuffle() const
Some of the instructions in the list have alternate opcodes.
bool isNonSchedulable(Value *V) const
Checks if the value is non-schedulable.
bool isAddSubOrFNegLikeOp() const
Checks for an add/sub-like operation or an fneg, which models a flattened fadd reduction chain link: ...
bool isMulDivLikeOp() const
Checks if main/alt instructions are mul/div/rem/fmul/fdiv/frem operations.
unsigned getOpcode() const
The main/alternate opcodes for the list of instructions.
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
bool match(Val *V, const Pattern &P)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
auto m_Value()
Match an arbitrary value and ignore it.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
A private "module" namespace for types and utilities used by this pass.
static std::optional< std::pair< bool, APInt > > getCmpBoundaryFamily(CmpInst::Predicate Pred, const APInt &C)
If the comparison (Pred, X, C) is a single-element or single-complement range check,...
SmallVector< SmallVector< Value * > > scanAltAssociativeOperands(const InstructionsState &S, const TargetLibraryInfo &TLI, ArrayRef< Value * > VL, ArrayRef< Value * > Op0, ArrayRef< Value * > Op1, SmallVectorImpl< Value * > &ReassocScalars, SmallBitVector &SubLanes)
Peel the per-lane associative chains of an alternate node into operand columns.
std::pair< Instruction *, SmallVector< Value * > > convertTo(Instruction *I, const InstructionsState &S)
std::pair< Instruction *, Instruction * > getMainAltOpsNoStateVL(ArrayRef< Value * > VL)
Returns main/alternate instructions for the given VL.
bool isAlternateInstruction(Instruction *I, Instruction *MainOp, Instruction *AltOp, const TargetLibraryInfo &TLI)
Checks if the specified instruction I is an alternate operation for the given MainOp and AltOp instru...
static std::optional< std::pair< CmpInst::Predicate, APInt > > getLaneConstantCmp(const Instruction *I)
Returns the predicate and the compared constant of the comparison lane I, treating trunc X to i1 as a...
bool allSameOpcode(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:292
bool isValidForAlternation(unsigned Opcode)
static bool areCompatibleCmpOps(Value *BaseOp0, Value *BaseOp1, Value *Op0, Value *Op1, const TargetLibraryInfo &TLI)
Checks if the provided operands of 2 cmp instructions are compatible, i.e.
static Instruction * findInstructionWithOpcode(ArrayRef< Value * > VL, unsigned Opcode)
Find an instruction with a specific opcode in VL.
bool hasOnlyAbsorbableCopyableFMulOrFAdds(ArrayRef< Value * > VL)
Checks if every copyable in VL is an absorbable fmul/fadd: the binops die instead of being computed a...
bool isCommutative(const Instruction *I, const Value *ValWithUses, bool IsCopyable)
Definition SLPUtils.cpp:196
bool checkEVsForVecCalls(ArrayRef< Value * > VL, const InstructionsState &S, const TargetLibraryInfo &TLI, SmallVectorImpl< unsigned > &Indices, SmallVectorImpl< Value * > &Calls)
Detects an extractvalue bundle that can be widened by vectorizing the underlying struct-returning cal...
BasicBlock * getSESERegionEntry(ArrayRef< Value * > VL, const InstructionsState &S, const DominatorTree &DT, const LoopInfo &LI)
bool allSameBlock(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:145
bool isReassocChainLink(const Instruction *I)
Definition SLPUtils.cpp:90
Intrinsic::ID isEquivalentIntrinsicID(Intrinsic::ID LHS, Intrinsic::ID RHS)
Checks if LHS and RHS are the same intrinsic, or one is llvm.fma and the other is llvm....
Definition SLPUtils.cpp:187
bool isFMAOrFMulAdd(const Instruction *I)
Checks if I is a call to llvm.fma or llvm.fmuladd.
InstructionsState getSameOpcode(ArrayRef< Value * > VL, const TargetLibraryInfo &TLI)
bool isAbsorbableCopyableFMulOrFAdd(const InstructionsState &S, Value *V)
Checks if V is a copyable single-use fmul/fadd, absorbable as fmuladd(a, b, -0.0) or fmuladd(1....
bool areRegionScalars(ArrayRef< Value * > VL, const DominatorTree &DT, const LoopInfo &LI)
Checks if the instructions in VL are in different reachable blocks of the same loop (or all of them a...
bool isVectorLikeInstWithConstOps(Value *V)
Checks if V is one of vector-like instructions, i.e.
Definition SLPUtils.cpp:98
bool doesNotNeedToBeScheduled(Value *V)
Checks if the specified value does not require scheduling.
Definition SLPUtils.cpp:503
static bool isControlEquivalentToEntry(const BasicBlock *Entry, const BasicBlock *BB, const DominatorTree &DT, const LoopInfo &LI)
Checks if BB, dominated by Entry, is executed as often as Entry: every path from Entry passes BB befo...
bool isConstant(Value *V)
Definition SLPUtils.cpp:48
bool isAbsorbableFMulOrFAdd(ArrayRef< Value * > VL, Value *V)
Checks if V is a single-use fmul/fadd with operands outside VL.
static bool isCmpSameOrSwapped(const CmpInst *BaseCI, const CmpInst *CI, const TargetLibraryInfo &TLI)
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.
Definition STLExtras.h:1755
LLVM_ABI Intrinsic::ID getVectorIntrinsicIDForCall(const CallInst *CI, const TargetLibraryInfo *TLI)
Returns intrinsic ID for call.
bool succ_empty(const Instruction *I)
Definition CFG.h:141
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto successors(const MachineBasicBlock *BB)
auto map_to_vector(ContainerTy &&C, FuncTy &&F)
Map a range to a SmallVector with element types deduced from the mapping.
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.h:732
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2229
auto binary_search(R &&Range, T &&Value)
Provide wrappers to std::binary_search which take ranges instead of having to pass begin/end explicit...
Definition STLExtras.h:2055
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition bit.h:204
auto make_isa_range(RangeT &&Range)
Return a range over Range containing only elements for which isa<T> holds, casting each of them to T.
Definition STLExtras.h:567
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1769
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:552
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...
Definition Casting.h:547
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
bool canVectorizeTy(Type *Ty)
Returns true if Ty is a valid vector element type, void, or an unpacked literal struct where all elem...
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1788
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
LLVM_ABI bool isTriviallyVectorizable(Intrinsic::ID ID)
Identify if the intrinsic is trivially vectorizable.
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
Definition Casting.h:866
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:881