Skip to content

Commit 2e3be7d

Browse files
committed
Avoid generating address phis in LoopRotate
1 parent 80414ca commit 2e3be7d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/SILOptimizer/LoopTransforms/LoopRotate.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ hasLoopInvariantOperands(SILInstruction *inst, SILLoop *loop,
6565
static bool
6666
canDuplicateOrMoveToPreheader(SILLoop *loop, SILBasicBlock *preheader,
6767
SILBasicBlock *bb,
68-
SmallVectorImpl<SILInstruction *> &moves) {
68+
SmallVectorImpl<SILInstruction *> &moves,
69+
SinkAddressProjections &sinkProj) {
6970
llvm::DenseSet<SILInstruction *> invariants;
7071
int cost = 0;
7172
for (auto &instRef : *bb) {
@@ -120,6 +121,9 @@ canDuplicateOrMoveToPreheader(SILLoop *loop, SILBasicBlock *preheader,
120121
invariants.insert(inst);
121122
continue;
122123
}
124+
if (!sinkProj.analyzeAddressProjections(inst)) {
125+
return false;
126+
}
123127

124128
cost += (int)instructionInlineCost(instRef);
125129
}
@@ -392,8 +396,9 @@ bool swift::rotateLoop(SILLoop *loop, DominanceInfo *domInfo,
392396

393397
// Make sure we can duplicate the header.
394398
SmallVector<SILInstruction *, 8> moveToPreheader;
395-
if (!canDuplicateOrMoveToPreheader(loop, preheader, header,
396-
moveToPreheader)) {
399+
SinkAddressProjections sinkProj;
400+
if (!canDuplicateOrMoveToPreheader(loop, preheader, header, moveToPreheader,
401+
sinkProj)) {
397402
LLVM_DEBUG(llvm::dbgs()
398403
<< *loop << " instructions in header preventing rotating\n");
399404
return false;
@@ -440,6 +445,13 @@ bool swift::rotateLoop(SILLoop *loop, DominanceInfo *domInfo,
440445
// The other instructions are just cloned to the preheader.
441446
TermInst *preheaderBranch = preheader->getTerminator();
442447

448+
// sink address projections to avoid address phis.
449+
for (auto &inst : *header) {
450+
bool success = sinkProj.analyzeAddressProjections(&inst);
451+
assert(success);
452+
sinkProj.cloneProjections();
453+
}
454+
443455
for (auto &inst : *header) {
444456
if (SILInstruction *cloned = inst.clone(preheaderBranch)) {
445457
mapOperands(cloned, valueMap);

0 commit comments

Comments
 (0)