Skip to content

Commit 8000802

Browse files
committed
LoopRotate: handle copy_value and begin_borrow correctly
1 parent 7e8410e commit 8000802

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/SILOptimizer/LoopTransforms/LoopRotate.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ canDuplicateOrMoveToPreheader(SILLoop *loop, SILBasicBlock *preheader,
118118
!isa<TermInst>(inst) &&
119119
!isa<AllocationInst>(inst) && /* not marked mayhavesideeffects */
120120
!isa<CopyValueInst>(inst) &&
121+
!isa<MoveValueInst>(inst) &&
122+
!isa<BeginBorrowInst>(inst) &&
121123
hasLoopInvariantOperands(inst, loop, invariants)) {
122124
moves.push_back(inst);
123125
invariants.insert(inst);

test/SILOptimizer/looprotate_ossa.sil

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,28 +525,35 @@ bb4:
525525
return %1 : $Builtin.RawPointer
526526
}
527527

528-
// CHECK-LABEL: sil [ossa] @looprotate_copy :
528+
// CHECK-LABEL: sil [ossa] @looprotate_copy_move_borrow :
529529
// CHECK: bb0(%0 : $Int32, %1 : @guaranteed $Bar):
530530
// CHECK: copy_value
531+
// CHECK: move_value
532+
// CHECK: begin_borrow
531533
// CHECK: cond_br {{.*}}, bb2, bb1
532534
// CHECK: copy_value
533-
// CHECK-LABEL: } // end sil function 'looprotate_copy'
534-
sil [ossa] @looprotate_copy : $@convention(thin) (Int32, @guaranteed Bar) -> Int32 {
535+
// CHECK: move_value
536+
// CHECK: begin_borrow
537+
// CHECK-LABEL: } // end sil function 'looprotate_copy_move_borrow'
538+
sil [ossa] @looprotate_copy_move_borrow : $@convention(thin) (Int32, @guaranteed Bar) -> Int32 {
535539
bb0(%0 : $Int32, %1 : @guaranteed $Bar):
536540
%2 = struct_extract %0 : $Int32, #Int32._value
537541
%3 = integer_literal $Builtin.Int32, 0
538542
br bb1(%2 : $Builtin.Int32, %3 : $Builtin.Int32)
539543

540544
bb1(%5 : $Builtin.Int32, %6 : $Builtin.Int32):
541-
%7 = copy_value %1 : $Bar
545+
%c = copy_value %1 : $Bar
546+
%m = move_value %c : $Bar
547+
%7 = begin_borrow %m : $Bar
542548
%8 = class_method %7 : $Bar, #Bar.foo : (Bar) -> () -> (), $@convention(method) (@guaranteed Bar) -> ()
543549
%9 = apply %8(%7) : $@convention(method) (@guaranteed Bar) -> ()
544550
%10 = struct $Int32 (%6 : $Builtin.Int32)
545551
%11 = builtin "cmp_eq_Word"(%6 : $Builtin.Int32, %2 : $Builtin.Int32) : $Builtin.Int1
546552
cond_br %11, bb3, bb2
547553

548554
bb2:
549-
destroy_value %7 : $Bar
555+
end_borrow %7 : $Bar
556+
destroy_value %m : $Bar
550557
%14 = integer_literal $Builtin.Int32, 1
551558
%15 = integer_literal $Builtin.Int1, -1
552559
%16 = builtin "sadd_with_overflow_Word"(%6 : $Builtin.Int32, %14 : $Builtin.Int32, %15 : $Builtin.Int1) : $(Builtin.Int32, Builtin.Int1)
@@ -560,7 +567,8 @@ bb2:
560567
br bb1(%23 : $Builtin.Int32, %17 : $Builtin.Int32)
561568

562569
bb3:
563-
destroy_value %7 : $Bar
570+
end_borrow %7 : $Bar
571+
destroy_value %m : $Bar
564572
%26 = struct $Int32 (%5 : $Builtin.Int32)
565573
return %26 : $Int32
566574
}

0 commit comments

Comments
 (0)