diff --git a/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp b/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp --- a/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp @@ -104,6 +104,10 @@ auto *UserI = cast(U.getUser()); U.set(V); + // Do not bother dealing with unreachable code. + if (!DT.isReachableFromEntry(UserI->getParent())) + continue; + // If the instruction is used by a PHI node we have already processed // we'll need to iterate on the loop body to converge, so add it to // the next set. diff --git a/llvm/test/Transforms/LoopInstSimplify/pr55072.ll b/llvm/test/Transforms/LoopInstSimplify/pr55072.ll --- a/llvm/test/Transforms/LoopInstSimplify/pr55072.ll +++ b/llvm/test/Transforms/LoopInstSimplify/pr55072.ll @@ -1,11 +1,16 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S %s -passes=loop-instsimplify | FileCheck %s ; RUN: opt -S %s -passes='loop-mssa(loop-instsimplify)' -verify-memoryssa | FileCheck %s -; XFAIL: * -; REQUIRES: asserts - define i32 @test_01() { -; CHECK-LABEL: test_01 +; CHECK-LABEL: @test_01( +; CHECK-NEXT: bb: +; CHECK-NEXT: br label [[LOOP:%.*]] +; CHECK: loop: +; CHECK-NEXT: br label [[LOOP]] +; CHECK: unreached: +; CHECK-NEXT: ret i32 0 +; bb: br label %loop