Skip to content

Commit b426c15

Browse files
authored
Merge pull request #67132 from meg-gupta/bailoutmoveonly
Bail out of canonicalization of single struct field stores for non copyable types
2 parents c413a80 + 8a7d45f commit b426c15

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,14 @@ broadenSingleElementStores(StoreInst *storeInst,
384384
decl->getStoredProperties().size() != 1)
385385
break;
386386

387+
// If the struct is a move-only type, even though the single element in
388+
// the struct is trivial, the struct would be non-trivial. In this case, we
389+
// need a much more compelx analysis to determine the store ownership
390+
// qualifier. Such an analysis is not suitable in the canonicalize pass. So,
391+
// bail out.
392+
if (baseAddrType.isMoveOnly()) {
393+
break;
394+
}
387395
projections.push_back(Projection(inst));
388396
op = baseAddr;
389397
}

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,18 @@ sil [ossa] @get_owned_klass : $@convention(thin) () -> (@owned Klass)
8989
sil @use_anyobject_guaranteed : $@convention(thin) (@guaranteed AnyObject) -> ()
9090
sil @use_generic_obj_guaranteed : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
9191
sil [ossa] @unknown : $@convention(thin) () -> ()
92+
sil [ossa] @get_myint : $@convention(thin) () -> (MyInt)
9293

9394
enum KlassNativeObjEither {
9495
case lhs(Klass)
9596
case rhs(Builtin.NativeObject)
9697
}
9798

99+
@_moveOnly
100+
struct MoveOnlyStruct {
101+
var value: MyInt
102+
}
103+
98104
//////////////////////
99105
// Simple DCE Tests //
100106
//////////////////////
@@ -5396,3 +5402,17 @@ bb0:
53965402
%2 = tuple ()
53975403
return %2 : $()
53985404
}
5405+
5406+
// CHECK-LABEL: sil [ossa] @test_moveonly_singlestoreopt :
5407+
// CHECK: struct_element_addr
5408+
// CHECK-LABEL: } // end sil function 'test_moveonly_singlestoreopt'
5409+
sil [ossa] @test_moveonly_singlestoreopt : $@convention(method) (@inout MoveOnlyStruct) -> () {
5410+
bb0(%0 : $*MoveOnlyStruct):
5411+
%1 = struct_element_addr %0 : $*MoveOnlyStruct, #MoveOnlyStruct.value
5412+
%2 = function_ref @get_myint : $@convention(thin) () -> MyInt
5413+
%3 = apply %2() : $@convention(thin) () -> MyInt
5414+
store %3 to [trivial] %1 : $*MyInt
5415+
%16 = tuple ()
5416+
return %16 : $()
5417+
}
5418+

0 commit comments

Comments
 (0)