summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/SCCP.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/IPO/SCCP.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/SCCP.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/IPO/SCCP.cpp b/llvm/lib/Transforms/IPO/SCCP.cpp
index d50de34dfa48..2ecadd529170 100644
--- a/llvm/lib/Transforms/IPO/SCCP.cpp
+++ b/llvm/lib/Transforms/IPO/SCCP.cpp
@@ -169,6 +169,13 @@ static bool runIPSCCP(
for (Function &F : M) {
if (F.isDeclaration())
continue;
+ // Skip the dead functions marked by FunctionSpecializer, avoiding removing
+ // blocks in dead functions. Set MadeChanges if there is any dead function
+ // that will be removed later.
+ if (IsFuncSpecEnabled && Specializer.isDeadFunction(&F)) {
+ MadeChanges = true;
+ continue;
+ }
SmallVector<BasicBlock *, 512> BlocksToErase;
@@ -326,12 +333,15 @@ static bool runIPSCCP(
LLVM_DEBUG(dbgs() << "Found that GV '" << GV->getName()
<< "' is constant!\n");
for (User *U : make_early_inc_range(GV->users())) {
- // We can remove LoadInst here, because we already replaced its users
- // with a constant.
+ // We can remove LoadInst here. The LoadInsts in dead functions marked by
+ // FuncSpec are not simplified to constants, thus poison them.
assert((isa<StoreInst>(U) || isa<LoadInst>(U)) &&
"Only Store|Load Instruction can be user of GlobalVariable at "
"reaching here.");
- cast<Instruction>(U)->eraseFromParent();
+ Instruction *I = cast<Instruction>(U);
+ if (isa<LoadInst>(I))
+ I->replaceAllUsesWith(PoisonValue::get(I->getType()));
+ I->eraseFromParent();
}
// Try to create a debug constant expression for the global variable