Skip to content

Commit 270f734

Browse files
authored
Merge pull request #30435 from zoecarver/fix/builtin-is-dead
2 parents 802af8c + 8f15946 commit 270f734

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

include/swift/AST/Builtins.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ BUILTIN_CAST_OR_BITCAST_OPERATION(SExtOrBitCast, "sextOrBitCast", "n")
105105
#endif
106106

107107
#ifndef BUILTIN_BINARY_OPERATION_POLYMORPHIC
108-
#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(Id, Name, Attrs) \
109-
BUILTIN_BINARY_OPERATION(Id, Name, Attrs)
108+
#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(Id, Name) \
109+
BUILTIN_BINARY_OPERATION(Id, Name, "")
110110
#endif
111111

112112
// TODO: This needs a better name. We stringify generic_ in *_{OVERLOADED_STATIC,POLYMORPHIC}
113113
#ifndef BUILTIN_BINARY_OPERATION_ALL
114114
#define BUILTIN_BINARY_OPERATION_ALL(Id, Name, Attrs, Overload) \
115115
BUILTIN_BINARY_OPERATION_OVERLOADED_STATIC(Id, BUILTIN_BINARY_OPERATION_GENERIC_HELPER_STR(Name), Attrs, Overload) \
116-
BUILTIN_BINARY_OPERATION_POLYMORPHIC(Generic##Id, BUILTIN_BINARY_OPERATION_GENERIC_HELPER_STR(generic_##Name), Attrs)
116+
BUILTIN_BINARY_OPERATION_POLYMORPHIC(Generic##Id, BUILTIN_BINARY_OPERATION_GENERIC_HELPER_STR(generic_##Name))
117117
#endif
118118

119119
// NOTE: Here we need our name field to be bare. We stringify them as

lib/AST/Builtins.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ static const OverloadedBuiltinKind OverloadedBuiltinKinds[] = {
12141214
OverloadedBuiltinKind::Special,
12151215
#define BUILTIN_BINARY_OPERATION_OVERLOADED_STATIC(id, name, attrs, overload) \
12161216
OverloadedBuiltinKind::overload,
1217-
#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name, attrs) \
1217+
#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name) \
12181218
OverloadedBuiltinKind::Special,
12191219
#define BUILTIN_BINARY_OPERATION_WITH_OVERFLOW(id, name, _, attrs, overload) \
12201220
OverloadedBuiltinKind::overload,
@@ -1821,7 +1821,7 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
18211821

18221822
#define BUILTIN(id, name, attrs)
18231823
#define BUILTIN_BINARY_OPERATION(id, name, attrs)
1824-
#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name, attrs) \
1824+
#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name) \
18251825
case BuiltinValueKind::id:
18261826
#include "swift/AST/Builtins.def"
18271827
if (!Types.empty())
@@ -2096,7 +2096,7 @@ bool swift::isPolymorphicBuiltin(BuiltinValueKind id) {
20962096
#define BUILTIN(Id, Name, Attrs) \
20972097
case BuiltinValueKind::Id: \
20982098
return false;
2099-
#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(Id, Name, Attrs) \
2099+
#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(Id, Name) \
21002100
case BuiltinValueKind::Id: \
21012101
return true;
21022102
#include "swift/AST/Builtins.def"

lib/IRGen/GenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
314314
llvm::Value *v = IGF.Builder.Create##id(lhs, rhs); \
315315
return out.add(v); \
316316
}
317-
#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name, attrs) \
317+
#define BUILTIN_BINARY_OPERATION_POLYMORPHIC(id, name) \
318318
if (Builtin.ID == BuiltinValueKind::id) { \
319319
/* This builtin must be guarded so that dynamically it is never called. */ \
320320
IGF.emitTrap("invalid use of polymorphic builtin", /*Unreachable*/ false); \

test/SILOptimizer/mandatory_combiner.sil

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,3 +888,33 @@ bb0:
888888
return %13 : $MyInt
889889
} // end sil function 'mixed_nocapture_mixedargs_ossa'
890890

891+
892+
// CHECK-LABEL: sil [ossa] @dont_remove_polymorphic_builtin
893+
// CHECK: builtin "generic_add"
894+
// CHECK-LABEL: end sil function 'dont_remove_polymorphic_builtin'
895+
sil [ossa] @dont_remove_polymorphic_builtin : $@convention(thin) (@guaranteed Klass, @guaranteed Klass, @guaranteed Klass) -> () {
896+
bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass, %2 : @guaranteed $Klass):
897+
%3 = alloc_stack $Klass
898+
%4 = copy_value %0 : $Klass
899+
store %4 to [init] %3 : $*Klass
900+
901+
%6 = alloc_stack $Klass
902+
%7 = copy_value %0 : $Klass
903+
store %7 to [init] %6 : $*Klass
904+
905+
%9 = alloc_stack $Klass
906+
%10 = copy_value %0 : $Klass
907+
store %10 to [init] %9 : $*Klass
908+
909+
// builtin "add" is maked read none so it could be removed below. However,
910+
// builtin "generic_add" does modify memory so, it cannot be removed.
911+
// Make sure we don't remove it.
912+
%12 = builtin "generic_add"<Klass>(%3 : $*Klass, %6 : $*Klass, %9 : $*Klass) : $()
913+
914+
dealloc_stack %9 : $*Klass
915+
dealloc_stack %6 : $*Klass
916+
dealloc_stack %3 : $*Klass
917+
918+
%9999 = tuple ()
919+
return %9999 : $()
920+
}

0 commit comments

Comments
 (0)