xref: /llvm-project/llvm/test/CodeGen/X86/thread_pointer.ll (revision 2f448bf509432c1a19ec46ab8cbc7353c03c6280)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck %s --check-prefix=X64
3; RUN: llc < %s -mtriple=x86_64-linux-gnux32 | FileCheck %s --check-prefix=X32
4; RUN: llc < %s -mtriple=i386-linux-gnu | FileCheck %s --check-prefix=X86
5
6declare ptr @llvm.thread.pointer()
7
8define ptr @thread_pointer() nounwind {
9; X64-LABEL: thread_pointer:
10; X64:       # %bb.0:
11; X64-NEXT:    movq %fs:0, %rax
12; X64-NEXT:    retq
13;
14; X32-LABEL: thread_pointer:
15; X32:       # %bb.0:
16; X32-NEXT:    movl %fs:0, %eax
17; X32-NEXT:    retq
18;
19; X86-LABEL: thread_pointer:
20; X86:       # %bb.0:
21; X86-NEXT:    movl %gs:0, %eax
22; X86-NEXT:    retl
23  %1 = tail call ptr @llvm.thread.pointer()
24  ret ptr %1
25}
26
27define i32 @thread_pointer2(i32 %i) nounwind {
28; X64-LABEL: thread_pointer2:
29; X64:       # %bb.0: # %entry
30; X64-NEXT:    movslq %edi, %rax
31; X64-NEXT:    movl %fs:(,%rax,4), %eax
32; X64-NEXT:    retq
33;
34; X32-LABEL: thread_pointer2:
35; X32:       # %bb.0: # %entry
36; X32-NEXT:    movl %fs:0, %eax
37; X32-NEXT:    movl (%eax,%edi,4), %eax
38; X32-NEXT:    retq
39;
40; X86-LABEL: thread_pointer2:
41; X86:       # %bb.0: # %entry
42; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
43; X86-NEXT:    movl %gs:(,%eax,4), %eax
44; X86-NEXT:    retl
45entry:
46  %0 = tail call ptr @llvm.thread.pointer()
47  %arrayidx = getelementptr inbounds i32, ptr %0, i32 %i
48  %1 = load i32, ptr %arrayidx, align 4
49  ret i32 %1
50}
51