aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-07-17 04:28:42 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-07-17 04:28:42 +0000
commit0b79a7727d68a507837e827803859424cf3d997b (patch)
tree660f0ded255f727b4f60161a752eec3bad39b6e4 /lib/Transforms
parent6055a6adb792f857fe04d8880a6cfb8914828046 (diff)
downloadexternal_llvm-0b79a7727d68a507837e827803859424cf3d997b.zip
external_llvm-0b79a7727d68a507837e827803859424cf3d997b.tar.gz
external_llvm-0b79a7727d68a507837e827803859424cf3d997b.tar.bz2
Replace isTrapping with a new, similar method called
isSafeToSpeculativelyExecute. The new method is a bit closer to what the callers actually care about in that it rejects more things callers don't want. It also adds more precise handling for integer division, and unifies code for analyzing the legality of a speculative load. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76150 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/LICM.cpp9
-rw-r--r--lib/Transforms/Scalar/TailDuplication.cpp3
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp23
3 files changed, 10 insertions, 25 deletions
diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp
index 52dd06a..bdf7dee 100644
--- a/lib/Transforms/Scalar/LICM.cpp
+++ b/lib/Transforms/Scalar/LICM.cpp
@@ -623,7 +623,8 @@ void LICM::hoist(Instruction &I) {
///
bool LICM::isSafeToExecuteUnconditionally(Instruction &Inst) {
// If it is not a trapping instruction, it is always safe to hoist.
- if (!Inst.isTrapping()) return true;
+ if (Inst.isSafeToSpeculativelyExecute())
+ return true;
// Otherwise we have to check to make sure that the instruction dominates all
// of the exit blocks. If it doesn't, then there is a path out of the loop
@@ -635,12 +636,6 @@ bool LICM::isSafeToExecuteUnconditionally(Instruction &Inst) {
if (Inst.getParent() == CurLoop->getHeader())
return true;
- // It's always safe to load from a global or alloca.
- if (isa<LoadInst>(Inst))
- if (isa<AllocationInst>(Inst.getOperand(0)) ||
- isa<GlobalVariable>(Inst.getOperand(0)))
- return true;
-
// Get the exit blocks for the current loop.
SmallVector<BasicBlock*, 8> ExitBlocks;
CurLoop->getExitBlocks(ExitBlocks);
diff --git a/lib/Transforms/Scalar/TailDuplication.cpp b/lib/Transforms/Scalar/TailDuplication.cpp
index 684b0963..6d05fdf 100644
--- a/lib/Transforms/Scalar/TailDuplication.cpp
+++ b/lib/Transforms/Scalar/TailDuplication.cpp
@@ -258,7 +258,8 @@ void TailDup::eliminateUnconditionalBranch(BranchInst *Branch) {
while (!isa<TerminatorInst>(BBI)) {
Instruction *I = BBI++;
- bool CanHoist = !I->isTrapping() && !I->mayHaveSideEffects();
+ bool CanHoist = I->isSafeToSpeculativelyExecute() &&
+ !I->mayReadFromMemory();
if (CanHoist) {
for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op)
if (Instruction *OpI = dyn_cast<Instruction>(I->getOperand(op)))
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 55e1bf2..3b6b77f 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -384,26 +384,15 @@ static bool DominatesMergePoint(Value *V, BasicBlock *BB,
// Okay, it looks like the instruction IS in the "condition". Check to
// see if its a cheap instruction to unconditionally compute, and if it
// only uses stuff defined outside of the condition. If so, hoist it out.
+ if (!I->isSafeToSpeculativelyExecute())
+ return false;
+
switch (I->getOpcode()) {
default: return false; // Cannot hoist this out safely.
case Instruction::Load: {
- // We can hoist loads that are non-volatile and obviously cannot trap.
- if (cast<LoadInst>(I)->isVolatile())
- return false;
- // FIXME: A computation of a constant can trap!
- if (!isa<AllocaInst>(I->getOperand(0)) &&
- !isa<Constant>(I->getOperand(0)))
- return false;
- // External weak globals may have address 0, so we can't load them.
- Value *V2 = I->getOperand(0)->getUnderlyingObject();
- if (V2) {
- GlobalVariable* GV = dyn_cast<GlobalVariable>(V2);
- if (GV && GV->hasExternalWeakLinkage())
- return false;
- }
- // Finally, we have to check to make sure there are no instructions
- // before the load in its basic block, as we are going to hoist the loop
- // out to its predecessor.
+ // We have to check to make sure there are no instructions before the
+ // load in its basic block, as we are going to hoist the loop out to
+ // its predecessor.
BasicBlock::iterator IP = PBB->begin();
while (isa<DbgInfoIntrinsic>(IP))
IP++;