[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
This commit is contained in:
Matt Morehouse 2021-10-29 10:37:34 -07:00
parent f5537643b8
commit 33cc0cfd46
3 changed files with 48 additions and 2 deletions

View File

@ -70,8 +70,8 @@ X86Subtarget::classifyLocalReference(const GlobalValue *GV) const {
// Tagged globals have non-zero upper bits, which makes direct references
// require a 64-bit immediate. On the small code model this causes relocation
// errors, so we go through the GOT instead.
if (AllowTaggedGlobals && TM.getCodeModel() == CodeModel::Small &&
!isa_and_nonnull<Function>(GV))
if (AllowTaggedGlobals && TM.getCodeModel() == CodeModel::Small && GV &&
!isa<Function>(GV))
return X86II::MO_GOTPCREL;
// If we're not PIC, it's not very interesting.

View File

@ -42,4 +42,27 @@ define void ()* @func_addr() #0 {
ret void ()* @func
}
; Jump tables shouldn't go through the GOT.
define i32 @jump_table(i32 %x) #0 {
; CHECK-LABEL: jump_table:
; CHECK-NOT: @GOT
switch i32 %x, label %default [
i32 0, label %1
i32 1, label %2
i32 2, label %3
i32 3, label %4
]
1:
ret i32 7
2:
ret i32 42
3:
ret i32 3
4:
ret i32 8
default:
ret i32 %x
}
attributes #0 = { "target-features"="+tagged-globals" }

View File

@ -42,4 +42,27 @@ define void ()* @func_addr() #0 {
ret void ()* @func
}
; Jump tables shouldn't go through the GOT.
define i32 @jump_table(i32 %x) #0 {
; CHECK-LABEL: jump_table:
; CHECK-NOT: @GOT
switch i32 %x, label %default [
i32 0, label %1
i32 1, label %2
i32 2, label %3
i32 3, label %4
]
1:
ret i32 7
2:
ret i32 42
3:
ret i32 3
4:
ret i32 8
default:
ret i32 %x
}
attributes #0 = { "target-features"="+tagged-globals" }