Index: llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp +++ 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. Index: llvm/test/Transforms/LoopInstSimplify/pr55072.ll =================================================================== --- llvm/test/Transforms/LoopInstSimplify/pr55072.ll +++ llvm/test/Transforms/LoopInstSimplify/pr55072.ll @@ -1,14 +1,35 @@ +; 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 - target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2" target triple = "x86_64-unknown-linux-gnu" define i32 @test_01() { -; CHECK-LABEL: test_01 +; CHECK-LABEL: @test_01( +; CHECK-NEXT: bb: +; CHECK-NEXT: br label [[BB1:%.*]] +; CHECK: bb1: +; CHECK-NEXT: br label [[BB3:%.*]] +; CHECK: bb2: +; CHECK-NEXT: br label [[BB2:%.*]] +; CHECK: bb3: +; CHECK-NEXT: switch i32 undef, label [[BB8:%.*]] [ +; CHECK-NEXT: i32 0, label [[BB4:%.*]] +; CHECK-NEXT: i32 1, label [[BB6:%.*]] +; CHECK-NEXT: i32 2, label [[BB5:%.*]] +; CHECK-NEXT: ] +; CHECK: bb4: +; CHECK-NEXT: br label [[BB6]] +; CHECK: bb5: +; CHECK-NEXT: br label [[BB8]] +; CHECK: bb6: +; CHECK-NEXT: br label [[BB8]] +; CHECK: bb7: +; CHECK-NEXT: ret i32 0 +; CHECK: bb8: +; CHECK-NEXT: br label [[BB3]] +; bb: br label %bb1 @@ -20,9 +41,9 @@ bb3: ; preds = %bb8, %bb1 switch i32 undef, label %bb8 [ - i32 0, label %bb4 - i32 1, label %bb6 - i32 2, label %bb5 + i32 0, label %bb4 + i32 1, label %bb6 + i32 2, label %bb5 ] bb4: ; preds = %bb3