Skip to content

Commit 8e43acb

Browse files
authored
[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.
1 parent ac1a1e5 commit 8e43acb

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
@@ -115,16 +115,7 @@ function(_get_common_compile_options output_var flags)
115115
list(APPEND compile_options "-ffixed-point")
116116
endif()
117117

118-
# Builtin recognition causes issues when trying to implement the builtin
119-
# functions themselves. The GPU backends do not use libcalls so we disable
120-
# the known problematic ones. This allows inlining during LTO linking.
121-
if(LIBC_TARGET_OS_IS_GPU)
122-
set(libc_builtins bcmp strlen memmem bzero memcmp memcpy memmem memmove
123-
memset strcmp strstr)
124-
foreach(builtin ${libc_builtins})
125-
list(APPEND compile_options "-fno-builtin-${builtin}")
126-
endforeach()
127-
else()
118+
if(NOT LIBC_TARGET_OS_IS_GPU)
128119
list(APPEND compile_options "-fno-builtin")
129120
endif()
130121

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)