blob: fd726fc689cef605e376fbfbd2adfa7f7d553434 [file] [log] [blame]
Eric Christophered51b9e2012-05-10 21:48:22 +00001; Positive test for inline register constraints
2;
Jack Cartera62ba822012-07-18 06:41:36 +00003; RUN: llc -march=mipsel < %s | FileCheck -check-prefix=CHECK_LITTLE_32 %s
4; RUN: llc -march=mips < %s | FileCheck -check-prefix=CHECK_BIG_32 %s
Eric Christophered51b9e2012-05-10 21:48:22 +00005
Jack Carterb2af5122012-07-05 23:58:21 +00006%union.u_tag = type { i64 }
7%struct.anon = type { i32, i32 }
8@uval = common global %union.u_tag zeroinitializer, align 8
Eric Christophered51b9e2012-05-10 21:48:22 +00009
10; X with -3
Jack Cartera62ba822012-07-18 06:41:36 +000011define i32 @constraint_X() nounwind {
12entry:
Stephen Lind24ab202013-07-14 06:24:09 +000013;CHECK_LITTLE_32-LABEL: constraint_X:
Jack Cartera62ba822012-07-18 06:41:36 +000014;CHECK_LITTLE_32: #APP
Daniel Sandersb2305952014-05-22 11:46:58 +000015;CHECK_LITTLE_32: addiu ${{[0-9]+}},${{[0-9]+}},0xfffffffffffffffd
Jack Cartera62ba822012-07-18 06:41:36 +000016;CHECK_LITTLE_32: #NO_APP
Daniel Sandersb2305952014-05-22 11:46:58 +000017 tail call i32 asm sideeffect "addiu $0,$1,${2:X}", "=r,r,I"(i32 7, i32 -3) ;
Eric Christophered51b9e2012-05-10 21:48:22 +000018 ret i32 0
19}
Jack Carterb2af5122012-07-05 23:58:21 +000020
Jack Cartera62ba822012-07-18 06:41:36 +000021; x with -3
22define i32 @constraint_x() nounwind {
23entry:
Stephen Lind24ab202013-07-14 06:24:09 +000024;CHECK_LITTLE_32-LABEL: constraint_x:
Jack Cartera62ba822012-07-18 06:41:36 +000025;CHECK_LITTLE_32: #APP
Daniel Sandersb2305952014-05-22 11:46:58 +000026;CHECK_LITTLE_32: addiu ${{[0-9]+}},${{[0-9]+}},0xfffd
Jack Cartera62ba822012-07-18 06:41:36 +000027;CHECK_LITTLE_32: #NO_APP
Daniel Sandersb2305952014-05-22 11:46:58 +000028 tail call i32 asm sideeffect "addiu $0,$1,${2:x}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000029 ret i32 0
30}
31
32; d with -3
33define i32 @constraint_d() nounwind {
34entry:
Stephen Lind24ab202013-07-14 06:24:09 +000035;CHECK_LITTLE_32-LABEL: constraint_d:
Jack Cartera62ba822012-07-18 06:41:36 +000036;CHECK_LITTLE_32: #APP
Daniel Sandersb2305952014-05-22 11:46:58 +000037;CHECK_LITTLE_32: addiu ${{[0-9]+}},${{[0-9]+}},-3
Jack Cartera62ba822012-07-18 06:41:36 +000038;CHECK_LITTLE_32: #NO_APP
Daniel Sandersb2305952014-05-22 11:46:58 +000039 tail call i32 asm sideeffect "addiu $0,$1,${2:d}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000040 ret i32 0
41}
42
43; m with -3
44define i32 @constraint_m() nounwind {
45entry:
Stephen Lind24ab202013-07-14 06:24:09 +000046;CHECK_LITTLE_32-LABEL: constraint_m:
Jack Cartera62ba822012-07-18 06:41:36 +000047;CHECK_LITTLE_32: #APP
Daniel Sandersb2305952014-05-22 11:46:58 +000048;CHECK_LITTLE_32: addiu ${{[0-9]+}},${{[0-9]+}},-4
Jack Cartera62ba822012-07-18 06:41:36 +000049;CHECK_LITTLE_32: #NO_APP
Daniel Sandersb2305952014-05-22 11:46:58 +000050 tail call i32 asm sideeffect "addiu $0,$1,${2:m}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000051 ret i32 0
52}
53
54; z with -3
55define i32 @constraint_z() nounwind {
56entry:
Stephen Lind24ab202013-07-14 06:24:09 +000057;CHECK_LITTLE_32-LABEL: constraint_z:
Jack Cartera62ba822012-07-18 06:41:36 +000058;CHECK_LITTLE_32: #APP
Daniel Sandersb2305952014-05-22 11:46:58 +000059;CHECK_LITTLE_32: addiu ${{[0-9]+}},${{[0-9]+}},-3
Jack Cartera62ba822012-07-18 06:41:36 +000060;CHECK_LITTLE_32: #NO_APP
Daniel Sandersb2305952014-05-22 11:46:58 +000061 tail call i32 asm sideeffect "addiu $0,$1,${2:z}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000062
63; z with 0
64;CHECK_LITTLE_32: #APP
Daniel Sandersb2305952014-05-22 11:46:58 +000065;CHECK_LITTLE_32: addiu ${{[0-9]+}},${{[0-9]+}},$0
Jack Cartera62ba822012-07-18 06:41:36 +000066;CHECK_LITTLE_32: #NO_APP
Daniel Sandersb2305952014-05-22 11:46:58 +000067 tail call i32 asm sideeffect "addiu $0,$1,${2:z}", "=r,r,I"(i32 7, i32 0) nounwind
Toma Tabacu27cab752014-11-06 14:25:42 +000068
69; z with non-zero and the "r"(register) and "J"(integer zero) constraints
70;CHECK_LITTLE_32: #APP
71;CHECK_LITTLE_32: mtc0 ${{[1-9][0-9]?}}, ${{[0-9]+}}
72;CHECK_LITTLE_32: #NO_APP
73 call void asm sideeffect "mtc0 ${0:z}, $$12", "Jr"(i32 7) nounwind
74
75; z with zero and the "r"(register) and "J"(integer zero) constraints
76;CHECK_LITTLE_32: #APP
77;CHECK_LITTLE_32: mtc0 $0, ${{[0-9]+}}
78;CHECK_LITTLE_32: #NO_APP
79 call void asm sideeffect "mtc0 ${0:z}, $$12", "Jr"(i32 0) nounwind
80
81; z with non-zero and just the "r"(register) constraint
82;CHECK_LITTLE_32: #APP
83;CHECK_LITTLE_32: mtc0 ${{[1-9][0-9]?}}, ${{[0-9]+}}
84;CHECK_LITTLE_32: #NO_APP
85 call void asm sideeffect "mtc0 ${0:z}, $$12", "r"(i32 7) nounwind
86
87; z with zero and just the "r"(register) constraint
88; FIXME: Check for $0, instead of other registers.
89; We should be using $0 directly in this case, not real registers.
90; When the materialization of 0 gets fixed, this test will fail.
91;CHECK_LITTLE_32: #APP
92;CHECK_LITTLE_32: mtc0 ${{[1-9][0-9]?}}, ${{[0-9]+}}
93;CHECK_LITTLE_32: #NO_APP
94 call void asm sideeffect "mtc0 ${0:z}, $$12", "r"(i32 0) nounwind
Jack Cartera62ba822012-07-18 06:41:36 +000095 ret i32 0
96}
97
98; a long long in 32 bit mode (use to assert)
99define i32 @constraint_longlong() nounwind {
100entry:
Stephen Lind24ab202013-07-14 06:24:09 +0000101;CHECK_LITTLE_32-LABEL: constraint_longlong:
Jack Cartera62ba822012-07-18 06:41:36 +0000102;CHECK_LITTLE_32: #APP
Daniel Sandersb2305952014-05-22 11:46:58 +0000103;CHECK_LITTLE_32: addiu ${{[0-9]+}},${{[0-9]+}},3
Jack Cartera62ba822012-07-18 06:41:36 +0000104;CHECK_LITTLE_32: #NO_APP
Daniel Sandersb2305952014-05-22 11:46:58 +0000105 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 +0000106 ret i32 0
107}
108
109; D, in little endian the source reg will be 4 bytes into the long long
110define i32 @constraint_D() nounwind {
111entry:
Stephen Lind24ab202013-07-14 06:24:09 +0000112;CHECK_LITTLE_32-LABEL: constraint_D:
Jack Cartera62ba822012-07-18 06:41:36 +0000113;CHECK_LITTLE_32: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
114;CHECK_LITTLE_32: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
115;CHECK_LITTLE_32: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
116;CHECK_LITTLE_32: #APP
117;CHECK_LITTLE_32: or ${{[0-9]+}},$[[SECOND]],${{[0-9]+}}
118;CHECK_LITTLE_32: #NO_APP
119
120; D, in big endian the source reg will also be 4 bytes into the long long
Stephen Lind24ab202013-07-14 06:24:09 +0000121;CHECK_BIG_32-LABEL: constraint_D:
Jack Cartera62ba822012-07-18 06:41:36 +0000122;CHECK_BIG_32: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
123;CHECK_BIG_32: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
124;CHECK_BIG_32: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
125;CHECK_BIG_32: #APP
126;CHECK_BIG_32: or ${{[0-9]+}},$[[SECOND]],${{[0-9]+}}
127;CHECK_BIG_32: #NO_APP
David Blaikiea79ac142015-02-27 21:17:42 +0000128 %bosco = load i64, i64* getelementptr inbounds (%union.u_tag* @uval, i32 0, i32 0), align 8
Jack Cartera62ba822012-07-18 06:41:36 +0000129 %trunc1 = trunc i64 %bosco to i32
130 tail call i32 asm sideeffect "or $0,${1:D},$2", "=r,r,r"(i64 %bosco, i32 %trunc1) nounwind
131 ret i32 0
132}
133
134; L, in little endian the source reg will be 0 bytes into the long long
135define i32 @constraint_L() nounwind {
136entry:
Stephen Lind24ab202013-07-14 06:24:09 +0000137;CHECK_LITTLE_32-LABEL: constraint_L:
Jack Cartera62ba822012-07-18 06:41:36 +0000138;CHECK_LITTLE_32: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
139;CHECK_LITTLE_32: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
140;CHECK_LITTLE_32: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
141;CHECK_LITTLE_32: #APP
142;CHECK_LITTLE_32: or ${{[0-9]+}},$[[FIRST]],${{[0-9]+}}
143;CHECK_LITTLE_32: #NO_APP
144; L, in big endian the source reg will be 4 bytes into the long long
Stephen Lind24ab202013-07-14 06:24:09 +0000145;CHECK_BIG_32-LABEL: constraint_L:
Jack Cartera62ba822012-07-18 06:41:36 +0000146;CHECK_BIG_32: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
147;CHECK_BIG_32: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
148;CHECK_BIG_32: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
149;CHECK_BIG_32: #APP
150;CHECK_BIG_32: or ${{[0-9]+}},$[[SECOND]],${{[0-9]+}}
151;CHECK_BIG_32: #NO_APP
David Blaikiea79ac142015-02-27 21:17:42 +0000152 %bosco = load i64, i64* getelementptr inbounds (%union.u_tag* @uval, i32 0, i32 0), align 8
Jack Cartera62ba822012-07-18 06:41:36 +0000153 %trunc1 = trunc i64 %bosco to i32
154 tail call i32 asm sideeffect "or $0,${1:L},$2", "=r,r,r"(i64 %bosco, i32 %trunc1) nounwind
155 ret i32 0
156}
157
158; M, in little endian the source reg will be 4 bytes into the long long
159define i32 @constraint_M() nounwind {
160entry:
Stephen Lind24ab202013-07-14 06:24:09 +0000161;CHECK_LITTLE_32-LABEL: constraint_M:
Jack Cartera62ba822012-07-18 06:41:36 +0000162;CHECK_LITTLE_32: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
163;CHECK_LITTLE_32: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
164;CHECK_LITTLE_32: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
165;CHECK_LITTLE_32: #APP
166;CHECK_LITTLE_32: or ${{[0-9]+}},$[[SECOND]],${{[0-9]+}}
167;CHECK_LITTLE_32: #NO_APP
168; M, in big endian the source reg will be 0 bytes into the long long
Stephen Lind24ab202013-07-14 06:24:09 +0000169;CHECK_BIG_32-LABEL: constraint_M:
Jack Cartera62ba822012-07-18 06:41:36 +0000170;CHECK_BIG_32: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
171;CHECK_BIG_32: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
172;CHECK_BIG_32: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
173;CHECK_BIG_32: #APP
174;CHECK_BIG_32: or ${{[0-9]+}},$[[FIRST]],${{[0-9]+}}
175;CHECK_BIG_32: #NO_APP
David Blaikiea79ac142015-02-27 21:17:42 +0000176 %bosco = load i64, i64* getelementptr inbounds (%union.u_tag* @uval, i32 0, i32 0), align 8
Jack Cartera62ba822012-07-18 06:41:36 +0000177 %trunc1 = trunc i64 %bosco to i32
178 tail call i32 asm sideeffect "or $0,${1:M},$2", "=r,r,r"(i64 %bosco, i32 %trunc1) nounwind
179 ret i32 0
180}