[llvm-branch-commits] [llvm] [llvm][IR] Treat memcmp and bcmp as libcalls (PR #135706)
Paul Kirth via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Apr 15 09:31:59 PDT 2025
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/135706
>From 4b8f422ee979e6063e553f8a5bc292c5a11e13b4 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Mon, 14 Apr 2025 08:25:15 -0700
Subject: [PATCH] [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.
---
llvm/include/llvm/IR/RuntimeLibcalls.def | 2 ++
llvm/test/LTO/Resolution/X86/bcmp-libcall.ll | 5 ++---
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.def b/llvm/include/llvm/IR/RuntimeLibcalls.def
index 2545aebc73391..2c72bc8c012cc 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.def
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.def
@@ -513,6 +513,8 @@ HANDLE_LIBCALL(UO_PPCF128, "__gcc_qunord")
HANDLE_LIBCALL(MEMCPY, "memcpy")
HANDLE_LIBCALL(MEMMOVE, "memmove")
HANDLE_LIBCALL(MEMSET, "memset")
+HANDLE_LIBCALL(MEMCMP, "memcmp")
+HANDLE_LIBCALL(BCMP, "bcmp")
// DSEPass can emit calloc if it finds a pair of malloc/memset
HANDLE_LIBCALL(CALLOC, "calloc")
HANDLE_LIBCALL(BZERO, nullptr)
diff --git a/llvm/test/LTO/Resolution/X86/bcmp-libcall.ll b/llvm/test/LTO/Resolution/X86/bcmp-libcall.ll
index b4e526f83e60f..48ea6291308ab 100644
--- a/llvm/test/LTO/Resolution/X86/bcmp-libcall.ll
+++ b/llvm/test/LTO/Resolution/X86/bcmp-libcall.ll
@@ -26,9 +26,8 @@ define i1 @foo(ptr %0, [2 x i32] %1) {
; CHECK: declare i32 @memcmp(ptr, ptr, i32)
declare i32 @memcmp(ptr, ptr, i32)
-;; Ensure bcmp is removed from module. Follow up patches can address this.
-; CHECK-NOT: declare{{.*}}i32 @bcmp
-; CHECK-NOT: define{{.*}}i32 @bcmp
+;; Ensure bcmp is not removed from module.
+; CHECK: define{{.*}}i32 @bcmp
define i32 @bcmp(ptr %0, ptr %1, i32 %2) {
ret i32 0
}
More information about the llvm-branch-commits
mailing list