[PATCH] D91501: [VPlan] VPTransformState::get() can always return lane 0 for uniforms.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 15 09:31:42 PST 2020
fhahn created this revision.
fhahn added reviewers: Ayal, gilr, rengolin.
Herald added subscribers: psnobl, rogfer01, bollu, hiraditya.
Herald added a project: LLVM.
fhahn requested review of this revision.
Herald added a subscriber: vkmr.
When requesting a scalar value for a uniform VPDef, we can always return
lane 0. This can avoid unnecessary inserting some unncessary instructions
to duplicate the uniform value across lanes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91501
Files:
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
Index: llvm/lib/Transforms/Vectorize/VPlan.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.h
+++ llvm/lib/Transforms/Vectorize/VPlan.h
@@ -286,25 +286,7 @@
}
/// Get the generated Value for a given VPValue and given Part and Lane.
- Value *get(VPValue *Def, const VPIteration &Instance) {
- // If the Def is managed directly by VPTransformState, extract the lane from
- // the relevant part. Note that currently only VPInstructions and external
- // defs are managed by VPTransformState. Other Defs are still created by ILV
- // and managed in its ValueMap. For those this method currently just
- // delegates the call to ILV below.
- if (Data.PerPartOutput.count(Def)) {
- auto *VecPart = Data.PerPartOutput[Def][Instance.Part];
- if (!VecPart->getType()->isVectorTy()) {
- assert(Instance.Lane == 0 && "cannot get lane > 0 for scalar");
- return VecPart;
- }
- // TODO: Cache created scalar values.
- return Builder.CreateExtractElement(VecPart,
- Builder.getInt32(Instance.Lane));
- }
-
- return Callback.getOrCreateScalarValue(VPValue2Value[Def], Instance);
- }
+ Value *get(VPValue *Def, VPIteration Instance);
/// Set the generated Value for a given VPValue and a given Part.
void set(VPValue *Def, Value *V, unsigned Part) {
Index: llvm/lib/Transforms/Vectorize/VPlan.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -244,6 +244,31 @@
return It;
}
+Value *VPTransformState::get(VPValue *Def, VPIteration Instance) {
+ // For uniform definitions, all lanes produce the same value, so we can always
+ // return the first lane.
+ if (auto *ReplicateR = dyn_cast<VPReplicateRecipe>(Def))
+ if (ReplicateR->isUniform())
+ Instance.Lane = 0;
+ // If the Def is managed directly by VPTransformState, extract the lane from
+ // the relevant part. Note that currently only VPInstructions and external
+ // defs are managed by VPTransformState. Other Defs are still created by ILV
+ // and managed in its ValueMap. For those this method currently just
+ // delegates the call to ILV below.
+ if (Data.PerPartOutput.count(Def)) {
+ auto *VecPart = Data.PerPartOutput[Def][Instance.Part];
+ if (!VecPart->getType()->isVectorTy()) {
+ assert(Instance.Lane == 0 && "cannot get lane > 0 for scalar");
+ return VecPart;
+ }
+ // TODO: Cache created scalar values.
+ return Builder.CreateExtractElement(VecPart,
+ Builder.getInt32(Instance.Lane));
+ }
+
+ return Callback.getOrCreateScalarValue(VPValue2Value[Def], Instance);
+}
+
BasicBlock *
VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
// BB stands for IR BasicBlocks. VPBB stands for VPlan VPBasicBlocks.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91501.305370.patch
Type: text/x-patch
Size: 2968 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201115/1cd0caa9/attachment.bin>
More information about the llvm-commits
mailing list