diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-07-22 04:54:44 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-07-22 04:54:44 +0000 |
commit | 522a91181af75702f1526640d8fd356e22ea383a (patch) | |
tree | 40ee58b3e30ca6cdbdf69e8bd1881b4ec2a23afc /llvm/lib | |
parent | d382e9d82b086187601cf786d4143816e124eb9f (diff) | |
download | bcm5719-llvm-522a91181af75702f1526640d8fd356e22ea383a.tar.gz bcm5719-llvm-522a91181af75702f1526640d8fd356e22ea383a.zip |
Don't remove side effecting instructions due to ConstantFoldInstruction
Just because we can constant fold the result of an instruction does not
imply that we can delete the instruction. It may have side effects.
This fixes PR28655.
llvm-svn: 276389
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/ConstantProp.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/LICM.cpp | 6 |
5 files changed, 20 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 310c29275fa..99b12d4db0d 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -44,6 +44,7 @@ #include "llvm/Transforms/Utils/CtorUtils.h" #include "llvm/Transforms/Utils/Evaluator.h" #include "llvm/Transforms/Utils/GlobalStatus.h" +#include "llvm/Transforms/Utils/Local.h" #include <algorithm> using namespace llvm; @@ -779,7 +780,8 @@ static void ConstantPropUsersOf(Value *V, const DataLayout &DL, // Instructions could multiply use V. while (UI != E && *UI == I) ++UI; - I->eraseFromParent(); + if (isInstructionTriviallyDead(I, TLI)) + I->eraseFromParent(); } } diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 51c3262b5d1..377ccb9c37f 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2830,7 +2830,8 @@ bool InstCombiner::run() { // Add operands to the worklist. replaceInstUsesWith(*I, C); ++NumConstProp; - eraseInstFromFunction(*I); + if (isInstructionTriviallyDead(I, TLI)) + eraseInstFromFunction(*I); MadeIRChange = true; continue; } @@ -2851,7 +2852,8 @@ bool InstCombiner::run() { // Add operands to the worklist. replaceInstUsesWith(*I, C); ++NumConstProp; - eraseInstFromFunction(*I); + if (isInstructionTriviallyDead(I, TLI)) + eraseInstFromFunction(*I); MadeIRChange = true; continue; } @@ -3007,7 +3009,8 @@ static bool AddReachableCodeToWorklist(BasicBlock *BB, const DataLayout &DL, << *Inst << '\n'); Inst->replaceAllUsesWith(C); ++NumConstProp; - Inst->eraseFromParent(); + if (isInstructionTriviallyDead(Inst, TLI)) + Inst->eraseFromParent(); continue; } diff --git a/llvm/lib/Transforms/Scalar/ConstantProp.cpp b/llvm/lib/Transforms/Scalar/ConstantProp.cpp index 88172d19fe5..9e982194bac 100644 --- a/llvm/lib/Transforms/Scalar/ConstantProp.cpp +++ b/llvm/lib/Transforms/Scalar/ConstantProp.cpp @@ -19,6 +19,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Utils/Local.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/IR/Constant.h" @@ -90,11 +91,13 @@ bool ConstantPropagation::runOnFunction(Function &F) { // Remove the dead instruction. WorkList.erase(I); - I->eraseFromParent(); + if (isInstructionTriviallyDead(I, TLI)) { + I->eraseFromParent(); + ++NumInstKilled; + } // We made a change to the function... Changed = true; - ++NumInstKilled; } } return Changed; diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index b9e717cf763..d1769fc3ebb 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -758,7 +758,8 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) { ConstantFoldInstruction(I, BB->getModule()->getDataLayout(), TLI); if (SimpleVal) { I->replaceAllUsesWith(SimpleVal); - I->eraseFromParent(); + if (isInstructionTriviallyDead(I, TLI)) + I->eraseFromParent(); Condition = SimpleVal; } } diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index 2c0a70e44f5..cdd17fc516a 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -377,9 +377,11 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI, &I, I.getModule()->getDataLayout(), TLI)) { DEBUG(dbgs() << "LICM folding inst: " << I << " --> " << *C << '\n'); CurAST->copyValue(&I, C); - CurAST->deleteValue(&I); I.replaceAllUsesWith(C); - I.eraseFromParent(); + if (isInstructionTriviallyDead(&I, TLI)) { + CurAST->deleteValue(&I); + I.eraseFromParent(); + } continue; } |