1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 20:12:56 +02:00

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
This commit is contained in:
Christopher Lamb 2007-12-29 07:56:53 +00:00
parent 38687aa2b2
commit dfad5f19b4
2 changed files with 12 additions and 4 deletions

View File

@ -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.

View File

@ -1015,7 +1015,9 @@ void SCCPSolver::visitLoadInst(LoadInst &I) {
if (PtrVal.isUndefined()) return; // The pointer is not resolved yet!
if (PtrVal.isConstant() && !I.isVolatile()) {
Value *Ptr = PtrVal.getConstant();
if (isa<ConstantPointerNull>(Ptr)) {
// TODO: Consider a target hook for valid address spaces for this xform.
if (isa<ConstantPointerNull>(Ptr) &&
cast<PointerType>(Ptr->getType())->getAddressSpace() == 0) {
// load null -> null
markConstant(IV, &I, Constant::getNullValue(I.getType()));
return;