Files
swift-mirror/test/SILOptimizer/polymorphic_builtins.sil
Michael Gottesman 9864cb9c06 [polymorphic-builtins] Teach constant folding how to fold a polymorphic builtin to its static overload if the passed in type is a concrete builtin type
Specifically, this transforms:

builtin "generic_add"<Builtin.Vec4xInt32>(

  ->

builtin "add_Vec4xInt32"(

If we do not have a static overload for the type, we just leave the generic call
alone. If the generic builtin takes addresses as its arguments (i.e. 2x
in_guaranteed + 1x out), we load the arguments, evaluate the static overloaded
builtin and then store the result into the out parameter.
2019-09-19 17:10:14 -07:00

55 lines
2.7 KiB
Plaintext

// RUN: %target-sil-opt -module-name Swift -diagnostic-constant-propagation %s | %FileCheck %s
sil_stage raw
import Builtin
struct MyInt {
var i : Builtin.Int32
}
// CHECK-LABEL: sil @concrete_type_object_test : $@convention(thin) (Builtin.Vec4xInt32, Builtin.Vec4xInt32) -> Builtin.Vec4xInt32 {
// CHECK: builtin "add_Vec4xInt32"(
// CHECK: return
// CHECK: } // end sil function 'concrete_type_object_test'
sil @concrete_type_object_test : $@convention(thin) (Builtin.Vec4xInt32, Builtin.Vec4xInt32) -> Builtin.Vec4xInt32 {
bb0(%0 : $Builtin.Vec4xInt32, %1 : $Builtin.Vec4xInt32):
%2 = builtin "generic_add"(%0 : $Builtin.Vec4xInt32, %1 : $Builtin.Vec4xInt32) : $Builtin.Vec4xInt32
return %2 : $Builtin.Vec4xInt32
}
// CHECK-LABEL: sil @concrete_type_address_test : $@convention(thin) (@in_guaranteed Builtin.Vec4xInt32, @in_guaranteed Builtin.Vec4xInt32) -> @out Builtin.Vec4xInt32 {
// CHECK: bb0([[RESULT:%.*]] : $*Builtin.Vec4xInt32, [[ARG0:%.*]] : $*Builtin.Vec4xInt32, [[ARG1:%.*]] : $*Builtin.Vec4xInt32):
// CHECK: [[LOADED_ARG0:%.*]] = load [[ARG0]]
// CHECK: [[LOADED_ARG1:%.*]] = load [[ARG1]]
// CHECK: [[LOADED_RESULT:%.*]] = builtin "add_Vec4xInt32"([[LOADED_ARG0]] : $Builtin.Vec4xInt32, [[LOADED_ARG1]] : $Builtin.Vec4xInt32) : $Builtin.Vec4xInt32
// CHECK: store [[LOADED_RESULT]] to [[RESULT]]
// CHECK: } // end sil function 'concrete_type_address_test'
sil @concrete_type_address_test : $@convention(thin) (@in_guaranteed Builtin.Vec4xInt32, @in_guaranteed Builtin.Vec4xInt32) -> @out Builtin.Vec4xInt32 {
bb0(%0 : $*Builtin.Vec4xInt32, %1 : $*Builtin.Vec4xInt32, %2 : $*Builtin.Vec4xInt32):
builtin "generic_add"<Builtin.Vec4xInt32>(%0 : $*Builtin.Vec4xInt32, %1 : $*Builtin.Vec4xInt32, %2 : $*Builtin.Vec4xInt32) : $()
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: sil @concrete_type_object_fail : $@convention(thin) (MyInt, MyInt) -> MyInt {
// CHECK: builtin "generic_add"<MyInt>(
// CHECK: return
// CHECK: } // end sil function 'concrete_type_object_fail'
sil @concrete_type_object_fail : $@convention(thin) (MyInt, MyInt) -> MyInt {
bb0(%0 : $MyInt, %1 : $MyInt):
%2 = builtin "generic_add"<MyInt>(%0 : $MyInt, %1 : $MyInt) : $MyInt
return %2 : $MyInt
}
// CHECK-LABEL: sil @concrete_type_address_fail : $@convention(thin) (@in_guaranteed MyInt, @in_guaranteed MyInt) -> @out MyInt {
// CHECK: builtin "generic_add"<MyInt>(
// CHECK: return
// CHECK: } // end sil function 'concrete_type_address_fail'
sil @concrete_type_address_fail : $@convention(thin) (@in_guaranteed MyInt, @in_guaranteed MyInt) -> @out MyInt {
bb0(%0 : $*MyInt, %1 : $*MyInt, %2 : $*MyInt):
%3 = builtin "generic_add"<MyInt>(%0 : $*MyInt, %1 : $*MyInt, %2 : $*MyInt) : $()
%9999 = tuple()
return %9999 : $()
}