blob: 58fabf868f8cc319bedd2f176ff07b1a8bb0346a [file] [log] [blame]
Alex Bradbury9330e642018-01-10 20:05:09 +00001; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3; RUN: | FileCheck -check-prefix=RV32I %s
Alex Bradbury4efa0b62019-02-14 13:09:54 +00004; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5; RUN: | FileCheck -check-prefix=RV64I %s
Alex Bradbury9330e642018-01-10 20:05:09 +00006
7@gi = external global i32
8
Alex Bradbury5dabe032019-05-23 12:43:13 +00009define i32 @constraint_r(i32 %a) nounwind {
Alex Bradbury9330e642018-01-10 20:05:09 +000010; RV32I-LABEL: constraint_r:
11; RV32I: # %bb.0:
Alex Bradbury9330e642018-01-10 20:05:09 +000012; RV32I-NEXT: lui a1, %hi(gi)
Alex Bradbury0171a9f2018-03-19 11:54:28 +000013; RV32I-NEXT: lw a1, %lo(gi)(a1)
Alex Bradbury9330e642018-01-10 20:05:09 +000014; RV32I-NEXT: #APP
15; RV32I-NEXT: add a0, a0, a1
16; RV32I-NEXT: #NO_APP
Alex Bradbury9330e642018-01-10 20:05:09 +000017; RV32I-NEXT: ret
Alex Bradbury4efa0b62019-02-14 13:09:54 +000018;
19; RV64I-LABEL: constraint_r:
20; RV64I: # %bb.0:
21; RV64I-NEXT: lui a1, %hi(gi)
22; RV64I-NEXT: lwu a1, %lo(gi)(a1)
23; RV64I-NEXT: #APP
24; RV64I-NEXT: add a0, a0, a1
25; RV64I-NEXT: #NO_APP
26; RV64I-NEXT: ret
Alex Bradbury9330e642018-01-10 20:05:09 +000027 %1 = load i32, i32* @gi
28 %2 = tail call i32 asm "add $0, $1, $2", "=r,r,r"(i32 %a, i32 %1)
29 ret i32 %2
30}
31
Alex Bradbury5dabe032019-05-23 12:43:13 +000032define i32 @constraint_i(i32 %a) nounwind {
Alex Bradbury9330e642018-01-10 20:05:09 +000033; RV32I-LABEL: constraint_i:
34; RV32I: # %bb.0:
Alex Bradbury9330e642018-01-10 20:05:09 +000035; RV32I-NEXT: #APP
36; RV32I-NEXT: addi a0, a0, 113
37; RV32I-NEXT: #NO_APP
Alex Bradbury9330e642018-01-10 20:05:09 +000038; RV32I-NEXT: ret
Alex Bradbury4efa0b62019-02-14 13:09:54 +000039;
40; RV64I-LABEL: constraint_i:
41; RV64I: # %bb.0:
42; RV64I-NEXT: #APP
43; RV64I-NEXT: addi a0, a0, 113
44; RV64I-NEXT: #NO_APP
45; RV64I-NEXT: ret
Alex Bradbury9330e642018-01-10 20:05:09 +000046 %1 = load i32, i32* @gi
47 %2 = tail call i32 asm "addi $0, $1, $2", "=r,r,i"(i32 %a, i32 113)
48 ret i32 %2
49}
50
Alex Bradbury5dabe032019-05-23 12:43:13 +000051define void @constraint_m(i32* %a) nounwind {
Alex Bradbury9330e642018-01-10 20:05:09 +000052; RV32I-LABEL: constraint_m:
53; RV32I: # %bb.0:
Alex Bradbury9330e642018-01-10 20:05:09 +000054; RV32I-NEXT: #APP
55; RV32I-NEXT: #NO_APP
Alex Bradbury9330e642018-01-10 20:05:09 +000056; RV32I-NEXT: ret
Alex Bradbury4efa0b62019-02-14 13:09:54 +000057;
58; RV64I-LABEL: constraint_m:
59; RV64I: # %bb.0:
60; RV64I-NEXT: #APP
61; RV64I-NEXT: #NO_APP
62; RV64I-NEXT: ret
Alex Bradbury9330e642018-01-10 20:05:09 +000063 call void asm sideeffect "", "=*m"(i32* %a)
64 ret void
65}
66
Alex Bradbury5dabe032019-05-23 12:43:13 +000067define i32 @constraint_m2(i32* %a) nounwind {
Alex Bradbury9330e642018-01-10 20:05:09 +000068; RV32I-LABEL: constraint_m2:
69; RV32I: # %bb.0:
Alex Bradbury9330e642018-01-10 20:05:09 +000070; RV32I-NEXT: #APP
71; RV32I-NEXT: lw a0, 0(a0)
72; RV32I-NEXT: #NO_APP
Alex Bradbury9330e642018-01-10 20:05:09 +000073; RV32I-NEXT: ret
Alex Bradbury4efa0b62019-02-14 13:09:54 +000074;
75; RV64I-LABEL: constraint_m2:
76; RV64I: # %bb.0:
77; RV64I-NEXT: #APP
78; RV64I-NEXT: lw a0, 0(a0)
79; RV64I-NEXT: #NO_APP
80; RV64I-NEXT: ret
Alex Bradbury9330e642018-01-10 20:05:09 +000081 %1 = tail call i32 asm "lw $0, $1", "=r,*m"(i32* %a) nounwind
82 ret i32 %1
83}
84
Lewis Revill28a5cad2019-06-11 12:42:13 +000085define void @constraint_I() {
86; RV32I-LABEL: constraint_I:
87; RV32I: # %bb.0:
88; RV32I-NEXT: #APP
89; RV32I-NEXT: addi a0, a0, 2047
90; RV32I-NEXT: #NO_APP
91; RV32I-NEXT: #APP
92; RV32I-NEXT: addi a0, a0, -2048
93; RV32I-NEXT: #NO_APP
94; RV32I-NEXT: ret
95;
96; RV64I-LABEL: constraint_I:
97; RV64I: # %bb.0:
98; RV64I-NEXT: #APP
99; RV64I-NEXT: addi a0, a0, 2047
100; RV64I-NEXT: #NO_APP
101; RV64I-NEXT: #APP
102; RV64I-NEXT: addi a0, a0, -2048
103; RV64I-NEXT: #NO_APP
104; RV64I-NEXT: ret
105 tail call void asm sideeffect "addi a0, a0, $0", "I"(i32 2047)
106 tail call void asm sideeffect "addi a0, a0, $0", "I"(i32 -2048)
107 ret void
108}
109
110define void @constraint_J() {
111; RV32I-LABEL: constraint_J:
112; RV32I: # %bb.0:
113; RV32I-NEXT: #APP
114; RV32I-NEXT: addi a0, a0, 0
115; RV32I-NEXT: #NO_APP
116; RV32I-NEXT: ret
117;
118; RV64I-LABEL: constraint_J:
119; RV64I: # %bb.0:
120; RV64I-NEXT: #APP
121; RV64I-NEXT: addi a0, a0, 0
122; RV64I-NEXT: #NO_APP
123; RV64I-NEXT: ret
124 tail call void asm sideeffect "addi a0, a0, $0", "J"(i32 0)
125 ret void
126}
127
128define void @constraint_K() {
129; RV32I-LABEL: constraint_K:
130; RV32I: # %bb.0:
131; RV32I-NEXT: #APP
132; RV32I-NEXT: csrwi mstatus, 31
133; RV32I-NEXT: #NO_APP
134; RV32I-NEXT: #APP
135; RV32I-NEXT: csrwi mstatus, 0
136; RV32I-NEXT: #NO_APP
137; RV32I-NEXT: ret
138;
139; RV64I-LABEL: constraint_K:
140; RV64I: # %bb.0:
141; RV64I-NEXT: #APP
142; RV64I-NEXT: csrwi mstatus, 31
143; RV64I-NEXT: #NO_APP
144; RV64I-NEXT: #APP
145; RV64I-NEXT: csrwi mstatus, 0
146; RV64I-NEXT: #NO_APP
147; RV64I-NEXT: ret
148 tail call void asm sideeffect "csrwi mstatus, $0", "K"(i32 31)
149 tail call void asm sideeffect "csrwi mstatus, $0", "K"(i32 0)
150 ret void
151}
152
Alex Bradbury9330e642018-01-10 20:05:09 +0000153; TODO: expend tests for more complex constraints, out of range immediates etc