diff --git a/include/swift/AST/Builtins.def b/include/swift/AST/Builtins.def index 6925fd42d7703..41e69984310fd 100644 --- a/include/swift/AST/Builtins.def +++ b/include/swift/AST/Builtins.def @@ -105,15 +105,15 @@ BUILTIN_CAST_OR_BITCAST_OPERATION(SExtOrBitCast, "sextOrBitCast", "n") #endif #ifndef BUILTIN_BINARY_OPERATION_POLYMORPHIC -#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(Id, Name, Attrs) \ - BUILTIN_BINARY_OPERATION(Id, Name, Attrs) +#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(Id, Name) \ + BUILTIN_BINARY_OPERATION(Id, Name, "") #endif // TODO: This needs a better name. We stringify generic_ in *_{OVERLOADED_STATIC,POLYMORPHIC} #ifndef BUILTIN_BINARY_OPERATION_ALL #define BUILTIN_BINARY_OPERATION_ALL(Id, Name, Attrs, Overload) \ BUILTIN_BINARY_OPERATION_OVERLOADED_STATIC(Id, BUILTIN_BINARY_OPERATION_GENERIC_HELPER_STR(Name), Attrs, Overload) \ - BUILTIN_BINARY_OPERATION_POLYMORPHIC(Generic##Id, BUILTIN_BINARY_OPERATION_GENERIC_HELPER_STR(generic_##Name), Attrs) + BUILTIN_BINARY_OPERATION_POLYMORPHIC(Generic##Id, BUILTIN_BINARY_OPERATION_GENERIC_HELPER_STR(generic_##Name)) #endif // NOTE: Here we need our name field to be bare. We stringify them as diff --git a/lib/AST/Builtins.cpp b/lib/AST/Builtins.cpp index c3f85c992b6d9..2cd63f283a529 100644 --- a/lib/AST/Builtins.cpp +++ b/lib/AST/Builtins.cpp @@ -1205,7 +1205,7 @@ static const OverloadedBuiltinKind OverloadedBuiltinKinds[] = { OverloadedBuiltinKind::Special, #define BUILTIN_BINARY_OPERATION_OVERLOADED_STATIC(id, name, attrs, overload) \ OverloadedBuiltinKind::overload, -#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name, attrs) \ +#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name) \ OverloadedBuiltinKind::Special, #define BUILTIN_BINARY_OPERATION_WITH_OVERFLOW(id, name, _, attrs, overload) \ OverloadedBuiltinKind::overload, @@ -1812,7 +1812,7 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) { #define BUILTIN(id, name, attrs) #define BUILTIN_BINARY_OPERATION(id, name, attrs) -#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name, attrs) \ +#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name) \ case BuiltinValueKind::id: #include "swift/AST/Builtins.def" if (!Types.empty()) @@ -2084,7 +2084,7 @@ bool swift::isPolymorphicBuiltin(BuiltinValueKind id) { #define BUILTIN(Id, Name, Attrs) \ case BuiltinValueKind::Id: \ return false; -#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(Id, Name, Attrs) \ +#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(Id, Name) \ case BuiltinValueKind::Id: \ return true; #include "swift/AST/Builtins.def" diff --git a/lib/IRGen/GenBuiltin.cpp b/lib/IRGen/GenBuiltin.cpp index 0dae3c3f72bde..16f9a652edca2 100644 --- a/lib/IRGen/GenBuiltin.cpp +++ b/lib/IRGen/GenBuiltin.cpp @@ -313,7 +313,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, llvm::Value *v = IGF.Builder.Create##id(lhs, rhs); \ return out.add(v); \ } -#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name, attrs) \ +#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name) \ if (Builtin.ID == BuiltinValueKind::id) { \ /* This builtin must be guarded so that dynamically it is never called. */ \ IGF.emitTrap("invalid use of polymorphic builtin", /*Unreachable*/ false); \ diff --git a/test/SILOptimizer/mandatory_combiner.sil b/test/SILOptimizer/mandatory_combiner.sil index 53ecc0368f784..7b22803c6eb8e 100644 --- a/test/SILOptimizer/mandatory_combiner.sil +++ b/test/SILOptimizer/mandatory_combiner.sil @@ -888,3 +888,33 @@ bb0: return %13 : $MyInt } // end sil function 'mixed_nocapture_mixedargs_ossa' + +// CHECK-LABEL: sil [ossa] @dont_remove_polymorphic_builtin +// CHECK: builtin "generic_add" +// CHECK-LABEL: end sil function 'dont_remove_polymorphic_builtin' +sil [ossa] @dont_remove_polymorphic_builtin : $@convention(thin) (@guaranteed Klass, @guaranteed Klass, @guaranteed Klass) -> () { +bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass, %2 : @guaranteed $Klass): + %3 = alloc_stack $Klass + %4 = copy_value %0 : $Klass + store %4 to [init] %3 : $*Klass + + %6 = alloc_stack $Klass + %7 = copy_value %0 : $Klass + store %7 to [init] %6 : $*Klass + + %9 = alloc_stack $Klass + %10 = copy_value %0 : $Klass + store %10 to [init] %9 : $*Klass + + // builtin "add" is maked read none so it could be removed below. However, + // builtin "generic_add" does modify memory so, it cannot be removed. + // Make sure we don't remove it. + %12 = builtin "generic_add"(%3 : $*Klass, %6 : $*Klass, %9 : $*Klass) : $() + + dealloc_stack %9 : $*Klass + dealloc_stack %6 : $*Klass + dealloc_stack %3 : $*Klass + + %9999 = tuple () + return %9999 : $() +}