From e3b557809604d036af6e00c60f012c2025b59a5e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 11 Feb 2023 13:38:04 +0100 Subject: Vendor import of llvm-project main llvmorg-16-init-18548-gb0daacf58f41, the last commit before the upstream release/17.x branch was created. --- llvm/lib/Transforms/Utils/LCSSA.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Transforms/Utils/LCSSA.cpp') diff --git a/llvm/lib/Transforms/Utils/LCSSA.cpp b/llvm/lib/Transforms/Utils/LCSSA.cpp index 84d377d835f3..af79dc456ea6 100644 --- a/llvm/lib/Transforms/Utils/LCSSA.cpp +++ b/llvm/lib/Transforms/Utils/LCSSA.cpp @@ -107,10 +107,16 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl &Worklist, if (ExitBlocks.empty()) continue; - for (Use &U : I->uses()) { + for (Use &U : make_early_inc_range(I->uses())) { Instruction *User = cast(U.getUser()); BasicBlock *UserBB = User->getParent(); + // Skip uses in unreachable blocks. + if (!DT.isReachableFromEntry(UserBB)) { + U.set(PoisonValue::get(I->getType())); + continue; + } + // For practical purposes, we consider that the use in a PHI // occurs in the respective predecessor block. For more info, // see the `phi` doc in LangRef and the LCSSA doc. @@ -235,7 +241,7 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl &Worklist, llvm::findDbgValues(DbgValues, I); // Update pre-existing debug value uses that reside outside the loop. - for (auto DVI : DbgValues) { + for (auto *DVI : DbgValues) { BasicBlock *UserBB = DVI->getParent(); if (InstBB == UserBB || L->contains(UserBB)) continue; @@ -417,7 +423,7 @@ bool llvm::formLCSSARecursively(Loop &L, const DominatorTree &DT, static bool formLCSSAOnAllLoops(const LoopInfo *LI, const DominatorTree &DT, ScalarEvolution *SE) { bool Changed = false; - for (auto &L : *LI) + for (const auto &L : *LI) Changed |= formLCSSARecursively(*L, DT, LI, SE); return Changed; } -- cgit v1.2.3