[PATCH] D64404: [SimpleLoopUnswitch] Don't consider unswitching `switch` insructions with one unique successor
Daniil Suchkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 9 04:56:40 PDT 2019
DaniilSuchkov created this revision.
DaniilSuchkov added reviewers: asbirlea, reames.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
DaniilSuchkov added a parent revision: D64403: [SimpleLoopUnswitch] Add a test case exposing a bug.
Currently SimpleLoopUnswitch considers unswitching any `switch` instructions, in case if the instruction has only one unique successor it causes crash on `assert(SuccessorsCount > 1 && "Cannot unswitch a condition without multiple distinct successors!")`.
https://reviews.llvm.org/D64404
Files:
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-redundant-switch.ll
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<nontrivial>' -disable-output -S < %s
; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -disable-output -S < %s
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<SwitchInst>(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<Constant>(SI->getCondition()) &&
- L.isLoopInvariant(SI->getCondition()))
+ L.isLoopInvariant(SI->getCondition()) && HasAtLeastTwoSuccessors)
UnswitchCandidates.push_back({SI, {SI->getCondition()}});
continue;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64404.208644.patch
Type: text/x-patch
Size: 1355 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190709/79add8ca/attachment.bin>
More information about the llvm-commits
mailing list