[PATCH] D79609: [GlobalISel] Don't add duplicate successors to MBBs when translating indirectbr
Jessica Paquette via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 8 13:58:46 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf66309deab1d: [GlobalISel] Don't add duplicate successors to MBBs when translating indirectbr (authored by paquette).
Changed prior to commit:
https://reviews.llvm.org/D79609?vs=262892&id=262948#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79609/new/
https://reviews.llvm.org/D79609
Files:
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-indirect-br-repeated-block.ll
Index: llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-indirect-br-repeated-block.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-indirect-br-repeated-block.ll
@@ -0,0 +1,26 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+; RUN: llc -O0 -mtriple=aarch64-apple-ios -global-isel -stop-after=irtranslator -verify-machineinstrs %s -o - | FileCheck %s
+;
+; Make sure that we don't duplicate successors/predecessors when translating
+; indirectbr instructions with duplicate block labels.
+
+define void @foo() {
+ ; CHECK-LABEL: name: foo
+ ; CHECK: bb.1 (%ir-block.0):
+ ; CHECK: successors: %bb.2(0x2aaaaaaa), %bb.4(0x2aaaaaaa), %bb.3(0x2aaaaaaa)
+ ; CHECK: [[DEF:%[0-9]+]]:_(p0) = G_IMPLICIT_DEF
+ ; CHECK: G_BRINDIRECT [[DEF]](p0)
+ ; CHECK: bb.2 (%ir-block.1):
+ ; CHECK: successors:
+ ; CHECK: bb.3 (%ir-block.2):
+ ; CHECK: successors:
+ ; CHECK: bb.4 (%ir-block.3):
+ ; CHECK: RET_ReallyLR
+ indirectbr i8* undef, [label %1, label %3, label %2, label %3, label %3]
+1:
+ unreachable
+2:
+ unreachable
+3:
+ ret void
+}
Index: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -838,9 +838,16 @@
MIRBuilder.buildBrIndirect(Tgt);
// Link successors.
+ SmallPtrSet<const BasicBlock *, 32> AddedSuccessors;
MachineBasicBlock &CurBB = MIRBuilder.getMBB();
- for (const BasicBlock *Succ : successors(&BrInst))
+ for (const BasicBlock *Succ : successors(&BrInst)) {
+ // It's legal for indirectbr instructions to have duplicate blocks in the
+ // destination list. We don't allow this in MIR. Skip anything that's
+ // already a successor.
+ if (!AddedSuccessors.insert(Succ).second)
+ continue;
CurBB.addSuccessor(&getMBB(*Succ));
+ }
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79609.262948.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200508/1463daa2/attachment.bin>
More information about the llvm-commits
mailing list