Skip to content

Commit c640bca

Browse files
authored
Merge pull request #61826 from meg-gupta/rleisuniq
Consider is_unique as a barrier for optimization in OSSA RLE
2 parents c7095e0 + dbc0650 commit c640bca

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/SILOptimizer/Transforms/RedundantLoadElimination.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ static bool isRLEInertInstruction(SILInstruction *Inst) {
152152
case SILInstructionKind::DeallocStackInst:
153153
case SILInstructionKind::CondFailInst:
154154
case SILInstructionKind::IsEscapingClosureInst:
155-
case SILInstructionKind::IsUniqueInst:
156155
case SILInstructionKind::EndCOWMutationInst:
157156
case SILInstructionKind::FixLifetimeInst:
158157
case SILInstructionKind::EndAccessInst:
@@ -162,6 +161,9 @@ static bool isRLEInertInstruction(SILInstruction *Inst) {
162161
case SILInstructionKind::BeginBorrowInst:
163162
case SILInstructionKind::EndBorrowInst:
164163
return true;
164+
case SILInstructionKind::IsUniqueInst:
165+
// TODO: Consider is_unique to be a barrier for optimization.
166+
return !Inst->getFunction()->hasOwnership();
165167
default:
166168
return false;
167169
}

test/SILOptimizer/redundant_load_elim_nontrivial_ossa.sil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ final class NewHalfOpenRangeGenerator : NewRangeGenerator1 {
7575
override init(start: NonTrivialStruct, end: NonTrivialStruct)
7676
}
7777

78+
struct ArrayIntBuffer {
79+
var storage : Builtin.NativeObject
80+
}
81+
82+
struct MyArray<T> {
83+
var buffer : ArrayIntBuffer
84+
}
85+
86+
struct MyStruct {
87+
}
88+
7889
sil_global @total_klass : $Klass
7990
sil_global @total_nontrivialstruct : $NonTrivialStruct
8091

@@ -85,6 +96,7 @@ sil @use_a : $@convention(thin) (@owned A) -> ()
8596
sil @use_twofield : $@convention(thin) (@owned TwoField) -> ()
8697
sil @init_twofield : $@convention(thin) (@thin TwoField.Type) -> @owned TwoField
8798
sil @get_nontrivialstruct : $@convention(thin) () -> @owned NonTrivialStruct
99+
sil [ossa] @get_array : $@convention(thin) () -> @owned MyArray<MyStruct>
88100

89101
// We have a bug in the old projection code which this test case exposes.
90102
// Make sure its handled properly in the new projection.
@@ -1250,3 +1262,18 @@ bb14:
12501262
return %26 : $()
12511263
}
12521264

1265+
// CHECK-LABEL: @test_is_unique :
1266+
// CHECK: load
1267+
// CHECK: } // end sil function 'test_is_unique'
1268+
sil [ossa] @test_is_unique : $@convention(thin) (@in MyArray<MyStruct>) -> () {
1269+
bb0(%0 : $*MyArray<MyStruct>):
1270+
%1 = function_ref @get_array : $@convention(thin) () -> @owned MyArray<MyStruct>
1271+
%2 = apply %1() : $@convention(thin) () -> @owned MyArray<MyStruct>
1272+
store %2 to [assign] %0 : $*MyArray<MyStruct>
1273+
%4 = struct_element_addr %0 : $*MyArray<MyStruct>, #MyArray.buffer
1274+
%5 = is_unique %4 : $*ArrayIntBuffer
1275+
%7 = load [take] %0 : $*MyArray<MyStruct>
1276+
destroy_value %7 : $MyArray<MyStruct>
1277+
%t = tuple ()
1278+
return %t : $()
1279+
}

0 commit comments

Comments
 (0)