Disable null pointer folding transforms for non-generic address spaces. This should...
authorChristopher Lamb <christopher.lamb@gmail.com>
Sat, 29 Dec 2007 07:56:53 +0000 (07:56 +0000)
committerChristopher Lamb <christopher.lamb@gmail.com>
Sat, 29 Dec 2007 07:56:53 +0000 (07:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45403 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
lib/Transforms/Scalar/SCCP.cpp

index de528d956abe927dd66deee7d59087a7b9571464..6502bb38fe2b1a203030466f4002f45d68ee506c 100644 (file)
@@ -9338,8 +9338,11 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
         return ReplaceInstUsesWith(LI, LIB);
   }
 
         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
       // 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()));
     }
                     Constant::getNullValue(Op->getType()), &LI);
       return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
     }
+  } 
 
   if (Constant *C = dyn_cast<Constant>(Op)) {
     // load null/undef -> undef
 
   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.
       // 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.
index d236039332e83d0d2c11cd1d8089a4c992294554..3a607cbd5f6de031543fa0065140820d49334dd9 100644 (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 (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;
       // load null -> null
       markConstant(IV, &I, Constant::getNullValue(I.getType()));
       return;