[llvm] 0b4cf80 - [fix-irreducible] Skip unreachable predecessors.

Michael Liao via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 11 07:09:56 PDT 2020


Author: Michael Liao
Date: 2020-07-11T10:08:44-04:00
New Revision: 0b4cf802fad4f504aefbeb70c061e60cff10d153

URL: https://github.com/llvm/llvm-project/commit/0b4cf802fad4f504aefbeb70c061e60cff10d153
DIFF: https://github.com/llvm/llvm-project/commit/0b4cf802fad4f504aefbeb70c061e60cff10d153.diff

LOG: [fix-irreducible] Skip unreachable predecessors.

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

Added: 
    llvm/test/Transforms/FixIrreducible/unreachable.ll

Modified: 
    llvm/lib/Transforms/Utils/FixIrreducible.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/FixIrreducible.cpp b/llvm/lib/Transforms/Utils/FixIrreducible.cpp
index 510c033f6474..452463c9b627 100644
--- a/llvm/lib/Transforms/Utils/FixIrreducible.cpp
+++ b/llvm/lib/Transforms/Utils/FixIrreducible.cpp
@@ -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);

diff  --git a/llvm/test/Transforms/FixIrreducible/unreachable.ll b/llvm/test/Transforms/FixIrreducible/unreachable.ll
new file mode 100644
index 000000000000..71cd81e01953
--- /dev/null
+++ b/llvm/test/Transforms/FixIrreducible/unreachable.ll
@@ -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
+}


        


More information about the llvm-commits mailing list