Skip to content

Commit 47def35

Browse files
committed
tidying, more comments
1 parent ca4f6c9 commit 47def35

File tree

7 files changed

+42
-33
lines changed

7 files changed

+42
-33
lines changed

llvm/include/llvm/Analysis/IVDescriptors.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,12 @@ class RecurrenceDescriptor {
178178
/// Returns a struct describing whether the instruction is either a
179179
/// Select(ICmp(A, B), X, Y), or
180180
/// Select(FCmp(A, B), X, Y)
181-
/// where one of (X, Y) is an increasing (FindLast) or decreasing (FindFirst)
182-
/// loop induction variable, and the other is a PHI value.
183-
// TODO: Support non-monotonic variable. FindLast does not need be restricted
184-
// to increasing loop induction variables.
185-
LLVM_ABI static InstDesc isFindIVPattern(RecurKind Kind, Loop *TheLoop,
186-
PHINode *OrigPhi, Instruction *I,
187-
ScalarEvolution &SE);
188-
189-
/// Returns a struct describing whether the instruction is of the form
190-
/// Select(Cmp(A, B), X, Y)
191-
/// where one of (X, Y) is the Phi value and the other is an arbitrary value.
192-
LLVM_ABI static InstDesc isFindLastPattern(Instruction *I, PHINode *Phi,
193-
Loop *TheLoop);
181+
/// where one of (X, Y) is an increasing (FindLastIV) or decreasing
182+
/// (FindFirstIV) loop induction variable or an (FindLast) arbitrary integer
183+
/// value, and the other is a PHI value.
184+
LLVM_ABI static InstDesc isFindPattern(RecurKind Kind, Loop *TheLoop,
185+
PHINode *OrigPhi, Instruction *I,
186+
ScalarEvolution &SE);
194187

195188
/// Returns a struct describing if the instruction is a
196189
/// Select(FCmp(X, Y), (Z = X op PHINode), PHINode) instruction pattern.
@@ -315,7 +308,8 @@ class RecurrenceDescriptor {
315308
}
316309

317310
/// Returns true if the recurrence kind is of the form
318-
/// select(cmp(),x,y) where one of (x,y) is an arbitrary value.
311+
/// select(cmp(),x,y) where one of (x,y) is an arbitrary value and the
312+
/// other is a recurrence.
319313
static bool isFindLastRecurrenceKind(RecurKind Kind) {
320314
return Kind == RecurKind::FindLast;
321315
}

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
1818
#include "llvm/Analysis/ValueTracking.h"
1919
#include "llvm/IR/Dominators.h"
20+
#include "llvm/IR/Instruction.h"
2021
#include "llvm/IR/Instructions.h"
2122
#include "llvm/IR/PatternMatch.h"
2223
#include "llvm/IR/ValueHandle.h"
24+
#include "llvm/Support/Casting.h"
2325
#include "llvm/Support/Debug.h"
2426
#include "llvm/Support/KnownBits.h"
2527

@@ -693,9 +695,9 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
693695
// value of the data type or a non-constant value by using mask and multiple
694696
// reduction operations.
695697
RecurrenceDescriptor::InstDesc
696-
RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
697-
PHINode *OrigPhi, Instruction *I,
698-
ScalarEvolution &SE) {
698+
RecurrenceDescriptor::isFindPattern(RecurKind Kind, Loop *TheLoop,
699+
PHINode *OrigPhi, Instruction *I,
700+
ScalarEvolution &SE) {
699701
// TODO: Support the vectorization of FindLastIV when the reduction phi is
700702
// used by more than one select instruction. This vectorization is only
701703
// performed when the SCEV of each increasing induction variable used by the
@@ -721,16 +723,14 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
721723
return InstDesc(false, I);
722724

723725
// FIXME: Support more complex patterns, including multiple selects.
724-
// Phi or Select must be used only outside the loop,
725-
// except for each other.
726-
if (!all_of(I->users(), [OrigPhi, TheLoop](User *U) {
727-
if (U == OrigPhi)
728-
return true;
729-
if (auto *UI = dyn_cast<Instruction>(U))
730-
return !TheLoop->contains(UI);
731-
return false;
732-
}))
726+
// The Select must be used only outside the loop and by the PHI.
727+
for (User *U : I->users()) {
728+
if (U == OrigPhi)
729+
continue;
730+
if (auto *UI = dyn_cast<Instruction>(U); UI && !TheLoop->contains(UI))
731+
continue;
733732
return InstDesc(false, I);
733+
}
734734

735735
return InstDesc(I, RecurKind::FindLast);
736736
}
@@ -944,7 +944,7 @@ RecurrenceDescriptor::InstDesc RecurrenceDescriptor::isRecurrenceInstr(
944944
Kind == RecurKind::Sub || Kind == RecurKind::AddChainWithSubs)
945945
return isConditionalRdxPattern(I);
946946
if ((isFindIVRecurrenceKind(Kind) || isFindLastRecurrenceKind(Kind)) && SE)
947-
return isFindIVPattern(Kind, L, OrigPhi, I, *SE);
947+
return isFindPattern(Kind, L, OrigPhi, I, *SE);
948948
[[fallthrough]];
949949
case Instruction::FCmp:
950950
case Instruction::ICmp:

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ AArch64TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
10331033
break;
10341034
}
10351035
case Intrinsic::experimental_vector_extract_last_active:
1036-
if (ST->isSVEAvailable()) {
1036+
if (ST->isSVEorStreamingSVEAvailable()) {
10371037
auto [LegalCost, _] = getTypeLegalizationCost(ICA.getArgTypes()[0]);
10381038
// This should turn into chained clastb instructions.
10391039
return LegalCost;

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10011,8 +10011,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1001110011
IC = UserIC > 0 ? UserIC : IC;
1001210012

1001310013
// FIXME: Enable interleaving for last_active reductions.
10014-
if (any_of(LVL.getReductionVars(), [&](auto &Reduction) -> bool {
10015-
const RecurrenceDescriptor &RdxDesc = Reduction.second;
10014+
if (any_of(make_second_range(LVL.getReductionVars()), [&](auto &RdxDesc) {
1001610015
return RecurrenceDescriptor::isFindLastRecurrenceKind(
1001710016
RdxDesc.getRecurrenceKind());
1001810017
})) {

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ struct LLVM_ABI_FOR_TEST VPWidenSelectRecipe : public VPRecipeWithIRFlags,
17721772
}
17731773
};
17741774

1775-
/// A recipe for selecting whole vector values.
1775+
/// A recipe for selecting whole vector values based on a scalar condition.
17761776
struct VPWidenSelectVectorRecipe : public VPRecipeWithIRFlags {
17771777
VPWidenSelectVectorRecipe(ArrayRef<VPValue *> Operands)
17781778
: VPRecipeWithIRFlags(VPDef::VPWidenSelectVectorSC, Operands) {}

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4532,7 +4532,6 @@ void VPlanTransforms::addExitUsersForFirstOrderRecurrences(VPlan &Plan,
45324532
}
45334533
}
45344534

4535-
/// Change CSA reductions to save the appropriate state.
45364535
void VPlanTransforms::convertFindLastRecurrences(
45374536
VPlan &Plan, VPRecipeBuilder &RecipeBuilder,
45384537
LoopVectorizationLegality *Legal) {
@@ -4542,6 +4541,22 @@ void VPlanTransforms::convertFindLastRecurrences(
45424541
if (Plan.hasScalarVFOnly())
45434542
return;
45444543

4544+
// We want to create the following nodes:
4545+
// vec.body:
4546+
// mask.phi = phi <VF x i1> [ all.false, vec.ph ], [ new.mask, vec.body ]
4547+
// ...data.phi already exists, but needs updating...
4548+
// data.phi = phi <VF x Ty> [ default.val, vec.ph ], [ new.data, vec.body ]
4549+
//
4550+
// ...'data' and 'compare' created by existing nodes...
4551+
//
4552+
// any_active = i1 any_of_reduction(compare)
4553+
// new.mask = select any_active, compare, mask.phi
4554+
// new.data = select any_active, data, data.phi
4555+
//
4556+
// middle.block:
4557+
// ...the extract already exists, but needs updating...
4558+
// result = extract-last-active new.data, new.mask, default.val
4559+
45454560
for (const auto &[Phi, RdxDesc] : Legal->getReductionVars()) {
45464561
if (RecurrenceDescriptor::isFindLastRecurrenceKind(
45474562
RdxDesc.getRecurrenceKind())) {

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ struct VPlanTransforms {
380380
static void addExitUsersForFirstOrderRecurrences(VPlan &Plan, VFRange &Range);
381381

382382
/// Change FindLast reductions to save the appropriate state using selects
383-
/// for entire vectors for both the data and the mask..
383+
/// for entire vectors for both the latest mask containing at least one active
384+
/// element and the corresponding data vector.
384385
static void convertFindLastRecurrences(VPlan &Plan,
385386
VPRecipeBuilder &RecipeBuilder,
386387
LoopVectorizationLegality *Legal);

0 commit comments

Comments
 (0)