diff options
| author | Christopher Lamb <christopher.lamb@gmail.com> | 2007-12-29 07:56:53 +0000 |
|---|---|---|
| committer | Christopher Lamb <christopher.lamb@gmail.com> | 2007-12-29 07:56:53 +0000 |
| commit | b053b80b79731c0da674522d428a6687412b217d (patch) | |
| tree | bee291019355307a8cc098facdb6342e8d9726f8 /llvm/lib/Transforms/Scalar/InstructionCombining.cpp | |
| parent | 2de9b852979be1123919c7c5d11a4b962fae6495 (diff) | |
| download | bcm5719-llvm-b053b80b79731c0da674522d428a6687412b217d.tar.gz bcm5719-llvm-b053b80b79731c0da674522d428a6687412b217d.zip | |
Disable null pointer folding transforms for non-generic address spaces. This should probably be a target-specific predicate based on address space. That way for targets where this isn't applicable the predicate can be optimized away.
llvm-svn: 45403
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index de528d956ab..6502bb38fe2 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -9338,8 +9338,11 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { return ReplaceInstUsesWith(LI, LIB); } - if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op)) - if (isa<ConstantPointerNull>(GEPI->getOperand(0))) { + if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op)) { + const Value *GEPI0 = GEPI->getOperand(0); + // TODO: Consider a target hook for valid address spaces for this xform. + if (isa<ConstantPointerNull>(GEPI0) && + cast<PointerType>(GEPI0->getType())->getAddressSpace() == 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 @@ -9348,10 +9351,13 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { Constant::getNullValue(Op->getType()), &LI); return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType())); } + } if (Constant *C = dyn_cast<Constant>(Op)) { // load null/undef -> undef - if ((C->isNullValue() || isa<UndefValue>(C))) { + // TODO: Consider a target hook for valid address spaces for this xform. + if (isa<UndefValue>(C) || (C->isNullValue() && + cast<PointerType>(Op->getType())->getAddressSpace() == 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. |

