[PATCH] D104197: [VPlan] Track both incoming values for first-order recurrence phis.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 13 08:27:11 PDT 2021
fhahn created this revision.
fhahn added reviewers: Ayal, gilr, rengolin.
Herald added subscribers: tschuett, psnobl, rogfer01, bollu, hiraditya.
fhahn requested review of this revision.
Herald added a subscriber: vkmr.
Herald added a project: LLVM.
This patch updates VPWidenPHI recipes for first-order recurrences to
also track the incoming value from the back-edge. Similar to D99294 <https://reviews.llvm.org/D99294>,
which did the same for reductions.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D104197
Files:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
Index: llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
===================================================================
--- llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
+++ llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
@@ -10,7 +10,7 @@
; CHECK-LABEL: sink_replicate_region_1
; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
; CHECK-NEXT: loop:
-; CHECK-NEXT: WIDEN-PHI %0 = phi 0, %conv
+; CHECK-NEXT: WIDEN-PHI ir<%0> = phi ir<0>, ir<%conv>
; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next
; CHECK-NEXT: EMIT vp<%3> = icmp ule ir<%iv> vp<%0>
; CHECK-NEXT: Successor(s): loop.0
@@ -83,7 +83,7 @@
; CHECK-LABEL: sink_replicate_region_2
; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
; CHECK-NEXT: loop:
-; CHECK-NEXT: WIDEN-PHI %recur = phi 0, %recur.next
+; CHECK-NEXT: WIDEN-PHI ir<%recur> = phi ir<0>, ir<%recur.next>
; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next
; CHECK-NEXT: EMIT vp<%3> = icmp ule ir<%iv> vp<%0>
; CHECK-NEXT: Successor(s): loop.0
@@ -155,7 +155,7 @@
; CHECK-LABEL: sink_replicate_region_3_reduction
; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
; CHECK-NEXT: loop:
-; CHECK-NEXT: WIDEN-PHI %recur = phi 0, %recur.next
+; CHECK-NEXT: WIDEN-PHI ir<%recur> = phi ir<0>, ir<%recur.next>
; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next
; CHECK-NEXT: WIDEN-PHI ir<%and.red> = phi ir<1234>, ir<%and.red.next>
; CHECK-NEXT: EMIT vp<%4> = icmp ule ir<%iv> vp<%0>
@@ -214,7 +214,7 @@
; CHECK-LABEL: sink_replicate_region_4_requires_split_at_end_of_block
; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
; CHECK-NEXT: loop:
-; CHECK-NEXT: WIDEN-PHI %0 = phi 0, %conv
+; CHECK-NEXT: WIDEN-PHI ir<%0> = phi ir<0>, ir<%conv>
; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next
; CHECK-NEXT: EMIT vp<%3> = icmp ule ir<%iv> vp<%0>
; CHECK-NEXT: REPLICATE ir<%gep> = getelementptr ir<%ptr>, ir<%iv>
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4757,7 +4757,7 @@
assert(PN->getParent() == OrigLoop->getHeader() &&
"Non-header phis should have been handled elsewhere");
- VPValue *StartVPV = PhiR->getStartValue();
+ VPValue *StartVPV = RdxDesc ? PhiR->getStartValue() : nullptr;
Value *StartV = StartVPV ? StartVPV->getLiveInIRValue() : nullptr;
// In order to support recurrences we need to be able to vectorize Phi nodes.
// Phi nodes have cycles, so we need to vectorize them in two stages. This is
@@ -8958,22 +8958,32 @@
if ((Recipe = tryToOptimizeInductionPHI(Phi, Operands)))
return toVPRecipeResult(Recipe);
+ VPWidenPHIRecipe *PhiRecipe = nullptr;
+ VPValue *StartV = Operands[0];
if (Legal->isReductionVariable(Phi)) {
RecurrenceDescriptor &RdxDesc = Legal->getReductionVars()[Phi];
assert(RdxDesc.getRecurrenceStartValue() ==
Phi->getIncomingValueForBlock(OrigLoop->getLoopPreheader()));
- VPValue *StartV = Operands[0];
- auto *PhiRecipe = new VPWidenPHIRecipe(Phi, RdxDesc, *StartV);
- PhisToFix.push_back(PhiRecipe);
+ PhiRecipe = new VPWidenPHIRecipe(Phi, RdxDesc, *StartV);
// Record the incoming value from the backedge, so we can add the incoming
// value from the backedge after all recipes have been created.
recordRecipeOf(cast<Instruction>(
Phi->getIncomingValueForBlock(OrigLoop->getLoopLatch())));
- return toVPRecipeResult(PhiRecipe);
+ PhisToFix.push_back(PhiRecipe);
+ } else {
+ PhiRecipe = new VPWidenPHIRecipe(Phi);
+ PhiRecipe->addOperand(StartV);
+ if (Legal->isFirstOrderRecurrence(Phi)) {
+ Value *Incoming =
+ Phi->getIncomingValueForBlock(OrigLoop->getLoopLatch());
+ Instruction *IncI = dyn_cast<Instruction>(Incoming);
+ recordRecipeOf(IncI);
+ PhisToFix.push_back(PhiRecipe);
+ }
}
- return toVPRecipeResult(new VPWidenPHIRecipe(Phi));
+ return toVPRecipeResult(PhiRecipe);
}
if (isa<TruncInst>(Instr) &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104197.351723.patch
Type: text/x-patch
Size: 4277 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210613/47ea0c83/attachment.bin>
More information about the llvm-commits
mailing list