Skip to content

Commit efcaf76

Browse files
committed
!fixup address latest comments, thanks!
1 parent 83a61a0 commit efcaf76

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,19 +3482,18 @@ void InnerLoopVectorizer::fixFixedOrderRecurrence(VPLiveOut *LO,
34823482
Value *ResumeScalarFOR = State.get(VPExtract, UF - 1, true);
34833483

34843484
// Fix the initial value of the original recurrence in the scalar loop.
3485-
Builder.SetInsertPoint(LoopScalarPreHeader, LoopScalarPreHeader->begin());
34863485
PHINode *ScalarHeaderPhi = LO->getPhi();
3487-
auto *NewScalarHeaderPhi =
3488-
Builder.CreatePHI(ScalarHeaderPhi->getType(), 2, "scalar.recur.init");
34893486
auto *InitScalarFOR =
34903487
ScalarHeaderPhi->getIncomingValueForBlock(LoopScalarPreHeader);
3488+
Builder.SetInsertPoint(LoopScalarPreHeader, LoopScalarPreHeader->begin());
3489+
auto *ScalarPreheaderPhi =
3490+
Builder.CreatePHI(ScalarHeaderPhi->getType(), 2, "scalar.recur.init");
34913491
for (auto *BB : predecessors(LoopScalarPreHeader)) {
34923492
auto *Incoming = BB == LoopMiddleBlock ? ResumeScalarFOR : InitScalarFOR;
3493-
NewScalarHeaderPhi->addIncoming(Incoming, BB);
3493+
ScalarPreheaderPhi->addIncoming(Incoming, BB);
34943494
}
3495-
34963495
ScalarHeaderPhi->setIncomingValueForBlock(LoopScalarPreHeader,
3497-
NewScalarHeaderPhi);
3496+
ScalarPreheaderPhi);
34983497
ScalarHeaderPhi->setName("scalar.recur");
34993498
}
35003499

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,13 @@ bool VPlanTransforms::adjustFixedOrderRecurrences(VPlan &Plan,
849849

850850
// This is the second phase of vectorizing first-order recurrences. An
851851
// overview of the transformation is described below. Suppose we have the
852-
// following loop.
852+
// following loop with some use after the loop of the last a[i-1],
853853
//
854-
// for (int i = 0; i < n; ++i)
855-
// b[i] = a[i] - a[i - 1];
854+
// for (int i = 0; i < n; ++i) {
855+
// t = a[i - 1];
856+
// b[i] = a[i] - t;
857+
// }
858+
// use t;
856859
//
857860
// There is a first-order recurrence on "a". For this loop, the shorthand
858861
// scalar IR looks like:
@@ -866,7 +869,10 @@ bool VPlanTransforms::adjustFixedOrderRecurrences(VPlan &Plan,
866869
// s1 = phi [s_init, scalar.ph], [s2, scalar.body]
867870
// s2 = a[i]
868871
// b[i] = s2 - s1
869-
// br cond, scalar.body, ...
872+
// br cond, scalar.body, exit.block
873+
//
874+
// exit.block:
875+
// use = lcssa.phi [s1, scalar.body]
870876
//
871877
// In this example, s1 is a recurrence because it's value depends on the
872878
// previous iteration. In the first phase of vectorization, we created a

0 commit comments

Comments
 (0)