summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Bieneman <chris.bieneman@me.com>2018-01-09 21:58:46 +0000
committerChris Bieneman <chris.bieneman@me.com>2018-01-09 21:58:46 +0000
commitabdea268c1ff58f159e3aaa59fb7ccc56c316004 (patch)
tree6d6a43cda874ed7c54a059ec3b2ccaca7f13f1ce /llvm/lib
parent1712700842c03afcb9c3c758f95fa039f912ec02 (diff)
downloadbcm5719-llvm-abdea268c1ff58f159e3aaa59fb7ccc56c316004.tar.gz
bcm5719-llvm-abdea268c1ff58f159e3aaa59fb7ccc56c316004.zip
[IPSCCP] Remove calls without side effects
Summary: When performing constant propagation for call instructions we have historically replaced all uses of the return from a call, but not removed the call itself. This is required for correctness if the calls have side effects, however the compiler should be able to safely remove calls that don't have side effects. This allows the compiler to completely fold away calls to functions that have no side effects if the inputs are constant and the output can be determined at compile time. Reviewers: davide, sanjoy, bruno, dberlin Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38856 llvm-svn: 322125
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/Instruction.cpp5
-rw-r--r--llvm/lib/Transforms/Scalar/SCCP.cpp2
2 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 5f2a6146ad8..215c6907256 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -589,6 +589,11 @@ bool Instruction::mayThrow() const {
return isa<ResumeInst>(this);
}
+bool Instruction::isSafeToRemove() const {
+ return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
+ !isa<TerminatorInst>(this);
+}
+
bool Instruction::isAssociative() const {
unsigned Opcode = getOpcode();
if (isAssociative(Opcode))
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index df6053ac201..b6d034e9fb9 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -1900,7 +1900,7 @@ static bool runIPSCCP(Module &M, const DataLayout &DL,
if (Inst->getType()->isVoidTy())
continue;
if (tryToReplaceWithConstant(Solver, Inst)) {
- if (!isa<CallInst>(Inst) && !isa<TerminatorInst>(Inst))
+ if (Inst->isSafeToRemove())
Inst->eraseFromParent();
// Hey, we just changed something!
MadeChanges = true;
OpenPOWER on IntegriCloud