|
| 1 | +// This line tests that IRGen is properly turning the unspecialized builtins |
| 2 | +// into traps. |
| 3 | +// |
| 4 | +// RUN: %target-swift-frontend -emit-ir -parse-as-library -parse-stdlib %s | %FileCheck %s |
| 5 | + |
| 6 | +// Make sure we are not eliminating these builtins before IRGen runs. As part of |
| 7 | +// the builtin's contract, we expect IRGen to convert them to traps, not |
| 8 | +// anything before. |
| 9 | +// |
| 10 | +// RUN: %target-swift-frontend -emit-sil -parse-as-library -parse-stdlib %s | %FileCheck --check-prefix=SIL %s |
| 11 | + |
| 12 | +import Swift |
| 13 | + |
| 14 | +// SIL-LABEL: sil [transparent] [serialized] @$s20polymorphic_builtins11_isConcrete4typeSbxm_tlF : $@convention(thin) <T> (@thick T.Type) -> Bool { |
| 15 | +// SIL: builtin "isConcrete"<T>({{%[0-9]*}} : $@thick T.Type) : $Builtin.Int1 |
| 16 | +// SIL: // end sil function '$s20polymorphic_builtins11_isConcrete4typeSbxm_tlF' |
| 17 | +@_transparent |
| 18 | +public func _isConcrete<T>(type: T.Type) -> Bool { |
| 19 | + return Bool(_builtinBooleanLiteral: Builtin.isConcrete(type)) |
| 20 | +} |
| 21 | + |
| 22 | +// SIL-LABEL: sil [transparent] [serialized] @$s20polymorphic_builtins41calleeAddVectorsGenericTransparentGuardedyxx_xtlF : $@convention(thin) <T> (@in_guaranteed T, @in_guaranteed T) -> @out T { |
| 23 | +// SIL: builtin "isConcrete"<T>({{%[0-9]*}} : $@thick T.Type) : $Builtin.Int1 |
| 24 | +// SIL: builtin "generic_add"<T>( |
| 25 | +// SIL: } // end sil function '$s20polymorphic_builtins41calleeAddVectorsGenericTransparentGuardedyxx_xtlF' |
| 26 | + |
| 27 | +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s20polymorphic_builtins41calleeAddVectorsGenericTransparentGuardedyxx_xtlF"( |
| 28 | +// CHECK: br i1 false, label %[[CONCRETE_LABEL:[0-9][0-9]*]], label %[[NON_CONCRETE_LABEL:[0-9][0-9]*]] |
| 29 | +// |
| 30 | +// CHECK: <label>:[[CONCRETE_LABEL]]: |
| 31 | +// CHECK: call void @llvm.trap() |
| 32 | +// CHECK: br label %[[EPILOGUE_BLOCK:[0-9][0-9]*]] |
| 33 | +// |
| 34 | +// CHECK: <label>:[[NON_CONCRETE_LABEL]] |
| 35 | +// CHECK: br label %[[EPILOGUE_BLOCK]] |
| 36 | +/// |
| 37 | +// CHECK: <label>:[[EPILOGUE_BLOCK]]: |
| 38 | +// CHECK: ret void |
| 39 | +// CHECK-NEXT: } |
| 40 | +@_transparent |
| 41 | +public func calleeAddVectorsGenericTransparentGuarded<T>(_ lhs: T, _ rhs: T) -> T { |
| 42 | + if _isConcrete(T.self) { |
| 43 | + return Builtin.generic_add(lhs, rhs) |
| 44 | + } |
| 45 | + return lhs |
| 46 | +} |
| 47 | + |
| 48 | +public func callerAddVectorsGenericTransparent(_ lhs: Builtin.Vec4xInt32, _ rhs: Builtin.Vec4xInt32) -> Builtin.Vec4xInt32 { |
| 49 | + return calleeAddVectorsGenericTransparentGuarded(lhs, rhs) |
| 50 | +} |
0 commit comments