Author: clamb Date: Sat Dec 29 01:56:53 2007 New Revision: 45403 URL: http://llvm.org/viewvc/llvm-project?rev=45403&view=rev Log: 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.
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=45403&r1=45402&r2=45403&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sat Dec 29 01:56:53 2007 @@ -9338,8 +9338,11 @@ 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 @@ 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. Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=45403&r1=45402&r2=45403&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original) +++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Sat Dec 29 01:56:53 2007 @@ -1015,7 +1015,9 @@ 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; _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits