summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-05-01 04:24:53 +0000
committerChris Lattner <sabre@nondot.org>2005-05-01 04:24:53 +0000
commita9d84e3388b3ecf29c5742a94777cc16b82be901 (patch)
treeb3c8c47eab8f836ad48960adcb8eea0aa0cb793b /llvm/lib/Transforms
parentda96eeb2d58e3d28865523daf74fc4fc88699499 (diff)
downloadbcm5719-llvm-a9d84e3388b3ecf29c5742a94777cc16b82be901.tar.gz
bcm5719-llvm-a9d84e3388b3ecf29c5742a94777cc16b82be901.zip
Check for volatile loads only once.
Implement load.ll:test7 llvm-svn: 21645
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp44
1 files changed, 35 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index c901b1a45e8..6b958f2c77f 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -4750,13 +4750,34 @@ static bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom) {
Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
Value *Op = LI.getOperand(0);
+ // load (cast X) --> cast (load X) iff safe
+ if (CastInst *CI = dyn_cast<CastInst>(Op))
+ if (Instruction *Res = InstCombineLoadCast(*this, LI))
+ return Res;
+
+ // None of the following transforms are legal for volatile loads.
+ if (LI.isVolatile()) return 0;
+
+ if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op))
+ if (isa<ConstantPointerNull>(GEPI->getOperand(0)) ||
+ isa<UndefValue>(GEPI->getOperand(0))) {
+ // Insert a new store to null instruction before the load to indicate
+ // that this code is not reachable. We do this instead of inserting
+ // an unreachable instruction directly because we cannot modify the
+ // CFG.
+ new StoreInst(UndefValue::get(LI.getType()),
+ Constant::getNullValue(Op->getType()), &LI);
+ return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
+ }
+
if (Constant *C = dyn_cast<Constant>(Op)) {
- if ((C->isNullValue() || isa<UndefValue>(C)) &&
- !LI.isVolatile()) { // load null/undef -> undef
+ // load null/undef -> undef
+ if ((C->isNullValue() || isa<UndefValue>(C))) {
// Insert a new store to null instruction before the load to indicate that
// this code is not reachable. We do this instead of inserting an
// unreachable instruction directly because we cannot modify the CFG.
- new StoreInst(UndefValue::get(LI.getType()), C, &LI);
+ new StoreInst(UndefValue::get(LI.getType()),
+ Constant::getNullValue(Op->getType()), &LI);
return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
}
@@ -4772,18 +4793,23 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
if (GV->isConstant() && !GV->isExternal())
if (Constant *V = GetGEPGlobalInitializer(GV->getInitializer(), CE))
return ReplaceInstUsesWith(LI, V);
+ if (CE->getOperand(0)->isNullValue()) {
+ // Insert a new store to null instruction before the load to indicate
+ // that this code is not reachable. We do this instead of inserting
+ // an unreachable instruction directly because we cannot modify the
+ // CFG.
+ new StoreInst(UndefValue::get(LI.getType()),
+ Constant::getNullValue(Op->getType()), &LI);
+ return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
+ }
+
} else if (CE->getOpcode() == Instruction::Cast) {
if (Instruction *Res = InstCombineLoadCast(*this, LI))
return Res;
}
}
- // load (cast X) --> cast (load X) iff safe
- if (CastInst *CI = dyn_cast<CastInst>(Op))
- if (Instruction *Res = InstCombineLoadCast(*this, LI))
- return Res;
-
- if (!LI.isVolatile() && Op->hasOneUse()) {
+ if (Op->hasOneUse()) {
// Change select and PHI nodes to select values instead of addresses: this
// helps alias analysis out a lot, allows many others simplifications, and
// exposes redundancy in the code.
OpenPOWER on IntegriCloud