[llvm] 27944bb - [Attributor][FIX] Avoid deleting (internal) library functions
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 12 01:17:41 PST 2023
Author: Johannes Doerfert
Date: 2023-01-12T01:17:23-08:00
New Revision: 27944bbbe7ade95ed38b147583fe6392d8d19f5c
URL: https://github.com/llvm/llvm-project/commit/27944bbbe7ade95ed38b147583fe6392d8d19f5c
DIFF: https://github.com/llvm/llvm-project/commit/27944bbbe7ade95ed38b147583fe6392d8d19f5c.diff
LOG: [Attributor][FIX] Avoid deleting (internal) library functions
In CGSCC mode we cannot delete internal library functions, esp.
__kmpc_alloc_shared, or we trigger an assertion. While the assertion is
probably too narrow, we avoid deleting those unused functions for now to
unblock the AMDGPU buildbot.
Added:
llvm/test/Transforms/OpenMP/dead_lib_func.ll
Modified:
llvm/lib/Transforms/IPO/Attributor.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 30450c350c00..a6d7cc71bb9a 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -2094,13 +2094,23 @@ void Attributor::identifyDeadInternalFunctions() {
if (!Configuration.DeleteFns)
return;
+ // To avoid triggering an assertion in the lazy call graph we will not delete
+ // any internal library functions. We should modify the assertion though and
+ // allow internals to be deleted.
+ const auto *TLI =
+ isModulePass()
+ ? nullptr
+ : getInfoCache().getTargetLibraryInfoForFunction(*Functions.back());
+ LibFunc LF;
+
// Identify dead internal functions and delete them. This happens outside
// the other fixpoint analysis as we might treat potentially dead functions
// as live to lower the number of iterations. If they happen to be dead, the
// below fixpoint loop will identify and eliminate them.
+
SmallVector<Function *, 8> InternalFns;
for (Function *F : Functions)
- if (F->hasLocalLinkage())
+ if (F->hasLocalLinkage() && (isModulePass() || !TLI->getLibFunc(*F, LF)))
InternalFns.push_back(F);
SmallPtrSet<Function *, 8> LiveInternalFns;
diff --git a/llvm/test/Transforms/OpenMP/dead_lib_func.ll b/llvm/test/Transforms/OpenMP/dead_lib_func.ll
new file mode 100644
index 000000000000..2501c1cd0537
--- /dev/null
+++ b/llvm/test/Transforms/OpenMP/dead_lib_func.ll
@@ -0,0 +1,28 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals
+; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s --check-prefixes=TUNIT,CHECK
+; RUN: opt -S -passes=openmp-opt-cgscc < %s | FileCheck %s --check-prefixes=CGSCC,CHECK
+
+; TUNIT-NOT: __kmpc_alloc_shared
+
+define internal ptr @__kmpc_alloc_shared(i64) {
+; CGSCC-LABEL: define {{[^@]+}}@__kmpc_alloc_shared
+; CGSCC-SAME: (i64 [[TMP0:%.*]]) {
+; CGSCC-NEXT: ret ptr null
+;
+ ret ptr null
+}
+
+!llvm.module.flags = !{!0, !1}
+
+!0 = !{i32 7, !"openmp", i32 50}
+!1 = !{i32 7, !"openmp-device", i32 50}
+;.
+; TUNIT: [[META0:![0-9]+]] = !{i32 7, !"openmp", i32 50}
+; TUNIT: [[META1:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
+;.
+; CGSCC: [[META0:![0-9]+]] = !{i32 7, !"openmp", i32 50}
+; CGSCC: [[META1:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
+;.
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK: {{.*}}
+; TUNIT: {{.*}}
More information about the llvm-commits
mailing list