Index: llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp =================================================================== --- llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -2549,10 +2549,11 @@ } if (auto *SI = dyn_cast(BB->getTerminator())) { + const bool HasAtLeastTwoSuccessors = BB->getUniqueSuccessor() == nullptr; // We can only consider fully loop-invariant switch conditions as we need // to completely eliminate the switch after unswitching. if (!isa(SI->getCondition()) && - L.isLoopInvariant(SI->getCondition())) + L.isLoopInvariant(SI->getCondition()) && HasAtLeastTwoSuccessors) UnswitchCandidates.push_back({SI, {SI->getCondition()}}); continue; } Index: llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-redundant-switch.ll =================================================================== --- llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-redundant-switch.ll +++ llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-redundant-switch.ll @@ -1,5 +1,4 @@ ; REQUIRES: asserts -; XFAIL: * ; RUN: opt -passes='unswitch' -disable-output -S < %s ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -disable-output -S < %s