Skip to content

Commit 745921f

Browse files
committed
[LV] Minor savings to Sink casts to unravel first order recurrence
Two minor savings: avoid copying the SinkAfter map and avoid moving a cast if it is not needed. Differential Revision: https://reviews.llvm.org/D36408 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310910 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent faa4dac commit 745921f

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ bool RecurrenceDescriptor::isFirstOrderRecurrence(
565565
auto *I = Phi->user_back();
566566
if (I->isCast() && (I->getParent() == Phi->getParent()) && I->hasOneUse() &&
567567
DT->dominates(Previous, I->user_back())) {
568-
SinkAfter[I] = Previous;
568+
if (!DT->dominates(Previous, I)) // Otherwise we're good w/o sinking.
569+
SinkAfter[I] = Previous;
569570
return true;
570571
}
571572
}

lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7655,7 +7655,7 @@ void LoopVectorizationPlanner::executePlan(InnerLoopVectorizer &ILV) {
76557655
// 2. Copy and widen instructions from the old loop into the new loop.
76567656

76577657
// Move instructions to handle first-order recurrences.
7658-
DenseMap<Instruction *, Instruction *> SinkAfter = Legal->getSinkAfter();
7658+
DenseMap<Instruction *, Instruction *> &SinkAfter = Legal->getSinkAfter();
76597659
for (auto &Entry : SinkAfter) {
76607660
Entry.first->removeFromParent();
76617661
Entry.first->insertAfter(Entry.second);

test/Transforms/LoopVectorize/first-order-recurrence.ll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ scalar.body:
140140
; CHECK: vector.body:
141141
; CHECK: %vector.recur = phi <4 x i16> [ %vector.recur.init, %vector.ph ], [ [[L1:%[a-zA-Z0-9.]+]], %vector.body ]
142142
; CHECK: [[L1]] = load <4 x i16>
143-
; CHECK: {{.*}} = shufflevector <4 x i16> %vector.recur, <4 x i16> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
143+
; CHECK: [[SHUF:%[a-zA-Z0-9.]+]] = shufflevector <4 x i16> %vector.recur, <4 x i16> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
144+
; Check also that the casts were not moved needlessly.
145+
; CHECK: sitofp <4 x i16> [[L1]] to <4 x double>
146+
; CHECK: sitofp <4 x i16> [[SHUF]] to <4 x double>
144147
; CHECK: middle.block:
145148
; CHECK: %vector.recur.extract = extractelement <4 x i16> [[L1]], i32 3
146149
; CHECK: scalar.ph:

0 commit comments

Comments
 (0)