Skip to content

Commit 4b8f422

Browse files
committed
[llvm][IR] Treat memcmp and bcmp as libcalls
Since the backend may emit calls to these functions, they should be treated like other libcalls. If we don't, then it is possible to have their definitions removed during LTO because they are dead, only to have a later transform introduce calls to them. See https://discourse.llvm.org/t/rfc-addressing-deficiencies-in-llvm-s-lto-implementation/84999 for more information.
1 parent 34d1490 commit 4b8f422

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ HANDLE_LIBCALL(UO_PPCF128, "__gcc_qunord")
513513
HANDLE_LIBCALL(MEMCPY, "memcpy")
514514
HANDLE_LIBCALL(MEMMOVE, "memmove")
515515
HANDLE_LIBCALL(MEMSET, "memset")
516+
HANDLE_LIBCALL(MEMCMP, "memcmp")
517+
HANDLE_LIBCALL(BCMP, "bcmp")
516518
// DSEPass can emit calloc if it finds a pair of malloc/memset
517519
HANDLE_LIBCALL(CALLOC, "calloc")
518520
HANDLE_LIBCALL(BZERO, nullptr)

llvm/test/LTO/Resolution/X86/bcmp-libcall.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ define i1 @foo(ptr %0, [2 x i32] %1) {
2626
; CHECK: declare i32 @memcmp(ptr, ptr, i32)
2727
declare i32 @memcmp(ptr, ptr, i32)
2828

29-
;; Ensure bcmp is removed from module. Follow up patches can address this.
30-
; CHECK-NOT: declare{{.*}}i32 @bcmp
31-
; CHECK-NOT: define{{.*}}i32 @bcmp
29+
;; Ensure bcmp is not removed from module.
30+
; CHECK: define{{.*}}i32 @bcmp
3231
define i32 @bcmp(ptr %0, ptr %1, i32 %2) {
3332
ret i32 0
3433
}

0 commit comments

Comments
 (0)