Skip to content

Commit 4f8259b

Browse files
committed
[Thumb] Fix invalid symbol redefinition due to duplicated jumptable (PR42760)
Fix for https://bugs.llvm.org/show_bug.cgi?id=42760. A tBR_JTr instruction is duplicated by tail duplication, which results in the same jumptable with the same label being emitted twice. Fix this by marking tBR_JTr as not duplicable. The corresponding ARM/Thumb instructions are already marked as not duplicable. Additionally also mark tTBB_JT and tTBH_JT to be consistent with Thumb2, even though this shouldn't be strictly necessary. Differential Revision: https://reviews.llvm.org/D65606 llvm-svn: 367753
1 parent a67d81e commit 4f8259b

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

llvm/lib/Target/ARM/ARMInstrThumb.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
592592
[(ARMbrjt tGPR:$target, tjumptable:$jt)]>,
593593
Sched<[WriteBrTbl]> {
594594
let Size = 2;
595+
let isNotDuplicable = 1;
595596
list<Predicate> Predicates = [IsThumb, IsThumb1Only];
596597
}
597598
}
@@ -1471,7 +1472,7 @@ def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
14711472
// Thumb-1 doesn't have the TBB or TBH instructions, but we can synthesize them
14721473
// and make use of the same compressed jump table format as Thumb-2.
14731474
let Size = 2, isBranch = 1, isTerminator = 1, isBarrier = 1,
1474-
isIndirectBranch = 1 in {
1475+
isIndirectBranch = 1, isNotDuplicable = 1 in {
14751476
def tTBB_JT : tPseudoInst<(outs),
14761477
(ins tGPRwithpc:$base, tGPR:$index, i32imm:$jt, i32imm:$pclbl), 0,
14771478
IIC_Br, []>, Sched<[WriteBr]>;

llvm/test/CodeGen/Thumb/pr42760.ll

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=thumbv6m-none-unknown-eabi -tail-dup-placement-threshold=3 < %s | FileCheck %s
3+
4+
define hidden void @test() {
5+
; CHECK-LABEL: test:
6+
; CHECK: @ %bb.0: @ %entry
7+
; CHECK-NEXT: movs r0, #1
8+
; CHECK-NEXT: lsls r1, r0, #2
9+
; CHECK-NEXT: b .LBB0_2
10+
; CHECK-NEXT: .LBB0_1: @ %bb2
11+
; CHECK-NEXT: @ in Loop: Header=BB0_2 Depth=1
12+
; CHECK-NEXT: cmp r0, #0
13+
; CHECK-NEXT: bne .LBB0_6
14+
; CHECK-NEXT: .LBB0_2: @ %switch
15+
; CHECK-NEXT: @ =>This Inner Loop Header: Depth=1
16+
; CHECK-NEXT: adr r2, .LJTI0_0
17+
; CHECK-NEXT: ldr r2, [r2, r1]
18+
; CHECK-NEXT: mov pc, r2
19+
; CHECK-NEXT: @ %bb.3:
20+
; CHECK-NEXT: .p2align 2
21+
; CHECK-NEXT: .LJTI0_0:
22+
; CHECK-NEXT: .long .LBB0_6+1
23+
; CHECK-NEXT: .long .LBB0_4+1
24+
; CHECK-NEXT: .long .LBB0_6+1
25+
; CHECK-NEXT: .long .LBB0_5+1
26+
; CHECK-NEXT: .LBB0_4: @ %switch
27+
; CHECK-NEXT: @ in Loop: Header=BB0_2 Depth=1
28+
; CHECK-NEXT: b .LBB0_1
29+
; CHECK-NEXT: .LBB0_5: @ %bb
30+
; CHECK-NEXT: @ in Loop: Header=BB0_2 Depth=1
31+
; CHECK-NEXT: cmp r0, #0
32+
; CHECK-NEXT: beq .LBB0_1
33+
; CHECK-NEXT: .LBB0_6: @ %dead
34+
entry:
35+
br label %switch
36+
37+
switch: ; preds = %bb2, %entry
38+
switch i32 undef, label %dead2 [
39+
i32 0, label %dead
40+
i32 1, label %bb2
41+
i32 2, label %dead
42+
i32 3, label %bb
43+
]
44+
45+
dead: ; preds = %bb2, %bb, %switch, %switch
46+
unreachable
47+
48+
dead2: ; preds = %switch
49+
unreachable
50+
51+
bb: ; preds = %switch
52+
br i1 undef, label %dead, label %bb2
53+
54+
bb2: ; preds = %bb, %switch
55+
br i1 undef, label %dead, label %switch
56+
}

0 commit comments

Comments
 (0)