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 @@ -1302,13 +1302,11 @@ MemoryAccess *Current = StartAccess; Instruction *KillingI = KillingDef->getMemoryInst(); - bool StepAgain; LLVM_DEBUG(dbgs() << " trying to get dominating access\n"); // Find the next clobbering Mod access for DefLoc, starting at StartAccess. Optional CurrentLoc; - do { - StepAgain = false; + for (;; Current = cast(Current)->getDefiningAccess()) { LLVM_DEBUG({ dbgs() << " visiting " << *Current; if (!MSSA.isLiveOnEntryDef(Current) && isa(Current)) @@ -1347,8 +1345,6 @@ Instruction *CurrentI = CurrentDef->getMemoryInst(); if (canSkipDef(CurrentDef, !isInvisibleToCallerBeforeRet(DefUO))) { - StepAgain = true; - Current = CurrentDef->getDefiningAccess(); continue; } @@ -1387,16 +1383,12 @@ // If Current cannot be analyzed or is not removable, check the next // candidate. if (!hasAnalyzableMemoryWrite(CurrentI, TLI) || !isRemovable(CurrentI)) { - StepAgain = true; - Current = CurrentDef->getDefiningAccess(); continue; } // If Current does not have an analyzable write location, skip it CurrentLoc = getLocForWriteEx(CurrentI); if (!CurrentLoc) { - StepAgain = true; - Current = CurrentDef->getDefiningAccess(); continue; } @@ -1405,8 +1397,6 @@ // memory location and not multiple locations in a loop. if (Current->getBlock() != KillingDef->getBlock() && !IsGuaranteedLoopInvariant(const_cast(CurrentLoc->Ptr))) { - StepAgain = true; - Current = CurrentDef->getDefiningAccess(); WalkerStepLimit -= 1; continue; } @@ -1416,10 +1406,9 @@ // the next candidate if the current Current does not write the same // underlying object as the terminator. if (!isMemTerminator(*CurrentLoc, CurrentI, KillingI)) { - StepAgain = true; - Current = CurrentDef->getDefiningAccess(); + continue; } - continue; + break; } else { int64_t InstWriteOffset, DepWriteOffset; auto OR = isOverwrite(KillingI, CurrentI, DefLoc, *CurrentLoc, DL, TLI, @@ -1427,23 +1416,23 @@ // If Current does not write to the same object as KillingDef, check // the next candidate. if (OR == OW_Unknown) { - StepAgain = true; - Current = CurrentDef->getDefiningAccess(); + continue; } else if (OR == OW_MaybePartial) { // If KillingDef only partially overwrites Current, check the next // candidate if the partial step limit is exceeded. This aggressively // limits the number of candidates for partial store elimination, // which are less likely to be removable in the end. if (PartialLimit <= 1) { - StepAgain = true; - Current = CurrentDef->getDefiningAccess(); WalkerStepLimit -= 1; continue; } PartialLimit -= 1; + break; + } else { + break; } } - } while (StepAgain); + }; // Accesses to objects accessible after the function returns can only be // eliminated if the access is killed along all paths to the exit. Collect