From: Chris Lattner Date: Wed, 14 Apr 2004 03:28:36 +0000 (+0000) Subject: ADd a trivial instcombine: load null -> null X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=d9955aaa61adbcb7118d4d090d00a4c6a7bbadf1;p=oota-llvm.git ADd a trivial instcombine: load null -> null git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12940 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index af85c5fdde9..fe13a6ba540 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2853,8 +2853,11 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { Value *Op = LI.getOperand(0); if (LI.isVolatile()) return 0; - if (ConstantPointerRef *CPR = dyn_cast(Op)) - Op = CPR->getValue(); + if (Constant *C = dyn_cast(Op)) + if (C->isNullValue()) // load null -> 0 + return ReplaceInstUsesWith(LI, Constant::getNullValue(LI.getType())); + else if (ConstantPointerRef *CPR = dyn_cast(C)) + Op = CPR->getValue(); // Instcombine load (constant global) into the value loaded... if (GlobalVariable *GV = dyn_cast(Op))