blob: 6d41385d18de1b92bbf1fb8646cffc3a1309f1f4 [file] [log] [blame]
Eric Christophered51b9e2012-05-10 21:48:22 +00001; Positive test for inline register constraints
2;
Daniel Sandersfbb6a232015-11-26 11:23:03 +00003; RUN: llc -no-integrated-as -march=mipsel < %s | \
4; RUN: FileCheck -check-prefix=ALL -check-prefix=LE32 -check-prefix=GAS %s
5; RUN: llc -no-integrated-as -march=mips < %s | \
6; RUN: FileCheck -check-prefix=ALL -check-prefix=BE32 -check-prefix=GAS %s
Eric Christophered51b9e2012-05-10 21:48:22 +00007
Jack Carterb2af5122012-07-05 23:58:21 +00008%union.u_tag = type { i64 }
9%struct.anon = type { i32, i32 }
10@uval = common global %union.u_tag zeroinitializer, align 8
Eric Christophered51b9e2012-05-10 21:48:22 +000011
12; X with -3
Jack Cartera62ba822012-07-18 06:41:36 +000013define i32 @constraint_X() nounwind {
14entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000015; ALL-LABEL: constraint_X:
16; ALL: #APP
17; GAS: addiu ${{[0-9]+}}, ${{[0-9]+}}, 0xfffffffffffffffd
18; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000019 tail call i32 asm sideeffect "addiu $0, $1, ${2:X}", "=r,r,I"(i32 7, i32 -3) ;
Eric Christophered51b9e2012-05-10 21:48:22 +000020 ret i32 0
21}
Jack Carterb2af5122012-07-05 23:58:21 +000022
Jack Cartera62ba822012-07-18 06:41:36 +000023; x with -3
24define i32 @constraint_x() nounwind {
25entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000026; ALL-LABEL: constraint_x:
27; ALL: #APP
28; GAS: addiu ${{[0-9]+}}, ${{[0-9]+}}, 0xfffd
29; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000030 tail call i32 asm sideeffect "addiu $0, $1, ${2:x}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000031 ret i32 0
32}
33
34; d with -3
35define i32 @constraint_d() nounwind {
36entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000037; ALL-LABEL: constraint_d:
38; ALL: #APP
39; ALL: addiu ${{[0-9]+}}, ${{[0-9]+}}, -3
40; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000041 tail call i32 asm sideeffect "addiu $0, $1, ${2:d}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000042 ret i32 0
43}
44
45; m with -3
46define i32 @constraint_m() nounwind {
47entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000048; ALL-LABEL: constraint_m:
49; ALL: #APP
50; ALL: addiu ${{[0-9]+}}, ${{[0-9]+}}, -4
51; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000052 tail call i32 asm sideeffect "addiu $0, $1, ${2:m}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000053 ret i32 0
54}
55
56; z with -3
57define i32 @constraint_z() nounwind {
58entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +000059; ALL-LABEL: constraint_z:
60; ALL: #APP
61; ALL: addiu ${{[0-9]+}}, ${{[0-9]+}}, -3
62; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000063 tail call i32 asm sideeffect "addiu $0, $1, ${2:z}", "=r,r,I"(i32 7, i32 -3) ;
Jack Cartera62ba822012-07-18 06:41:36 +000064
65; z with 0
Daniel Sandersfbb6a232015-11-26 11:23:03 +000066; ALL: #APP
67; GAS: addiu ${{[0-9]+}}, ${{[0-9]+}}, $0
68; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +000069 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 +000070
71; z with non-zero and the "r"(register) and "J"(integer zero) constraints
Daniel Sandersfbb6a232015-11-26 11:23:03 +000072; ALL: #APP
73; ALL: mtc0 ${{[1-9][0-9]?}}, ${{[0-9]+}}
74; ALL: #NO_APP
Toma Tabacu27cab752014-11-06 14:25:42 +000075 call void asm sideeffect "mtc0 ${0:z}, $$12", "Jr"(i32 7) nounwind
76
77; z with zero and the "r"(register) and "J"(integer zero) constraints
Daniel Sandersfbb6a232015-11-26 11:23:03 +000078; ALL: #APP
79; ALL: mtc0 $0, ${{[0-9]+}}
80; ALL: #NO_APP
Toma Tabacu27cab752014-11-06 14:25:42 +000081 call void asm sideeffect "mtc0 ${0:z}, $$12", "Jr"(i32 0) nounwind
82
83; z with non-zero and just the "r"(register) constraint
Daniel Sandersfbb6a232015-11-26 11:23:03 +000084; ALL: #APP
85; ALL: mtc0 ${{[1-9][0-9]?}}, ${{[0-9]+}}
86; ALL: #NO_APP
Toma Tabacu27cab752014-11-06 14:25:42 +000087 call void asm sideeffect "mtc0 ${0:z}, $$12", "r"(i32 7) nounwind
88
89; z with zero and just the "r"(register) constraint
90; FIXME: Check for $0, instead of other registers.
91; We should be using $0 directly in this case, not real registers.
92; When the materialization of 0 gets fixed, this test will fail.
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", "r"(i32 0) nounwind
Jack Cartera62ba822012-07-18 06:41:36 +000097 ret i32 0
98}
99
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000100; A long long in 32 bit mode (use to assert)
Jack Cartera62ba822012-07-18 06:41:36 +0000101define i32 @constraint_longlong() nounwind {
102entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000103; ALL-LABEL: constraint_longlong:
104; ALL: #APP
105; ALL: addiu ${{[0-9]+}}, ${{[0-9]+}}, 3
106; ALL: #NO_APP
Daniel Sanders00a4aac2015-11-16 14:14:59 +0000107 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 +0000108 ret i32 0
109}
110
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000111; In little endian the source reg will be 4 bytes into the long long
112; In big endian the source reg will also be 4 bytes into the long long
Jack Cartera62ba822012-07-18 06:41:36 +0000113define i32 @constraint_D() nounwind {
114entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000115; ALL-LABEL: constraint_D:
116; ALL: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
117; ALL: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
118; ALL: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
119; ALL: #APP
120; LE32: or ${{[0-9]+}}, $[[SECOND]], ${{[0-9]+}}
121; BE32: or ${{[0-9]+}}, $[[SECOND]], ${{[0-9]+}}
122; ALL: #NO_APP
David Blaikief72d05b2015-03-13 18:20:45 +0000123 %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 +0000124 %trunc1 = trunc i64 %bosco to i32
Daniel Sanders00a4aac2015-11-16 14:14:59 +0000125 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 +0000126 ret i32 0
127}
128
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000129; In little endian the source reg will be 0 bytes into the long long
130; In big endian the source reg will be 4 bytes into the long long
Jack Cartera62ba822012-07-18 06:41:36 +0000131define i32 @constraint_L() nounwind {
132entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000133; ALL-LABEL: constraint_L:
134; ALL: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
135; ALL: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
136; ALL: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
137; ALL: #APP
138; LE32: or ${{[0-9]+}}, $[[FIRST]], ${{[0-9]+}}
139; BE32: or ${{[0-9]+}}, $[[SECOND]], ${{[0-9]+}}
140; ALL: #NO_APP
David Blaikief72d05b2015-03-13 18:20:45 +0000141 %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 +0000142 %trunc1 = trunc i64 %bosco to i32
Daniel Sanders00a4aac2015-11-16 14:14:59 +0000143 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 +0000144 ret i32 0
145}
146
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000147; In little endian the source reg will be 4 bytes into the long long
148; In big endian the source reg will be 0 bytes into the long long
Jack Cartera62ba822012-07-18 06:41:36 +0000149define i32 @constraint_M() nounwind {
150entry:
Daniel Sandersfbb6a232015-11-26 11:23:03 +0000151; ALL-LABEL: constraint_M:
152; ALL: lw ${{[0-9]+}}, %got(uval)(${{[0-9,a-z]+}})
153; ALL: lw $[[SECOND:[0-9]+]], 4(${{[0-9]+}})
154; ALL: lw $[[FIRST:[0-9]+]], 0(${{[0-9]+}})
155; ALL: #APP
156; LE32: or ${{[0-9]+}}, $[[SECOND]], ${{[0-9]+}}
157; BE32: or ${{[0-9]+}}, $[[FIRST]], ${{[0-9]+}}
158; ALL: #NO_APP
David Blaikief72d05b2015-03-13 18:20:45 +0000159 %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 +0000160 %trunc1 = trunc i64 %bosco to i32
Daniel Sanders00a4aac2015-11-16 14:14:59 +0000161 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 +0000162 ret i32 0
163}