Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / named_reg_global.c
blobeab98797feb17374354dd1b164f4c4c64ecea4a3
1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X86-64
2 // RUN: %clang_cc1 -triple arm64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM
3 // RUN: %clang_cc1 -triple armv7-linux-gnu -target-abi apcs-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM
5 // CHECK-NOT: @sp = common global
7 #if defined(__x86_64__)
8 register unsigned long current_stack_pointer asm("rsp");
9 #else
10 register unsigned long current_stack_pointer asm("sp");
11 #endif
13 struct p4_Thread {
14 struct {
15 int len;
16 } word;
18 // Testing pointer types as well
19 #if defined(__x86_64__)
20 register struct p4_Thread *p4TH asm("rsp");
21 #else
22 register struct p4_Thread *p4TH asm("sp");
23 #endif
25 // CHECK: define{{.*}} i[[bits:[0-9]+]] @get_stack_pointer_addr()
26 // CHECK: [[ret:%[0-9]+]] = call i[[bits]] @llvm.read_register.i[[bits]](metadata !0)
27 // CHECK: ret i[[bits]] [[ret]]
28 unsigned long get_stack_pointer_addr(void) {
29 return current_stack_pointer;
31 // CHECK: declare{{.*}} i[[bits]] @llvm.read_register.i[[bits]](metadata)
33 // CHECK: define{{.*}} void @set_stack_pointer_addr(i[[bits]] noundef %addr) #0 {
34 // CHECK: [[sto:%[0-9]+]] = load i[[bits]], ptr %
35 // CHECK: call void @llvm.write_register.i[[bits]](metadata !0, i[[bits]] [[sto]])
36 // CHECK: ret void
37 void set_stack_pointer_addr(unsigned long addr) {
38 current_stack_pointer = addr;
40 // CHECK: declare{{.*}} void @llvm.write_register.i[[bits]](metadata, i[[bits]])
42 // CHECK: define {{.*}}@fn1
43 int fn1(void) {
44 return (*p4TH).word.len;
46 // CHECK: %[[regr:[0-9]+]] = call i[[bits]] @llvm.read_register.i[[bits]](metadata !0)
47 // CHECK: inttoptr i[[bits]] %[[regr]] to ptr
49 // CHECK: define {{.*}}@fn2
50 void fn2(struct p4_Thread *val) {
51 p4TH = val;
53 // CHECK: %[[regw:[0-9]+]] = ptrtoint ptr %{{.*}} to i[[bits]]
54 // CHECK: call void @llvm.write_register.i[[bits]](metadata !0, i[[bits]] %[[regw]])
56 // CHECK-X86-64: !llvm.named.register.rsp = !{!0}
57 // CHECK-X86-64: !0 = !{!"rsp"}
58 // CHECK-ARM: !llvm.named.register.sp = !{!0}
59 // CHECK-ARM: !0 = !{!"sp"}