diff --git a/llvm/lib/Transforms/Utils/LCSSA.cpp b/llvm/lib/Transforms/Utils/LCSSA.cpp index 6de59f9eb5338c..020a40b229f77d 100644 --- a/llvm/lib/Transforms/Utils/LCSSA.cpp +++ b/llvm/lib/Transforms/Utils/LCSSA.cpp @@ -111,6 +111,10 @@ bool llvm::formLCSSAForInstructions(SmallVectorImpl &Worklist, Instruction *User = cast(U.getUser()); BasicBlock *UserBB = User->getParent(); + // Skip uses in unreachable blocks. + if (!DT.isReachableFromEntry(UserBB)) + 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.