xref: /llvm-project/clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c (revision 0bbf3ddf5fea86e0eb0726142827e175aadaf53b)
1 // RUN: %clang_cc1 -triple loongarch32 -emit-llvm -O2 %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -triple loongarch64 -emit-llvm -O2 %s -o - | FileCheck %s
3 
4 /// Check GCC register names and alias can be used in register variable definition.
5 
6 // CHECK-LABEL: @test_r0
7 // CHECK: call void asm sideeffect "", "{$r0}"(i32 undef)
test_r0()8 void test_r0() {
9     register int a asm ("$r0");
10     register int b asm ("r0");
11     asm ("" :: "r" (a));
12     asm ("" :: "r" (b));
13 }
14 
15 // CHECK-LABEL: @test_r12
16 // CHECK: call void asm sideeffect "", "{$r12}"(i32 undef)
test_r12()17 void test_r12() {
18     register int a asm ("$r12");
19     register int b asm ("r12");
20     asm ("" :: "r" (a));
21     asm ("" :: "r" (b));
22 }
23 
24 // CHECK-LABEL: @test_r31
25 // CHECK: call void asm sideeffect "", "{$r31}"(i32 undef)
test_r31()26 void test_r31() {
27     register int a asm ("$r31");
28     register int b asm ("r31");
29     asm ("" :: "r" (a));
30     asm ("" :: "r" (b));
31 }
32 
33 // CHECK-LABEL: @test_zero
34 // CHECK: call void asm sideeffect "", "{$r0}"(i32 undef)
test_zero()35 void test_zero() {
36     register int a asm ("$zero");
37     register int b asm ("zero");
38     asm ("" :: "r" (a));
39     asm ("" :: "r" (b));
40 }
41 
42 // CHECK-LABEL: @test_a0
43 // CHECK: call void asm sideeffect "", "{$r4}"(i32 undef)
test_a0()44 void test_a0() {
45     register int a asm ("$a0");
46     register int b asm ("a0");
47     asm ("" :: "r" (a));
48     asm ("" :: "r" (b));
49 }
50 
51 // CHECK-LABEL: @test_t1
52 // CHECK: call void asm sideeffect "", "{$r13}"(i32 undef)
test_t1()53 void test_t1() {
54     register int a asm ("$t1");
55     register int b asm ("t1");
56     asm ("" :: "r" (a));
57     asm ("" :: "r" (b));
58 }
59 
60 // CHECK-LABEL: @test_fp
61 // CHECK: call void asm sideeffect "", "{$r22}"(i32 undef)
test_fp()62 void test_fp() {
63     register int a asm ("$fp");
64     register int b asm ("fp");
65     asm ("" :: "r" (a));
66     asm ("" :: "r" (b));
67 }
68 
69 // CHECK-LABEL: @test_s2
70 // CHECK: call void asm sideeffect "", "{$r25}"(i32 undef)
test_s2()71 void test_s2() {
72     register int a asm ("$s2");
73     register int b asm ("s2");
74     asm ("" :: "r" (a));
75     asm ("" :: "r" (b));
76 }
77 
78 // CHECK-LABEL: @test_f0
79 // CHECK: call void asm sideeffect "", "{$f0}"(float undef)
test_f0()80 void test_f0() {
81     register float a asm ("$f0");
82     asm ("" :: "f" (a));
83 }
84 
85 // CHECK-LABEL: @test_f14
86 // CHECK: call void asm sideeffect "", "{$f14}"(float undef)
test_f14()87 void test_f14() {
88     register float a asm ("$f14");
89     asm ("" :: "f" (a));
90 }
91 
92 // CHECK-LABEL: @test_f31
93 // CHECK: call void asm sideeffect "", "{$f31}"(float undef)
test_f31()94 void test_f31() {
95     register float a asm ("$f31");
96     asm ("" :: "f" (a));
97 }
98 
99 // CHECK-LABEL: @test_fa0
100 // CHECK: call void asm sideeffect "", "{$f0}"(float undef)
test_fa0()101 void test_fa0() {
102     register float a asm ("$fa0");
103     asm ("" :: "f" (a));
104 }
105 
106 // CHECK-LABEL: @test_ft1
107 // CHECK: call void asm sideeffect "", "{$f9}"(float undef)
test_ft1()108 void test_ft1() {
109     register float a asm ("$ft1");
110     asm ("" :: "f" (a));
111 }
112 
113 // CHECK-LABEL: @test_fs2
114 // CHECK: call void asm sideeffect "", "{$f26}"(float undef)
test_fs2()115 void test_fs2() {
116     register float a asm ("$fs2");
117     asm ("" :: "f" (a));
118 }
119 
120 // CHECK-LABEL: @test_fcc
121 // CHECK: call void asm sideeffect "", "~{$fcc0}"()
122 // CHECK: call void asm sideeffect "", "~{$fcc7}"()
test_fcc()123 void test_fcc() {
124     asm ("" ::: "$fcc0");
125     asm ("" ::: "$fcc7");
126 }
127