[PATCH] D83562: [fix-irreducible] Skip unreachable predecessors.
Michael Liao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 10 08:55:46 PDT 2020
hliao created this revision.
hliao added a reviewer: sameerds.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
- 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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D83562
Files:
llvm/lib/Transforms/Utils/FixIrreducible.cpp
llvm/test/Transforms/FixIrreducible/unreachable.ll
Index: llvm/test/Transforms/FixIrreducible/unreachable.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/lib/Transforms/Utils/FixIrreducible.cpp
===================================================================
--- llvm/lib/Transforms/Utils/FixIrreducible.cpp
+++ llvm/lib/Transforms/Utils/FixIrreducible.cpp
@@ -281,6 +281,9 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83562.277062.patch
Type: text/x-patch
Size: 1223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200710/d221ac77/attachment.bin>
More information about the llvm-commits
mailing list