ADd a trivial instcombine: load null -> null
authorChris Lattner <sabre@nondot.org>
Wed, 14 Apr 2004 03:28:36 +0000 (03:28 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 14 Apr 2004 03:28:36 +0000 (03:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12940 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index af85c5fdde9f36cd9e5078fdc46a2e9262965634..fe13a6ba54018850e6cb03b82c38aa810159bf81 100644 (file)
@@ -2853,8 +2853,11 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
   Value *Op = LI.getOperand(0);
   if (LI.isVolatile()) return 0;
 
-  if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Op))
-    Op = CPR->getValue();
+  if (Constant *C = dyn_cast<Constant>(Op))
+    if (C->isNullValue())  // load null -> 0
+      return ReplaceInstUsesWith(LI, Constant::getNullValue(LI.getType()));
+    else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C))
+      Op = CPR->getValue();
 
   // Instcombine load (constant global) into the value loaded...
   if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Op))