Index: lib/Analysis/MemorySSA.cpp =================================================================== --- lib/Analysis/MemorySSA.cpp +++ lib/Analysis/MemorySSA.cpp @@ -332,6 +332,7 @@ // The MemoryAccess we actually got called with, used to test local domination const MemoryAccess *OriginalAccess = nullptr; Optional AR = MayAlias; + bool SkipSelfAccess = false; UpwardsMemoryQuery() = default; @@ -619,9 +620,19 @@ if (!VisitedPhis.insert({Node.Last, Node.Loc}).second) continue; - UpwardsWalkResult Res = walkToPhiOrClobber(Node, /*StopAt=*/StopWhere); + const MemoryAccess *RealStopWhere = StopWhere; + bool ReplacedStopWhere = false; + if (Query->SkipSelfAccess && Query->OriginalAccess && + Node.Loc == Query->StartingLoc && + Node.Last->getBlock() == Query->OriginalAccess->getBlock()) { + assert(isa(Query->OriginalAccess)); + RealStopWhere = Query->OriginalAccess; + ReplacedStopWhere = true; + } + + UpwardsWalkResult Res = walkToPhiOrClobber(Node, /*StopAt=*/RealStopWhere); if (Res.IsKnownClobber) { - assert(Res.Result != StopWhere); + assert(Res.Result != RealStopWhere); // If this wasn't a cache hit, we hit a clobber when walking. That's a // failure. TerminatedPath Term{Res.Result, PathIndex}; @@ -633,10 +644,11 @@ continue; } - if (Res.Result == StopWhere) { + if (Res.Result == RealStopWhere) { // We've hit our target. Save this path off for if we want to continue // walking. - NewPaused.push_back(PathIndex); + if (!ReplacedStopWhere) + NewPaused.push_back(PathIndex); continue; }