summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/ConstantProp.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-07-22 04:54:44 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-07-22 04:54:44 +0000
commit522a91181af75702f1526640d8fd356e22ea383a (patch)
tree40ee58b3e30ca6cdbdf69e8bd1881b4ec2a23afc /llvm/lib/Transforms/Scalar/ConstantProp.cpp
parentd382e9d82b086187601cf786d4143816e124eb9f (diff)
downloadbcm5719-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/Transforms/Scalar/ConstantProp.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/ConstantProp.cpp7
1 files changed, 5 insertions, 2 deletions
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;
OpenPOWER on IntegriCloud