Skip to content

Commit cf71fdd

Browse files
fixup! respond to some more reviews
1 parent 696480f commit cf71fdd

File tree

6 files changed

+30
-43
lines changed

6 files changed

+30
-43
lines changed

llvm/include/llvm/Analysis/CSADescriptors.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- llvm/Analysis/CSADescriptors.h - CSA Descriptors --*- C++ -*-===//
1+
//===------------- CSADescriptors.h - CSA Descriptors -----------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

llvm/lib/Analysis/CSADescriptors.cpp

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//=== llvm/Analysis/CSADescriptors.cpp - CSA Descriptors -*- C++ -*-===//
1+
//===----------- CSADescriptors..cpp - CSA Descriptors ----------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -19,43 +19,43 @@ using namespace llvm::PatternMatch;
1919

2020
#define DEBUG_TYPE "csa-descriptors"
2121

22+
/// Return CSADescriptor that describes a CSA that matches one of these
23+
/// patterns:
24+
/// phi loop_inv, (select cmp, value, phi)
25+
/// phi loop_inv, (select cmp, phi, value)
26+
/// phi (select cmp, value, phi), loop_inv
27+
/// phi (select cmp, phi, value), loop_inv
28+
/// If the CSA does not match any of these paterns, return a CSADescriptor
29+
/// that describes an InvalidCSA.
2230
CSADescriptor CSADescriptor::isCSAPhi(PHINode *Phi, Loop *TheLoop) {
23-
// Return CSADescriptor that describes a CSA that matches one of these
24-
// patterns:
25-
// phi loop_inv, (select cmp, value, phi)
26-
// phi loop_inv, (select cmp, phi, value)
27-
// phi (select cmp, value, phi), loop_inv
28-
// phi (select cmp, phi, value), loop_inv
29-
// If the CSA does not match any of these paterns, return a CSADescriptor
30-
// that describes an InvalidCSA.
3131

3232
// Must be a scalar
3333
Type *Type = Phi->getType();
3434
if (!Type->isIntegerTy() && !Type->isFloatingPointTy() &&
3535
!Type->isPointerTy())
36-
return CSADescriptor();
36+
return {};
3737

3838
// Match phi loop_inv, (select cmp, value, phi)
3939
// or phi loop_inv, (select cmp, phi, value)
4040
// or phi (select cmp, value, phi), loop_inv
4141
// or phi (select cmp, phi, value), loop_inv
4242
if (Phi->getNumIncomingValues() != 2)
43-
return CSADescriptor();
44-
auto SelectInstIt = find_if(Phi->incoming_values(), [&Phi](Use &U) {
43+
return {};
44+
auto SelectInstIt = find_if(Phi->incoming_values(), [&Phi](const Use &U) {
4545
return match(U.get(), m_Select(m_Value(), m_Specific(Phi), m_Value())) ||
4646
match(U.get(), m_Select(m_Value(), m_Value(), m_Specific(Phi)));
4747
});
4848
if (SelectInstIt == Phi->incoming_values().end())
49-
return CSADescriptor();
49+
return {};
5050
auto LoopInvIt = find_if(Phi->incoming_values(), [&](Use &U) {
5151
return U.get() != *SelectInstIt && TheLoop->isLoopInvariant(U.get());
5252
});
5353
if (LoopInvIt == Phi->incoming_values().end())
54-
return CSADescriptor();
54+
return {};
5555

5656
// Phi or Sel must be used only outside the loop,
5757
// excluding if Phi use Sel or Sel use Phi
58-
auto IsOnlyUsedOutsideLoop = [=](Value *V, Value *Ignore) {
58+
auto IsOnlyUsedOutsideLoop = [&](Value *V, Value *Ignore) {
5959
return all_of(V->users(), [Ignore, TheLoop](User *U) {
6060
if (U == Ignore)
6161
return true;
@@ -64,10 +64,11 @@ CSADescriptor CSADescriptor::isCSAPhi(PHINode *Phi, Loop *TheLoop) {
6464
return true;
6565
});
6666
};
67-
auto *Sel = cast<SelectInst>(SelectInstIt->get());
68-
auto *LoopInv = LoopInvIt->get();
69-
if (!IsOnlyUsedOutsideLoop(Phi, Sel) || !IsOnlyUsedOutsideLoop(Sel, Phi))
70-
return CSADescriptor();
67+
Instruction *Select = cast<SelectInst>(SelectInstIt->get());
68+
Value *LoopInv = LoopInvIt->get();
69+
if (!IsOnlyUsedOutsideLoop(Phi, Select) ||
70+
!IsOnlyUsedOutsideLoop(Select, Phi))
71+
return {};
7172

72-
return CSADescriptor(Phi, Sel, LoopInv);
73+
return {Phi, Select, LoopInv};
7374
}

llvm/lib/Transforms/Vectorize/VPlan.h

-1
Original file line numberDiff line numberDiff line change
@@ -3986,7 +3986,6 @@ class VPlanSlp {
39863986
/// Return true if all visited instruction can be combined.
39873987
bool isCompletelySLP() const { return CompletelySLP; }
39883988
};
3989-
39903989
} // end namespace llvm
39913990

39923991
#endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_H

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,7 @@ Value *VPInstruction::generatePerPart(VPTransformState &State, unsigned Part) {
679679
State.set(this, InitMask, Part);
680680
return InitMask;
681681
}
682-
Value *V = State.get(this, Part - 1);
683-
return V;
682+
return State.get(this, Part - 1);
684683
}
685684
case VPInstruction::CSAInitData: {
686685
if (Part == 0) {
@@ -689,8 +688,7 @@ Value *VPInstruction::generatePerPart(VPTransformState &State, unsigned Part) {
689688
State.set(this, InitData, Part);
690689
return InitData;
691690
}
692-
Value *V = State.get(this, Part - 1);
693-
return V;
691+
return State.get(this, Part - 1);
694692
}
695693
case VPInstruction::CSAMaskPhi: {
696694
if (Part == 0) {
@@ -2318,7 +2316,7 @@ void VPCSAExtractScalarRecipe::execute(VPTransformState &State) {
23182316
// inactive, which would also cause the reduction to have value 0.
23192317
Value *MaybeLastIdx = State.Builder.CreateIntMaxReduce(ActiveLaneIdxs);
23202318
Value *IsLaneZeroActive =
2321-
State.Builder.CreateExtractElement(MaskSel, (uint64_t)0);
2319+
State.Builder.CreateExtractElement(MaskSel, static_cast<uint64_t>(0));
23222320
Value *Zero = ConstantInt::get(MaybeLastIdx->getType(), 0);
23232321
Value *MaybeLastIdxEQZero = State.Builder.CreateICmpEQ(MaybeLastIdx, Zero);
23242322
Value *And = State.Builder.CreateAnd(IsLaneZeroActive, MaybeLastIdxEQZero);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

+2-11
Original file line numberDiff line numberDiff line change
@@ -1442,17 +1442,8 @@ bool VPlanTransforms::tryAddExplicitVectorLength(VPlan &Plan) {
14421442
}
14431443

14441444
void VPlanTransforms::addExplicitVectorLengthForCSA(
1445-
VPInstruction *VPEVL, const MapVector<PHINode *, VPCSAState *> &CSAStates,
1446-
bool PlanHasScalarVFOnly) {
1447-
1448-
// We build the scalar version of a CSA when VF=ElementCount::getFixed(1),
1449-
// which does not require an EVL.
1450-
if (PlanHasScalarVFOnly)
1451-
return;
1452-
1453-
for (auto CSA : CSAStates) {
1454-
VPCSAState *CSAState = CSA.second;
1455-
1445+
VPInstruction *VPEVL, const MapVector<PHINode *, VPCSAState *> &CSAStates) {
1446+
for (auto &[_, CSAState] : CSAStates) {
14561447
// CSAAnyActive is used to keep track of whether any condition on the
14571448
// current iteration is active. This is used to decide whether the mask
14581449
// should be updated. When we are using EVL, we must only consider the first

llvm/lib/Transforms/Vectorize/VPlanTransforms.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,10 @@ struct VPlanTransforms {
117117

118118
/// Add recipes required to make CSA work with EVL based approach. This
119119
/// includes replacing \p CSAAnyActive with \p CSAAnyActiveEVL, and adding \p
120-
/// CSAVLPhi and \p CSAVLSel instructions. No EVL specific recipes are added
121-
/// when \p PlanHasScalarVFOnly since scalar version of a CSA does not require
122-
/// an EVL.
120+
/// CSAVLPhi and \p CSAVLSel instructions.
123121
static void addExplicitVectorLengthForCSA(
124-
VPInstruction *VPEVL, const MapVector<PHINode *, VPCSAState *> &CSAStates,
125-
bool PlanHasScalarVFOnly);
122+
VPInstruction *VPEVL,
123+
const MapVector<PHINode *, VPCSAState *> &CSAStates);
126124
};
127125

128126
} // namespace llvm

0 commit comments

Comments
 (0)