blob: af631f0d29f545374761671874d748328d35ba3a [file] [log] [blame]
James Y Knight3994be82015-08-10 19:11:39 +00001; RUN: llc -march=sparc <%s | FileCheck %s
Venkatraman Govindaraju407e4422014-01-22 01:29:51 +00002
3; CHECK-LABEL: test_constraint_r
4; CHECK: add %o1, %o0, %o0
5define i32 @test_constraint_r(i32 %a, i32 %b) {
6entry:
7 %0 = tail call i32 asm sideeffect "add $2, $1, $0", "=r,r,r"(i32 %a, i32 %b)
8 ret i32 %0
9}
10
Chris Dewhurst0dfa6bc2016-05-20 09:03:01 +000011;; Check tests only that the constraints are accepted without a compiler failure.
12; CHECK-LABEL: test_constraints_nro:
13%struct.anon = type { i32, i32 }
14@v = external global %struct.anon, align 4
15define void @test_constraints_nro() {
16entry:
17 %0 = load i32, i32* getelementptr inbounds (%struct.anon, %struct.anon* @v, i32 0, i32 0);
18 %1 = load i32, i32* getelementptr inbounds (%struct.anon, %struct.anon* @v, i32 0, i32 1);
19 tail call void asm sideeffect "", "nro,nro"(i32 %0, i32 %1)
20 ret void
21}
22
James Y Knight3994be82015-08-10 19:11:39 +000023; CHECK-LABEL: test_constraint_I:
Venkatraman Govindaraju407e4422014-01-22 01:29:51 +000024; CHECK: add %o0, 1023, %o0
25define i32 @test_constraint_I(i32 %a) {
26entry:
27 %0 = tail call i32 asm sideeffect "add $1, $2, $0", "=r,r,rI"(i32 %a, i32 1023)
28 ret i32 %0
29}
30
James Y Knight3994be82015-08-10 19:11:39 +000031; CHECK-LABEL: test_constraint_I_neg:
Venkatraman Govindaraju407e4422014-01-22 01:29:51 +000032; CHECK: add %o0, -4096, %o0
33define i32 @test_constraint_I_neg(i32 %a) {
34entry:
35 %0 = tail call i32 asm sideeffect "add $1, $2, $0", "=r,r,rI"(i32 %a, i32 -4096)
36 ret i32 %0
37}
38
James Y Knight3994be82015-08-10 19:11:39 +000039; CHECK-LABEL: test_constraint_I_largeimm:
Venkatraman Govindaraju407e4422014-01-22 01:29:51 +000040; CHECK: sethi 9, [[R0:%[gilo][0-7]]]
41; CHECK: or [[R0]], 784, [[R1:%[gilo][0-7]]]
42; CHECK: add %o0, [[R1]], %o0
43define i32 @test_constraint_I_largeimm(i32 %a) {
44entry:
45 %0 = tail call i32 asm sideeffect "add $1, $2, $0", "=r,r,rI"(i32 %a, i32 10000)
46 ret i32 %0
47}
Venkatraman Govindarajudd634ca2014-01-22 03:18:42 +000048
James Y Knight3994be82015-08-10 19:11:39 +000049; CHECK-LABEL: test_constraint_reg:
Venkatraman Govindarajudd634ca2014-01-22 03:18:42 +000050; CHECK: ldda [%o1] 43, %g2
James Y Knight3994be82015-08-10 19:11:39 +000051; CHECK: ldda [%o1] 43, %g4
Venkatraman Govindarajudd634ca2014-01-22 03:18:42 +000052define void @test_constraint_reg(i32 %s, i32* %ptr) {
53entry:
54 %0 = tail call i64 asm sideeffect "ldda [$1] $2, $0", "={r2},r,n"(i32* %ptr, i32 43)
James Y Knight3994be82015-08-10 19:11:39 +000055 %1 = tail call i64 asm sideeffect "ldda [$1] $2, $0", "={g4},r,n"(i32* %ptr, i32 43)
Venkatraman Govindarajudd634ca2014-01-22 03:18:42 +000056 ret void
57}
James Y Knight3994be82015-08-10 19:11:39 +000058
59;; Ensure that i64 args to asm are allocated to the IntPair register class.
60;; Also checks that register renaming for leaf proc works.
61; CHECK-LABEL: test_constraint_r_i64:
62; CHECK: mov %o0, %o5
63; CHECK: sra %o5, 31, %o4
64; CHECK: std %o4, [%o1]
65define i32 @test_constraint_r_i64(i32 %foo, i64* %out, i32 %o) {
66entry:
67 %conv = sext i32 %foo to i64
68 tail call void asm sideeffect "std $0, [$1]", "r,r,~{memory}"(i64 %conv, i64* %out)
69 ret i32 %o
70}
71
72;; Same test without leaf-proc opt
73; CHECK-LABEL: test_constraint_r_i64_noleaf:
74; CHECK: mov %i0, %i5
75; CHECK: sra %i5, 31, %i4
76; CHECK: std %i4, [%i1]
77define i32 @test_constraint_r_i64_noleaf(i32 %foo, i64* %out, i32 %o) #0 {
78entry:
79 %conv = sext i32 %foo to i64
80 tail call void asm sideeffect "std $0, [$1]", "r,r,~{memory}"(i64 %conv, i64* %out)
81 ret i32 %o
82}
83attributes #0 = { "no-frame-pointer-elim"="true" }
84
85;; Ensures that tied in and out gets allocated properly.
86; CHECK-LABEL: test_i64_inout:
87; CHECK: sethi 0, %o2
88; CHECK: mov 5, %o3
89; CHECK: xor %o2, %g0, %o2
90; CHECK: mov %o2, %o0
91; CHECK: ret
92define i64 @test_i64_inout() {
93entry:
94 %0 = call i64 asm sideeffect "xor $1, %g0, $0", "=r,0,~{i1}"(i64 5);
95 ret i64 %0
96}