Skip to content

Commit bdeb078

Browse files
jhuber6tru
authored andcommitted
[libc] Only add '-fno-builtin-*' on the entrypoints that use them (#100481)
Summary: The GPU build needs to be able to inline stuff in LTO. Builtin transformations cause problems on the functions that the optimizer does heavy libcall recognition on. Previously we moved to using `-fno-builtin-*` to allow us to only disable the problematic ones. However, this still didn't allow inlining because each function had the attribute that told the inliner not to inlining a nobuiltin function into a non-nobuiltin function This patch fixes that by only applying these attributes to the entrypoints that define them. That is enough to prevent recursive calls within the definitoins themselves. (cherry picked from commit 8e43acb)
1 parent 14fa8cd commit bdeb078

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,7 @@ function(_get_common_compile_options output_var flags)
104104
list(APPEND compile_options "-ffixed-point")
105105
endif()
106106

107-
# Builtin recognition causes issues when trying to implement the builtin
108-
# functions themselves. The GPU backends do not use libcalls so we disable
109-
# the known problematic ones. This allows inlining during LTO linking.
110-
if(LIBC_TARGET_OS_IS_GPU)
111-
set(libc_builtins bcmp strlen memmem bzero memcmp memcpy memmem memmove
112-
memset strcmp strstr)
113-
foreach(builtin ${libc_builtins})
114-
list(APPEND compile_options "-fno-builtin-${builtin}")
115-
endforeach()
116-
else()
107+
if(NOT LIBC_TARGET_OS_IS_GPU)
117108
list(APPEND compile_options "-fno-builtin")
118109
endif()
119110

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ function(create_entrypoint_object fq_target_name)
279279
add_dependencies(${fq_target_name} ${full_deps_list})
280280
target_link_libraries(${fq_target_name} ${full_deps_list})
281281

282+
# Builtin recognition causes issues when trying to implement the builtin
283+
# functions themselves. The GPU backends do not use libcalls so we disable the
284+
# known problematic ones on the entrypoints that implement them.
285+
if(LIBC_TARGET_OS_IS_GPU)
286+
set(libc_builtins bcmp strlen memmem bzero memcmp memcpy memmem memmove
287+
memset strcmp strstr)
288+
if(${ADD_ENTRYPOINT_OBJ_NAME} IN_LIST libc_builtins)
289+
target_compile_options(${fq_target_name} PRIVATE -fno-builtin-${ADD_ENTRYPOINT_OBJ_NAME})
290+
endif()
291+
endif()
292+
282293
set_target_properties(
283294
${fq_target_name}
284295
PROPERTIES

0 commit comments

Comments
 (0)