[SimpleLoopUnswitch] Don't consider unswitching `switch` insructions with one unique...
authorSerguei Katkov <serguei.katkov@azul.com>
Wed, 10 Jul 2019 10:25:22 +0000 (10:25 +0000)
committerSerguei Katkov <serguei.katkov@azul.com>
Wed, 10 Jul 2019 10:25:22 +0000 (10:25 +0000)
Only instructions with two or more unique successors should be considered for unswitching.

Patch Author: Daniil Suchkov.

Reviewers: reames, asbirlea, skatkov
Reviewed By: skatkov
Subscribers: hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D64404

llvm-svn: 365611

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-redundant-switch.ll

index 82e98ec..9715329 100644 (file)
@@ -2552,7 +2552,7 @@ unswitchBestCondition(Loop &L, DominatorTree &DT, LoopInfo &LI,
       // We can only consider fully loop-invariant switch conditions as we need
       // to completely eliminate the switch after unswitching.
       if (!isa<Constant>(SI->getCondition()) &&
-          L.isLoopInvariant(SI->getCondition()))
+          L.isLoopInvariant(SI->getCondition()) && !BB->getUniqueSuccessor())
         UnswitchCandidates.push_back({SI, {SI->getCondition()}});
       continue;
     }
index 3624f5b..8f743ca 100644 (file)
@@ -1,5 +1,4 @@
 ; REQUIRES: asserts
-; XFAIL: *
 ; RUN: opt -passes='unswitch<nontrivial>' -disable-output -S < %s
 ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -disable-output -S < %s