Skip to content

Commit 33cc0cf

Browse files
author
Matt Morehouse
committed
[X86] Don't affect jump tables under +tagged-globals.
`classifyLocalReference(nullptr)` is called to get the appropriate relocation type for jump tables. We should not use @GOTPCREL for this case. The new test cases trigger assertions without this patch. Reviewed By: eugenis Differential Revision: https://reviews.llvm.org/D112832
1 parent f553764 commit 33cc0cf

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎llvm/lib/Target/X86/X86Subtarget.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ X86Subtarget::classifyLocalReference(const GlobalValue *GV) const {
7070
// Tagged globals have non-zero upper bits, which makes direct references
7171
// require a 64-bit immediate. On the small code model this causes relocation
7272
// errors, so we go through the GOT instead.
73-
if (AllowTaggedGlobals && TM.getCodeModel() == CodeModel::Small &&
74-
!isa_and_nonnull<Function>(GV))
73+
if (AllowTaggedGlobals && TM.getCodeModel() == CodeModel::Small && GV &&
74+
!isa<Function>(GV))
7575
return X86II::MO_GOTPCREL;
7676

7777
// If we're not PIC, it's not very interesting.

‎llvm/test/CodeGen/X86/tagged-globals-pic.ll‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,27 @@ define void ()* @func_addr() #0 {
4242
ret void ()* @func
4343
}
4444

45+
; Jump tables shouldn't go through the GOT.
46+
define i32 @jump_table(i32 %x) #0 {
47+
; CHECK-LABEL: jump_table:
48+
; CHECK-NOT: @GOT
49+
50+
switch i32 %x, label %default [
51+
i32 0, label %1
52+
i32 1, label %2
53+
i32 2, label %3
54+
i32 3, label %4
55+
]
56+
1:
57+
ret i32 7
58+
2:
59+
ret i32 42
60+
3:
61+
ret i32 3
62+
4:
63+
ret i32 8
64+
default:
65+
ret i32 %x
66+
}
67+
4568
attributes #0 = { "target-features"="+tagged-globals" }

‎llvm/test/CodeGen/X86/tagged-globals-static.ll‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,27 @@ define void ()* @func_addr() #0 {
4242
ret void ()* @func
4343
}
4444

45+
; Jump tables shouldn't go through the GOT.
46+
define i32 @jump_table(i32 %x) #0 {
47+
; CHECK-LABEL: jump_table:
48+
; CHECK-NOT: @GOT
49+
50+
switch i32 %x, label %default [
51+
i32 0, label %1
52+
i32 1, label %2
53+
i32 2, label %3
54+
i32 3, label %4
55+
]
56+
1:
57+
ret i32 7
58+
2:
59+
ret i32 42
60+
3:
61+
ret i32 3
62+
4:
63+
ret i32 8
64+
default:
65+
ret i32 %x
66+
}
67+
4568
attributes #0 = { "target-features"="+tagged-globals" }

0 commit comments

Comments
 (0)