diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -822,6 +822,12 @@ return false; } +static bool isLifetimeEnd(const Instruction *Inst) { + if (const IntrinsicInst *II = dyn_cast(Inst)) + return II->getIntrinsicID() == Intrinsic::lifetime_end; + return false; +} + /// Try to locate the three instruction involved in a missed /// load-elimination case that is due to an intervening store. static void reportMayClobberedLoad(LoadInst *LI, MemDepResult DepInfo, @@ -864,6 +870,15 @@ const DataLayout &DL = LI->getModule()->getDataLayout(); Instruction *DepInst = DepInfo.getInst(); + + // Loading the allocation -> undef. + if (isa(DepInst) || isMallocLikeFn(DepInst, TLI) || + // Loading immediately after lifetime begin or end -> undef. + isLifetimeStart(DepInst) || isLifetimeEnd(DepInst)) { + Res = AvailableValue::get(UndefValue::get(LI->getType())); + return true; + } + if (DepInfo.isClobber()) { // If the dependence is to a store that writes to a superset of the bits // read by the load, we can extract the bits we need for the load from the @@ -923,14 +938,6 @@ } assert(DepInfo.isDef() && "follows from above"); - // Loading the allocation -> undef. - if (isa(DepInst) || isMallocLikeFn(DepInst, TLI) || - // Loading immediately after lifetime begin -> undef. - isLifetimeStart(DepInst)) { - Res = AvailableValue::get(UndefValue::get(LI->getType())); - return true; - } - // Loading from calloc (which zero initializes memory) -> zero if (isCallocLikeFn(DepInst, TLI)) { Res = AvailableValue::get(Constant::getNullValue(LI->getType()));