diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -327,6 +327,7 @@ OW_End, OW_PartialEarlierWithFullLater, OW_MaybePartial, + OW_None, OW_Unknown }; @@ -941,11 +942,13 @@ /// Return OW_MaybePartial if \p Later does not completely overwrite /// \p Earlier, but they both write to the same underlying object. In that /// case, use isPartialOverwrite to check if \p Later partially overwrites - /// \p Earlier. Returns 'OW_Unknown' if nothing can be determined. - OverwriteResult - isOverwrite(const Instruction *LaterI, const Instruction *EarlierI, - const MemoryLocation &Later, const MemoryLocation &Earlier, - int64_t &EarlierOff, int64_t &LaterOff) { + /// \p Earlier. Returns 'OR_None' if later is known to not overwrite the + /// earlier. 'OW_Unknown' if nothing can be determined. + OverwriteResult isOverwrite(const Instruction *LaterI, + const Instruction *EarlierI, + const MemoryLocation &Later, + const MemoryLocation &Earlier, + int64_t &EarlierOff, int64_t &LaterOff) { // AliasAnalysis does not always account for loops. Limit overwrite checks // to dependencies for which we can guarantee they are independant of any // loops they are in. @@ -1053,9 +1056,8 @@ return OW_MaybePartial; } - // Can reach here only if accesses are known not to overlap. There is no - // dedicated code to indicate no overlap so signal "unknown". - return OW_Unknown; + // Can reach here only if accesses are known not to overlap. + return OW_None; } bool isInvisibleToCallerAfterRet(const Value *V) { @@ -1450,12 +1452,13 @@ if (!isMemTerminator(*CurrentLoc, CurrentI, KillingI)) continue; } else { - int64_t InstWriteOffset, DepWriteOffset; + int64_t InstWriteOffset = 0; + int64_t DepWriteOffset = 0; auto OR = isOverwrite(KillingI, CurrentI, DefLoc, *CurrentLoc, DepWriteOffset, InstWriteOffset); // If Current does not write to the same object as KillingDef, check // the next candidate. - if (OR == OW_Unknown) + if (OR == OW_Unknown || OR == OW_None) continue; else if (OR == OW_MaybePartial) { // If KillingDef only partially overwrites Current, check the next @@ -1464,6 +1467,7 @@ // which are less likely to be removable in the end. if (PartialLimit <= 1) { WalkerStepLimit -= 1; + LLVM_DEBUG(dbgs() << " ... reached partial limit ... continue with next access\n"); continue; } PartialLimit -= 1;