diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-07-13 17:19:57 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-07-13 17:19:57 +0000 |
commit | 9112829d76cbb8e0c8ef51bbc2d7d1be48cd7b74 (patch) | |
tree | 9de1c5f67a98cd0e73c60838396486c984f63ac2 /lib/VMCore/Instruction.cpp | |
parent | 1e3dec662ea18131c495db50caccc57f77b7a5fe (diff) | |
download | FreeBSD-src-9112829d76cbb8e0c8ef51bbc2d7d1be48cd7b74.zip FreeBSD-src-9112829d76cbb8e0c8ef51bbc2d7d1be48cd7b74.tar.gz |
Update LLVM to r108243.
Diffstat (limited to 'lib/VMCore/Instruction.cpp')
-rw-r--r-- | lib/VMCore/Instruction.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index a37fe07..9792ada 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -286,9 +286,10 @@ bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const { for (const_use_iterator UI = use_begin(), E = use_end(); UI != E; ++UI) { // PHI nodes uses values in the corresponding predecessor block. For other // instructions, just check to see whether the parent of the use matches up. - const PHINode *PN = dyn_cast<PHINode>(*UI); + const User *U = *UI; + const PHINode *PN = dyn_cast<PHINode>(U); if (PN == 0) { - if (cast<Instruction>(*UI)->getParent() != BB) + if (cast<Instruction>(U)->getParent() != BB) return true; continue; } @@ -401,12 +402,20 @@ bool Instruction::isSafeToSpeculativelyExecute() const { return false; // Note that it is not safe to speculate into a malloc'd region because // malloc may return null. - if (isa<AllocaInst>(getOperand(0))) + // It's also not safe to follow a bitcast, for example: + // bitcast i8* (alloca i8) to i32* + // would result in a 4-byte load from a 1-byte alloca. + Value *Op0 = getOperand(0); + if (GEPOperator *GEP = dyn_cast<GEPOperator>(Op0)) { + // TODO: it's safe to do this for any GEP with constant indices that + // compute inside the allocated type, but not for any inbounds gep. + if (GEP->hasAllZeroIndices()) + Op0 = GEP->getPointerOperand(); + } + if (isa<AllocaInst>(Op0)) return true; if (GlobalVariable *GV = dyn_cast<GlobalVariable>(getOperand(0))) return !GV->hasExternalWeakLinkage(); - // FIXME: Handle cases involving GEPs. We have to be careful because - // a load of a out-of-bounds GEP has undefined behavior. return false; } case Call: @@ -421,6 +430,7 @@ bool Instruction::isSafeToSpeculativelyExecute() const { case Store: case Ret: case Br: + case IndirectBr: case Switch: case Unwind: case Unreachable: |