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

Alexandros Lamprineas via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 26 07:56:24 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)) &&
----------------
labrinea wrote:

A user of a fully specialized function may be anything not necessarily a call. For exaple it could be an assignment to function pointer, or a store, or a cast, etc... or even a call to another function with `F` being just an operand.

I think you want to replace the assert with
```
if (auto *CS = dyn_cast<CallBase>(U); CS && CS->getCalledFunction() == F)
```
or do we want to poison all the cases of users I mentioned?

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


More information about the llvm-commits mailing list