Skip to content

Commit 140caf6

Browse files
authored
Merge pull request #68659 from kubamracek/embedded-ispod
[embedded] Handle thick->thin metatype conversion on IsPOD builtin too
2 parents bfdbac8 + 6a0bfa2 commit 140caf6

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBuiltin.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ extension BuiltinInst : OnoneSimplifyable {
4040
.AssignCopyArrayNoAlias,
4141
.AssignCopyArrayFrontToBack,
4242
.AssignCopyArrayBackToFront,
43-
.AssignTakeArray:
44-
optimizeArrayBuiltin(context)
43+
.AssignTakeArray,
44+
.IsPOD:
45+
optimizeFirstArgumentToThinMetatype(context)
4546
default:
4647
if let literal = constantFold(context) {
4748
uses.replaceAll(with: literal, context)
@@ -173,7 +174,7 @@ private extension BuiltinInst {
173174
context.erase(instruction: self)
174175
}
175176

176-
func optimizeArrayBuiltin(_ context: SimplifyContext) {
177+
func optimizeFirstArgumentToThinMetatype(_ context: SimplifyContext) {
177178
guard let metatypeInst = operands[0].value as? MetatypeInst,
178179
metatypeInst.type.representationOfMetatype(in: parentFunction) == .Thick else {
179180
return

test/embedded/builtins-misc.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-emit-ir %s -parse-stdlib -module-name Swift -enable-experimental-feature Embedded -wmo -target arm64e-apple-none | %FileCheck %s
2+
3+
// REQUIRES: swift_in_compiler
4+
5+
class MyClass {}
6+
7+
struct MyStruct {
8+
var c: MyClass
9+
}
10+
11+
public func foo() -> Builtin.Int1 {
12+
return Builtin.ispod(MyStruct.self)
13+
}
14+
15+
// CHECK: define {{.*}}i1 @"$ss3fooBi1_yF"()
16+
// CHECK-NEXT: entry:
17+
// CHECK-NEXT: ret i1 false
18+
// CHECK-NEXT: }
19+
20+
public func bar() -> Builtin.Int1 {
21+
var s = MyGenericStruct<MyStruct>()
22+
return s.foo()
23+
}
24+
25+
public struct MyGenericStruct<T> {
26+
public func foo() -> Builtin.Int1 {
27+
return Builtin.ispod(T.self)
28+
}
29+
}
30+
31+
// CHECK: define {{.*}}i1 @"$ss15MyGenericStructV3fooBi1_yFs0aC0V_Tg5"()
32+
// CHECK-NEXT: entry:
33+
// CHECK-NEXT: ret i1 false
34+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)