Since 'load null' is undefined, we can make it do whatever we want. Returning
authorChris Lattner <sabre@nondot.org>
Sun, 7 Mar 2004 22:16:24 +0000 (22:16 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 7 Mar 2004 22:16:24 +0000 (22:16 +0000)
a zero value is the most likely way to cause further simplification, so we do it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12197 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/SCCP.cpp

index 8304e2e823bf2fe448b3d0b57f5e90e08e218a6b..56cb2cc77018003822106e1c08aba7f1f20b1520 100644 (file)
@@ -713,6 +713,12 @@ void SCCP::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)) {
+      // load null -> null
+      markConstant(IV, &I, Constant::getNullValue(I.getType()));
+      return;
+    }
+      
     if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Ptr))
       Ptr = CPR->getValue();