Skip to content

Commit 40508aa

Browse files
fhahnLukacma
authored andcommitted
[VPlan] Move isSingleScalar implementation to VPlanUtils.cpp (NFC)
Move the implementation of vputils::isSingleScalar to VPlanUtils.cpp to enable code sharing.
1 parent de42c9b commit 40508aa

File tree

2 files changed

+55
-53
lines changed

2 files changed

+55
-53
lines changed

llvm/lib/Transforms/Vectorize/VPlanUtils.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,60 @@ const SCEV *vputils::getSCEVExprForVPValue(VPValue *V, ScalarEvolution &SE) {
8989
.Default([&SE](const VPRecipeBase *) { return SE.getCouldNotCompute(); });
9090
}
9191

92+
bool vputils::isSingleScalar(const VPValue *VPV) {
93+
auto PreservesUniformity = [](unsigned Opcode) -> bool {
94+
if (Instruction::isBinaryOp(Opcode) || Instruction::isCast(Opcode))
95+
return true;
96+
switch (Opcode) {
97+
case Instruction::GetElementPtr:
98+
case Instruction::ICmp:
99+
case Instruction::FCmp:
100+
case Instruction::Select:
101+
case VPInstruction::Not:
102+
case VPInstruction::Broadcast:
103+
case VPInstruction::PtrAdd:
104+
return true;
105+
default:
106+
return false;
107+
}
108+
};
109+
110+
// A live-in must be uniform across the scope of VPlan.
111+
if (VPV->isLiveIn())
112+
return true;
113+
114+
if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV)) {
115+
const VPRegionBlock *RegionOfR = Rep->getRegion();
116+
// Don't consider recipes in replicate regions as uniform yet; their first
117+
// lane cannot be accessed when executing the replicate region for other
118+
// lanes.
119+
if (RegionOfR && RegionOfR->isReplicator())
120+
return false;
121+
return Rep->isSingleScalar() || (PreservesUniformity(Rep->getOpcode()) &&
122+
all_of(Rep->operands(), isSingleScalar));
123+
}
124+
if (isa<VPWidenGEPRecipe, VPDerivedIVRecipe, VPBlendRecipe,
125+
VPWidenSelectRecipe>(VPV))
126+
return all_of(VPV->getDefiningRecipe()->operands(), isSingleScalar);
127+
if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) {
128+
return PreservesUniformity(WidenR->getOpcode()) &&
129+
all_of(WidenR->operands(), isSingleScalar);
130+
}
131+
if (auto *VPI = dyn_cast<VPInstruction>(VPV))
132+
return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
133+
(PreservesUniformity(VPI->getOpcode()) &&
134+
all_of(VPI->operands(), isSingleScalar));
135+
if (isa<VPPartialReductionRecipe>(VPV))
136+
return false;
137+
if (isa<VPReductionRecipe>(VPV))
138+
return true;
139+
if (auto *Expr = dyn_cast<VPExpressionRecipe>(VPV))
140+
return Expr->isSingleScalar();
141+
142+
// VPExpandSCEVRecipes must be placed in the entry and are always uniform.
143+
return isa<VPExpandSCEVRecipe>(VPV);
144+
}
145+
92146
bool vputils::isUniformAcrossVFsAndUFs(VPValue *V) {
93147
// Live-ins are uniform.
94148
if (V->isLiveIn())

llvm/lib/Transforms/Vectorize/VPlanUtils.h

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -41,59 +41,7 @@ const SCEV *getSCEVExprForVPValue(VPValue *V, ScalarEvolution &SE);
4141

4242
/// Returns true if \p VPV is a single scalar, either because it produces the
4343
/// same value for all lanes or only has its first lane used.
44-
inline bool isSingleScalar(const VPValue *VPV) {
45-
auto PreservesUniformity = [](unsigned Opcode) -> bool {
46-
if (Instruction::isBinaryOp(Opcode) || Instruction::isCast(Opcode))
47-
return true;
48-
switch (Opcode) {
49-
case Instruction::GetElementPtr:
50-
case Instruction::ICmp:
51-
case Instruction::FCmp:
52-
case Instruction::Select:
53-
case VPInstruction::Not:
54-
case VPInstruction::Broadcast:
55-
case VPInstruction::PtrAdd:
56-
return true;
57-
default:
58-
return false;
59-
}
60-
};
61-
62-
// A live-in must be uniform across the scope of VPlan.
63-
if (VPV->isLiveIn())
64-
return true;
65-
66-
if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV)) {
67-
const VPRegionBlock *RegionOfR = Rep->getRegion();
68-
// Don't consider recipes in replicate regions as uniform yet; their first
69-
// lane cannot be accessed when executing the replicate region for other
70-
// lanes.
71-
if (RegionOfR && RegionOfR->isReplicator())
72-
return false;
73-
return Rep->isSingleScalar() || (PreservesUniformity(Rep->getOpcode()) &&
74-
all_of(Rep->operands(), isSingleScalar));
75-
}
76-
if (isa<VPWidenGEPRecipe, VPDerivedIVRecipe, VPBlendRecipe,
77-
VPWidenSelectRecipe>(VPV))
78-
return all_of(VPV->getDefiningRecipe()->operands(), isSingleScalar);
79-
if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) {
80-
return PreservesUniformity(WidenR->getOpcode()) &&
81-
all_of(WidenR->operands(), isSingleScalar);
82-
}
83-
if (auto *VPI = dyn_cast<VPInstruction>(VPV))
84-
return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
85-
(PreservesUniformity(VPI->getOpcode()) &&
86-
all_of(VPI->operands(), isSingleScalar));
87-
if (isa<VPPartialReductionRecipe>(VPV))
88-
return false;
89-
if (isa<VPReductionRecipe>(VPV))
90-
return true;
91-
if (auto *Expr = dyn_cast<VPExpressionRecipe>(VPV))
92-
return Expr->isSingleScalar();
93-
94-
// VPExpandSCEVRecipes must be placed in the entry and are alway uniform.
95-
return isa<VPExpandSCEVRecipe>(VPV);
96-
}
44+
bool isSingleScalar(const VPValue *VPV);
9745

9846
/// Return true if \p V is a header mask in \p Plan.
9947
bool isHeaderMask(const VPValue *V, const VPlan &Plan);

0 commit comments

Comments
 (0)