blob: 808930885f282c2f6c7adef3f31e60753cd648d1 [file] [log] [blame]
Eric Christophered51b9e2012-05-10 21:48:22 +00001; Positive test for inline register constraints
2;
Petar Jovanovice578e972016-04-11 15:24:23 +00003; RUN: llc -no-integrated-as -march=mipsel -relocation-model=pic < %s | \
Daniel Sandersfbb6a232015-11-26 11:23:03 +00004; RUN: FileCheck -check-prefix=ALL -check-prefix=LE32 -check-prefix=GAS %s
Petar Jovanovice578e972016-04-11 15:24:23 +00005; RUN: llc -no-integrated-as -march=mips -relocation-model=pic < %s | \
Daniel Sandersfbb6a232015-11-26 11:23:03 +00006; RUN: FileCheck -check-prefix=ALL -check-prefix=BE32 -check-prefix=GAS %s
Eric Christophered51b9e2012-05-10 21:48:22 +00007
Daniel Sanderse160f832016-05-14 12:43:08 +00008; IAS might not print in the same way since it parses the assembly.
9; RUN: llc -march=mipsel -relocation-model=pic < %s | \
10; RUN: FileCheck -check-prefix=ALL -check-prefix=LE32 -check-prefix=IAS %s
11; RUN: llc -march=mips -relocation-model=pic < %s | \
12; RUN: FileCheck -check-prefix=ALL -check-prefix=BE32 -check-prefix=IAS %s
13
Jack Carterb2af5122012-07-05 23:58:21 +000014%union.u_tag = type { i64 }
15%struct.anon = type { i32, i32 }
16@uval = common global %union.u_tag zeroinitializer, align 8
Eric Christophered51b9e2012-05-10 21:48:22 +000017
18; X with -3
Jack Cartera62ba822012-07-18 06:41:36 +000019define i32 @constraint_X() nounwind {
20entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000021; ALL-LABEL: constraint_X:
22; ALL: #APP
23; GAS: addiu ${{[0-9]+}}, ${{[0-9]+}}, 0xfffffffffffffffd
Daniel Sanderse160f832016-05-14 12:43:08 +000024; IAS: addiu ${{[0-9]+}}, ${{[0-9]+}}, -3
Daniel Sandersfbb6a232015-11-26 11:23:03 +000025; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000026 tail call i32 asm sideeffect "addiu $0, $1, ${2:X}", "=r,r,I"(i32 7, i32 -3) ;
Eric Christophered51b9e2012-05-10 21:48:22 +000027 ret i32 0
28}
Jack Carterb2af5122012-07-05 23:58:21 +000029
Jack Cartera62ba822012-07-18 06:41:36 +000030; x with -3
31define i32 @constraint_x() nounwind {
32entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000033; ALL-LABEL: constraint_x:
34; ALL: #APP
35; GAS: addiu ${{[0-9]+}}, ${{[0-9]+}}, 0xfffd
Daniel Sanderse160f832016-05-14 12:43:08 +000036; This is _also_ -3 because uimm16 values are silently coerced to simm16 when
37; it would otherwise fail to match.
38; IAS: addiu ${{[0-9]+}}, ${{[0-9]+}}, -3
Daniel Sandersfbb6a232015-11-26 11:23:03 +000039; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000040 tail call i32 asm sideeffect "addiu $0, $1, ${2:x}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000041 ret i32 0
42}
43
44; d with -3
45define i32 @constraint_d() nounwind {
46entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000047; ALL-LABEL: constraint_d:
48; ALL: #APP
49; ALL: addiu ${{[0-9]+}}, ${{[0-9]+}}, -3
50; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000051 tail call i32 asm sideeffect "addiu $0, $1, ${2:d}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000052 ret i32 0
53}
54
55; m with -3
56define i32 @constraint_m() nounwind {
57entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000058; ALL-LABEL: constraint_m:
59; ALL: #APP
60; ALL: addiu ${{[0-9]+}}, ${{[0-9]+}}, -4
61; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000062 tail call i32 asm sideeffect "addiu $0, $1, ${2:m}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000063 ret i32 0
64}
65
66; z with -3
Daniel Sanderse160f832016-05-14 12:43:08 +000067define void @constraint_z_0() nounwind {
Jack Cartera62ba822012-07-18 06:41:36 +000068entry:
Daniel Sanderse160f832016-05-14 12:43:08 +000069; ALL-LABEL: constraint_z_0:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000070; ALL: #APP
71; ALL: addiu ${{[0-9]+}}, ${{[0-9]+}}, -3
72; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000073 tail call i32 asm sideeffect "addiu $0, $1, ${2:z}", "=r,r,I"(i32 7, i32 -3) ;
Daniel Sanderse160f832016-05-14 12:43:08 +000074 ret void
75}
Jack Cartera62ba822012-07-18 06:41:36 +000076
77; z with 0
Daniel Sanderse160f832016-05-14 12:43:08 +000078define void @constraint_z_1() nounwind {
79entry:
80; ALL-LABEL: constraint_z_1:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000081; ALL: #APP
Daniel Sanderse160f832016-05-14 12:43:08 +000082; GAS: addu ${{[0-9]+}}, ${{[0-9]+}}, $0
83; IAS: move ${{[0-9]+}}, ${{[0-9]+}}
Daniel Sandersfbb6a232015-11-26 11:23:03 +000084; ALL: #NO_APP
Daniel Sanderse160f832016-05-14 12:43:08 +000085 tail call i32 asm sideeffect "addu $0, $1, ${2:z}", "=r,r,I"(i32 7, i32 0) nounwind
86 ret void
87}
Toma Tabacu27cab752014-11-06 14:25:42 +000088
89; z with non-zero and the "r"(register) and "J"(integer zero) constraints
Daniel Sanderse160f832016-05-14 12:43:08 +000090define void @constraint_z_2() nounwind {
91entry:
92; ALL-LABEL: constraint_z_2:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000093; ALL: #APP
94; ALL: mtc0 ${{[1-9][0-9]?}}, ${{[0-9]+}}
95; ALL: #NO_APP
Toma Tabacu27cab752014-11-06 14:25:42 +000096 call void asm sideeffect "mtc0 ${0:z}, $$12", "Jr"(i32 7) nounwind
Daniel Sanderse160f832016-05-14 12:43:08 +000097 ret void
98}
Toma Tabacu27cab752014-11-06 14:25:42 +000099
100; z with zero and the "r"(register) and "J"(integer zero) constraints
Daniel Sanderse160f832016-05-14 12:43:08 +0000101define void @constraint_z_3() nounwind {
102entry:
103; ALL-LABEL: constraint_z_3:
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000104; ALL: #APP
Daniel Sanderse160f832016-05-14 12:43:08 +0000105; GAS: mtc0 $0, ${{[0-9]+}}
106; IAS: mtc0 $zero, ${{[0-9]+}}, 0
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000107; ALL: #NO_APP
Toma Tabacu27cab752014-11-06 14:25:42 +0000108 call void asm sideeffect "mtc0 ${0:z}, $$12", "Jr"(i32 0) nounwind
Daniel Sanderse160f832016-05-14 12:43:08 +0000109 ret void
110}
Toma Tabacu27cab752014-11-06 14:25:42 +0000111
112; z with non-zero and just the "r"(register) constraint
Daniel Sanderse160f832016-05-14 12:43:08 +0000113define void @constraint_z_4() nounwind {
114entry:
115; ALL-LABEL: constraint_z_4:
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000116; ALL: #APP
117; ALL: mtc0 ${{[1-9][0-9]?}}, ${{[0-9]+}}
118; ALL: #NO_APP
Toma Tabacu27cab752014-11-06 14:25:42 +0000119 call void asm sideeffect "mtc0 ${0:z}, $$12", "r"(i32 7) nounwind
Daniel Sanderse160f832016-05-14 12:43:08 +0000120 ret void
121}
Toma Tabacu27cab752014-11-06 14:25:42 +0000122
123; z with zero and just the "r"(register) constraint
Daniel Sanderse160f832016-05-14 12:43:08 +0000124define void @constraint_z_5() nounwind {
125entry:
126; ALL-LABEL: constraint_z_5:
Toma Tabacu27cab752014-11-06 14:25:42 +0000127; FIXME: Check for $0, instead of other registers.
128; We should be using $0 directly in this case, not real registers.
129; When the materialization of 0 gets fixed, this test will fail.
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000130; ALL: #APP
131; ALL: mtc0 ${{[1-9][0-9]?}}, ${{[0-9]+}}
132; ALL: #NO_APP
Toma Tabacu27cab752014-11-06 14:25:42 +0000133 call void asm sideeffect "mtc0 ${0:z}, $$12", "r"(i32 0) nounwind
Daniel Sanderse160f832016-05-14 12:43:08 +0000134 ret void
Jack Cartera62ba822012-07-18 06:41:36 +0000135}
136
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000137; A long long in 32 bit mode (use to assert)
Jack Cartera62ba822012-07-18 06:41:36 +0000138define i32 @constraint_longlong() nounwind {
139entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000140; ALL-LABEL: constraint_longlong:
141; ALL: #APP
142; ALL: addiu ${{[0-9]+}}, ${{[0-9]+}}, 3
143; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +0000144 tail call i64 asm sideeffect "addiu $0, $1, $2 \0A\09", "=r,r,X"(i64 1229801703532086340, i64 3) nounwind
Jack Cartera62ba822012-07-18 06:41:36 +0000145 ret i32 0
146}
147
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000148; In little endian the source reg will be 4 bytes into the long long
149; In big endian the source reg will also be 4 bytes into the long long
Jack Cartera62ba822012-07-18 06:41:36 +0000150define i32 @constraint_D() nounwind {
151entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000152; ALL-LABEL: constraint_D:
153; ALL: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
154; ALL: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
155; ALL: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
156; ALL: #APP
157; LE32: or ${{[0-9]+}}, $[[SECOND]], ${{[0-9]+}}
158; BE32: or ${{[0-9]+}}, $[[SECOND]], ${{[0-9]+}}
159; ALL: #NO_APP
David Blaikief72d05b2015-03-13 18:20:45 +0000160 %bosco = load i64, i64* getelementptr inbounds (%union.u_tag, %union.u_tag* @uval, i32 0, i32 0), align 8
Jack Cartera62ba822012-07-18 06:41:36 +0000161 %trunc1 = trunc i64 %bosco to i32
Daniel Sanders00a4aac2015-11-16 14:14:59 +0000162 tail call i32 asm sideeffect "or $0, ${1:D}, $2", "=r,r,r"(i64 %bosco, i32 %trunc1) nounwind
Jack Cartera62ba822012-07-18 06:41:36 +0000163 ret i32 0
164}
165
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000166; In little endian the source reg will be 0 bytes into the long long
167; In big endian the source reg will be 4 bytes into the long long
Jack Cartera62ba822012-07-18 06:41:36 +0000168define i32 @constraint_L() nounwind {
169entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000170; ALL-LABEL: constraint_L:
171; ALL: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
172; ALL: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
173; ALL: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
174; ALL: #APP
175; LE32: or ${{[0-9]+}}, $[[FIRST]], ${{[0-9]+}}
176; BE32: or ${{[0-9]+}}, $[[SECOND]], ${{[0-9]+}}
177; ALL: #NO_APP
David Blaikief72d05b2015-03-13 18:20:45 +0000178 %bosco = load i64, i64* getelementptr inbounds (%union.u_tag, %union.u_tag* @uval, i32 0, i32 0), align 8
Jack Cartera62ba822012-07-18 06:41:36 +0000179 %trunc1 = trunc i64 %bosco to i32
Daniel Sanders00a4aac2015-11-16 14:14:59 +0000180 tail call i32 asm sideeffect "or $0, ${1:L}, $2", "=r,r,r"(i64 %bosco, i32 %trunc1) nounwind
Jack Cartera62ba822012-07-18 06:41:36 +0000181 ret i32 0
182}
183
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000184; In little endian the source reg will be 4 bytes into the long long
185; In big endian the source reg will be 0 bytes into the long long
Jack Cartera62ba822012-07-18 06:41:36 +0000186define i32 @constraint_M() nounwind {
187entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000188; ALL-LABEL: constraint_M:
189; ALL: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
190; ALL: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
191; ALL: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
192; ALL: #APP
193; LE32: or ${{[0-9]+}}, $[[SECOND]], ${{[0-9]+}}
194; BE32: or ${{[0-9]+}}, $[[FIRST]], ${{[0-9]+}}
195; ALL: #NO_APP
David Blaikief72d05b2015-03-13 18:20:45 +0000196 %bosco = load i64, i64* getelementptr inbounds (%union.u_tag, %union.u_tag* @uval, i32 0, i32 0), align 8
Jack Cartera62ba822012-07-18 06:41:36 +0000197 %trunc1 = trunc i64 %bosco to i32
Daniel Sanders00a4aac2015-11-16 14:14:59 +0000198 tail call i32 asm sideeffect "or $0, ${1:M}, $2", "=r,r,r"(i64 %bosco, i32 %trunc1) nounwind
Jack Cartera62ba822012-07-18 06:41:36 +0000199 ret i32 0
200}