Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c5c5883
[VPlan] Remove dead AnyOf reduction case in VPReductionRecipe. NFCI (…
lukel97 Mar 6, 2025
11ad62c
[FMF] Set all bits if needed when setting individual flags. (#131321)
fhahn Mar 15, 2025
7bd096b
[VPlan] Remove createReduction. NFCI (#131336)
lukel97 Mar 17, 2025
7e73b7a
[VPlan] Make VPReductionRecipe a VPRecipeWithIRFlags. NFC (#130881)
ElvisWang123 Mar 18, 2025
118d349
[LV] Split RecurrenceDescriptor into RecurKind + FastMathFlags in Loo…
lukel97 Mar 19, 2025
c5dbd00
[VPlan] Get DataLayout from SE in VPExpandSCEVRecipe::execute (NFC)
fhahn Mar 22, 2025
615cec7
[LV] Move IV bypass value creation out of ILV (NFC)
fhahn Mar 22, 2025
95a9d2c
[VPlan] Only execute VPExpandSCEVRecipes once and remove them (NFC).
fhahn Mar 23, 2025
1f6be69
[VPlan] Reautogenerate float-induction.ll after last commit
pawosm-arm Apr 9, 2025
8dd520e
[LV] Use VPBuilder to create ComputeReductionResult. (NFC)
fhahn Mar 23, 2025
447cad5
[VPlan] Only store RecurKind + FastMathFlags in VPReductionRecipe. NF…
lukel97 Mar 24, 2025
e4598e0
[VPlan] Split off reduction printing tests, add find-last-IV test.
fhahn Mar 25, 2025
3675c5f
[VPlan] Add ComputeFindLastIVResult opcode (NFC). (#132689)
fhahn Mar 26, 2025
07699e3
[VPlan] Manage FindLastIV start value in ComputeFindLastIVResult (NFC…
fhahn Mar 27, 2025
2493281
[LV] Add epilogue vectorization tests for FindLastIV reductions.
fhahn Mar 31, 2025
e8d8800
[LV] Add FindLastIV test with truncated IV and epilogue vectorization.
fhahn Apr 3, 2025
cfbd563
[LV] Use frozen start value for FindLastIV if needed. (#132691)
fhahn Apr 4, 2025
edcf3b5
[LV] Reautogenerate epilog-iv-select-cmp.ll test files after the rece…
pawosm-arm Apr 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions llvm/include/llvm/IR/FMF.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ class FastMathFlags {

unsigned Flags = 0;

FastMathFlags(unsigned F) {
// If all 7 bits are set, turn this into -1. If the number of bits grows,
// this must be updated. This is intended to provide some forward binary
// compatibility insurance for the meaning of 'fast' in case bits are added.
if (F == 0x7F) Flags = ~0U;
else Flags = F;
}
FastMathFlags(unsigned F) : Flags(F) {}

public:
// This is how the bits are used in Value::SubclassOptionalData so they
Expand All @@ -43,9 +37,12 @@ class FastMathFlags {
NoSignedZeros = (1 << 3),
AllowReciprocal = (1 << 4),
AllowContract = (1 << 5),
ApproxFunc = (1 << 6)
ApproxFunc = (1 << 6),
FlagEnd = (1 << 7)
};

constexpr static unsigned AllFlagsMask = FlagEnd - 1;

FastMathFlags() = default;

static FastMathFlags getFast() {
Expand All @@ -56,10 +53,10 @@ class FastMathFlags {

bool any() const { return Flags != 0; }
bool none() const { return Flags == 0; }
bool all() const { return Flags == ~0U; }
bool all() const { return Flags == AllFlagsMask; }

void clear() { Flags = 0; }
void set() { Flags = ~0U; }
void set() { Flags = AllFlagsMask; }

/// Flag queries
bool allowReassoc() const { return 0 != (Flags & AllowReassoc); }
Expand Down
19 changes: 6 additions & 13 deletions llvm/include/llvm/Transforms/Utils/LoopUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ Value *createSimpleReduction(IRBuilderBase &B, Value *Src,
RecurKind RdxKind);
/// Overloaded function to generate vector-predication intrinsics for
/// reduction.
Value *createSimpleReduction(VectorBuilder &VB, Value *Src,
const RecurrenceDescriptor &Desc);
Value *createSimpleReduction(VectorBuilder &VB, Value *Src, RecurKind RdxKind,
FastMathFlags FMFs);

/// Create a reduction of the given vector \p Src for a reduction of the
/// kind RecurKind::IAnyOf or RecurKind::FAnyOf. The reduction operation is
Expand All @@ -422,23 +422,16 @@ Value *createAnyOfReduction(IRBuilderBase &B, Value *Src,
/// Create a reduction of the given vector \p Src for a reduction of the
/// kind RecurKind::IFindLastIV or RecurKind::FFindLastIV. The reduction
/// operation is described by \p Desc.
Value *createFindLastIVReduction(IRBuilderBase &B, Value *Src,
Value *createFindLastIVReduction(IRBuilderBase &B, Value *Src, Value *Start,
const RecurrenceDescriptor &Desc);

/// Create a generic reduction using a recurrence descriptor \p Desc
/// Fast-math-flags are propagated using the RecurrenceDescriptor.
Value *createReduction(IRBuilderBase &B, const RecurrenceDescriptor &Desc,
Value *Src, PHINode *OrigPhi = nullptr);

/// Create an ordered reduction intrinsic using the given recurrence
/// descriptor \p Desc.
Value *createOrderedReduction(IRBuilderBase &B,
const RecurrenceDescriptor &Desc, Value *Src,
/// kind \p RdxKind.
Value *createOrderedReduction(IRBuilderBase &B, RecurKind RdxKind, Value *Src,
Value *Start);
/// Overloaded function to generate vector-predication intrinsics for ordered
/// reduction.
Value *createOrderedReduction(VectorBuilder &VB,
const RecurrenceDescriptor &Desc, Value *Src,
Value *createOrderedReduction(VectorBuilder &VB, RecurKind RdxKind, Value *Src,
Value *Start);

/// Get the intersection (logical and) of all of the potential IR flags
Expand Down
42 changes: 10 additions & 32 deletions llvm/lib/Transforms/Utils/LoopUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,11 +1209,11 @@ Value *llvm::createAnyOfReduction(IRBuilderBase &Builder, Value *Src,
}

Value *llvm::createFindLastIVReduction(IRBuilderBase &Builder, Value *Src,
Value *Start,
const RecurrenceDescriptor &Desc) {
assert(RecurrenceDescriptor::isFindLastIVRecurrenceKind(
Desc.getRecurrenceKind()) &&
"Unexpected reduction kind");
Value *StartVal = Desc.getRecurrenceStartValue();
Value *Sentinel = Desc.getSentinelValue();
Value *MaxRdx = Src->getType()->isVectorTy()
? Builder.CreateIntMaxReduce(Src, true)
Expand All @@ -1222,7 +1222,7 @@ Value *llvm::createFindLastIVReduction(IRBuilderBase &Builder, Value *Src,
// reduction is sentinel value.
Value *Cmp =
Builder.CreateCmp(CmpInst::ICMP_NE, MaxRdx, Sentinel, "rdx.select.cmp");
return Builder.CreateSelect(Cmp, MaxRdx, StartVal, "rdx.select");
return Builder.CreateSelect(Cmp, MaxRdx, Start, "rdx.select");
}

Value *llvm::getReductionIdentity(Intrinsic::ID RdxID, Type *Ty,
Expand Down Expand Up @@ -1308,53 +1308,31 @@ Value *llvm::createSimpleReduction(IRBuilderBase &Builder, Value *Src,
}

Value *llvm::createSimpleReduction(VectorBuilder &VBuilder, Value *Src,
const RecurrenceDescriptor &Desc) {
RecurKind Kind = Desc.getRecurrenceKind();
RecurKind Kind, FastMathFlags FMFs) {
assert(!RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind) &&
"AnyOf reduction is not supported.");
!RecurrenceDescriptor::isFindLastIVRecurrenceKind(Kind) &&
"AnyOf or FindLastIV reductions are not supported.");
Intrinsic::ID Id = getReductionIntrinsicID(Kind);
auto *SrcTy = cast<VectorType>(Src->getType());
Type *SrcEltTy = SrcTy->getElementType();
Value *Iden = getRecurrenceIdentity(Kind, SrcEltTy, Desc.getFastMathFlags());
Value *Iden = getRecurrenceIdentity(Kind, SrcEltTy, FMFs);
Value *Ops[] = {Iden, Src};
return VBuilder.createSimpleReduction(Id, SrcTy, Ops);
}

Value *llvm::createReduction(IRBuilderBase &B,
const RecurrenceDescriptor &Desc, Value *Src,
PHINode *OrigPhi) {
// TODO: Support in-order reductions based on the recurrence descriptor.
// All ops in the reduction inherit fast-math-flags from the recurrence
// descriptor.
IRBuilderBase::FastMathFlagGuard FMFGuard(B);
B.setFastMathFlags(Desc.getFastMathFlags());

RecurKind RK = Desc.getRecurrenceKind();
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK))
return createAnyOfReduction(B, Src, Desc, OrigPhi);
if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK))
return createFindLastIVReduction(B, Src, Desc);

return createSimpleReduction(B, Src, RK);
}

Value *llvm::createOrderedReduction(IRBuilderBase &B,
const RecurrenceDescriptor &Desc,
Value *llvm::createOrderedReduction(IRBuilderBase &B, RecurKind Kind,
Value *Src, Value *Start) {
assert((Desc.getRecurrenceKind() == RecurKind::FAdd ||
Desc.getRecurrenceKind() == RecurKind::FMulAdd) &&
assert((Kind == RecurKind::FAdd || Kind == RecurKind::FMulAdd) &&
"Unexpected reduction kind");
assert(Src->getType()->isVectorTy() && "Expected a vector type");
assert(!Start->getType()->isVectorTy() && "Expected a scalar type");

return B.CreateFAddReduce(Start, Src);
}

Value *llvm::createOrderedReduction(VectorBuilder &VBuilder,
const RecurrenceDescriptor &Desc,
Value *llvm::createOrderedReduction(VectorBuilder &VBuilder, RecurKind Kind,
Value *Src, Value *Start) {
assert((Desc.getRecurrenceKind() == RecurKind::FAdd ||
Desc.getRecurrenceKind() == RecurKind::FMulAdd) &&
assert((Kind == RecurKind::FAdd || Kind == RecurKind::FMulAdd) &&
"Unexpected reduction kind");
assert(Src->getType()->isVectorTy() && "Expected a vector type");
assert(!Start->getType()->isVectorTy() && "Expected a scalar type");
Expand Down
12 changes: 5 additions & 7 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,17 +442,15 @@ class LoopVectorizationPlanner {
/// TODO: \p VectorizingEpilogue indicates if the executed VPlan is for the
/// epilogue vector loop. It should be removed once the re-use issue has been
/// fixed.
/// \p ExpandedSCEVs is passed during execution of the plan for epilogue loop
/// to re-use expansion results generated during main plan execution.
///
/// Returns a mapping of SCEVs to their expanded IR values.
/// Note that this is a temporary workaround needed due to the current
/// epilogue handling.
DenseMap<const SCEV *, Value *>
executePlan(ElementCount VF, unsigned UF, VPlan &BestPlan,
InnerLoopVectorizer &LB, DominatorTree *DT,
bool VectorizingEpilogue,
const DenseMap<const SCEV *, Value *> *ExpandedSCEVs = nullptr);
DenseMap<const SCEV *, Value *> executePlan(ElementCount VF, unsigned UF,
VPlan &BestPlan,
InnerLoopVectorizer &LB,
DominatorTree *DT,
bool VectorizingEpilogue);

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void printPlans(raw_ostream &O);
Expand Down
Loading
Loading