diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -2092,9 +2092,14 @@ Store->getPointerOperand(), Store->getValueOperand()->getType(), Store->getAlign(), MDL, Preheader->getTerminator(), DT, TLI); } - } else - return false; // Not a load or store. - + } else { + // Uses of null that are not loads or stores can be ignored. + if (const Constant *Const = dyn_cast(ASIV)) { + if (Const->isNullValue()) + continue; + } + return false; // Not a load or store and not null. + } if (!AccessTy) AccessTy = getLoadStoreType(UI); else if (AccessTy != getLoadStoreType(UI)) diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -3471,9 +3471,14 @@ if (const Instruction *Inst = dyn_cast(V)) { // Look for instructions defined outside the loop. if (L->contains(Inst)) continue; - } else if (isa(V)) + } else if (isa(V)) { // Undef doesn't have a live range, so it doesn't matter. continue; + } else if (const Constant *Const = dyn_cast(V)) { + // NULL values don't really have a live range. They are just NULL. + if (Const->isNullValue()) + continue; + } for (const Use &U : V->uses()) { const Instruction *UserInst = dyn_cast(U.getUser()); // Ignore non-instructions.