[llvm] [FunctionSpecializer] Keep the blocks in dead functions and remove the callsites of dead function properly. (PR #154668)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 26 09:54:55 PDT 2025


================
@@ -844,6 +844,16 @@ void FunctionSpecializer::removeDeadFunctions() {
                       << F->getName() << "\n");
     if (FAM)
       FAM->clear(*F, F->getName());
+
+    // Remove all the callsites that were proven unreachable once, and replace
+    // them with poison.
+    for (User *U : make_early_inc_range(F->users())) {
+      assert((isa<CallInst>(U) || isa<InvokeInst>(U)) &&
----------------
XChy wrote:

If there are other kinds of users, `F->eraseFromParent()` should be forbidden, because `F` may be called in an unobservable way. For example, an external function calls it by its pointer.

IIUC, it suggests that what we do in `updateCallSites` is incorrect: 
We mark a function as unreachable if all the direct call sites get specialized, without considering any other users.
Actually, a fully specialized function is not definitely a dead function.

https://github.com/llvm/llvm-project/pull/154668


More information about the llvm-commits mailing list