Skip to content

Commit 363ad2f

Browse files
authored
Merge pull request #69361 from eeckstein/improve-loop-rotate
LoopRotate: ignore single-block loops where the "backedge" block only contains trivial instructions
2 parents 3bb86f3 + 4db8130 commit 363ad2f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/SILOptimizer/LoopTransforms/LoopRotate.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ static bool isSingleBlockLoop(SILLoop *L) {
288288
&& "Loop not well formed");
289289

290290
// Check whether the back-edge block is just a split-edge.
291-
return ++BackEdge->begin() == BackEdge->end();
291+
for (SILInstruction &inst : make_range(BackEdge->begin(), --BackEdge->end())) {
292+
if (instructionInlineCost(inst) != InlineCost::Free)
293+
return false;
294+
}
295+
return true;
292296
}
293297

294298
/// We rotated a loop if it has the following properties.

test/SILOptimizer/looprotate_ossa.sil

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ bb1:
465465
cond_br %0, bb1a, bb2
466466

467467
bb1a:
468+
%t = tuple(%0 : $Builtin.Int1, %0 : $Builtin.Int1)
468469
br bb1
469470

470471
bb2:

0 commit comments

Comments
 (0)