diff options
author | Xin Tong <trent.xin.tong@gmail.com> | 2017-01-27 01:42:20 +0000 |
---|---|---|
committer | Xin Tong <trent.xin.tong@gmail.com> | 2017-01-27 01:42:20 +0000 |
commit | e5f8d643d45ff188111fa5b310d9b9ba46abdb4e (patch) | |
tree | 777844af48d928abc334caa545877f980c06f97c /llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | |
parent | baabda9317d4a0f51805d41455da36d8c04de342 (diff) | |
download | bcm5719-llvm-e5f8d643d45ff188111fa5b310d9b9ba46abdb4e.tar.gz bcm5719-llvm-e5f8d643d45ff188111fa5b310d9b9ba46abdb4e.zip |
Constant fold switch inst when looking for trivial conditions to unswitch on.
Summary: Constant fold switch inst when looking for trivial conditions to unswitch on.
Reviewers: sanjoy, chenli, hfinkel, efriedma
Subscribers: llvm-commits, mzolotukhin
Differential Revision: https://reviews.llvm.org/D29037
llvm-svn: 293250
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopUnswitch.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index 76fe91884c7..d7daab4c666 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -899,7 +899,6 @@ bool LoopUnswitch::TryTrivialLoopUnswitch(bool &Changed) { if (I.mayHaveSideEffects()) return false; - // FIXME: add check for constant foldable switch instructions. if (BranchInst *BI = dyn_cast<BranchInst>(CurrentTerm)) { if (BI->isUnconditional()) { CurrentBB = BI->getSuccessor(0); @@ -911,7 +910,16 @@ bool LoopUnswitch::TryTrivialLoopUnswitch(bool &Changed) { // Found a trivial condition candidate: non-foldable conditional branch. break; } - } else { + } else if (SwitchInst *SI = dyn_cast<SwitchInst>(CurrentTerm)) { + // At this point, any constant-foldable instructions should have probably + // been folded. + ConstantInt *Cond = dyn_cast<ConstantInt>(SI->getCondition()); + if (!Cond) + break; + // Find the target block we are definitely going to. + CurrentBB = SI->findCaseValue(Cond).getCaseSuccessor(); + } else { + // We do not understand these terminator instructions. break; } |