[Attributor][FIX] Improve call graph updating
authorJohannes Doerfert <johannes@jdoerfert.de>
Fri, 16 Jul 2021 19:14:37 +0000 (14:14 -0500)
committerJohannes Doerfert <johannes@jdoerfert.de>
Thu, 22 Jul 2021 05:07:56 +0000 (00:07 -0500)
If we remove a non-intrinsic instruction we need to tell the (old) call
graph about it. This caused problems with some features down the line as
they allowed to removed calls more aggressively.

llvm/lib/Transforms/IPO/Attributor.cpp

index c2e755ef29f90bf11c14219c5d16187cf211ba46..97c585ef9117a0febe7ffb06773bc13a8c1ae49e 100644 (file)
@@ -31,6 +31,7 @@
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Instruction.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/NoFolder.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/IR/Verifier.h"
@@ -1589,9 +1590,12 @@ ChangeStatus Attributor::cleanupIR() {
 
   for (auto &V : ToBeDeletedInsts) {
     if (Instruction *I = dyn_cast_or_null<Instruction>(V)) {
-      if (auto *CB = dyn_cast<CallBase>(I))
-        if (CB->isMustTailCall() && !isRunOn(*I->getFunction()))
+      if (auto *CB = dyn_cast<CallBase>(I)) {
+        if (!isRunOn(*I->getFunction()))
           continue;
+        if (!isa<IntrinsicInst>(CB))
+          CGUpdater.removeCallSite(*CB);
+      }
       I->dropDroppableUses();
       CGModifiedFunctions.insert(I->getFunction());
       if (!I->getType()->isVoidTy())