Skip to content

Commit

Permalink
[fix-irreducible] Skip unreachable predecessors.
Browse files Browse the repository at this point in the history
Summary:
- Skip unreachable predecessors during header detection in SCC. Those
  unreachable blocks would be generated in the switch lowering pass in
  the corner cases or other frontends. Even though they could be removed
  through the CFG simplification, we should skip them during header
  detection.

Reviewers: sameerds

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83562
  • Loading branch information
darkbuck committed Jul 11, 2020
1 parent 850b150 commit 0b4cf80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/Transforms/Utils/FixIrreducible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ static bool makeReducible(LoopInfo &LI, DominatorTree &DT, Graph &&G) {
LLVM_DEBUG(dbgs() << "Found headers:");
for (auto BB : reverse(Blocks)) {
for (const auto P : predecessors(BB)) {
// Skip unreachable predecessors.
if (!DT.isReachableFromEntry(P))
continue;
if (!Blocks.count(P)) {
LLVM_DEBUG(dbgs() << " " << BB->getName());
Headers.insert(BB);
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/Transforms/FixIrreducible/unreachable.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: opt %s -fix-irreducible -S -o - | FileCheck %s

; CHECK-LABEL: @unreachable(
; CHECK: entry:
; CHECK-NOT: irr.guard:
define void @unreachable(i32 %n) {
entry:
br label %loop.body

loop.body:
br label %inner.block

unreachable.block:
br label %inner.block

inner.block:
br i1 undef, label %loop.exit, label %loop.latch

loop.latch:
br label %loop.body

loop.exit:
ret void
}

0 comments on commit 0b4cf80

Please sign in to comment.