1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1150 -verify-machineinstrs < %s | FileCheck %s
3 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1150 -global-isel -verify-machineinstrs < %s | FileCheck %s
5 define amdgpu_vs float @fadd_f32(float inreg %a, float inreg %b) {
6 ; CHECK-LABEL: fadd_f32:
8 ; CHECK-NEXT: s_add_f32 s0, s0, s1
9 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
10 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
11 ; CHECK-NEXT: ; return to shader part epilog
12 %add = fadd float %a, %b
16 define amdgpu_vs float @fsub_f32(float inreg %a, float inreg %b) {
17 ; CHECK-LABEL: fsub_f32:
19 ; CHECK-NEXT: s_sub_f32 s0, s0, s1
20 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
21 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
22 ; CHECK-NEXT: ; return to shader part epilog
23 %sub = fsub float %a, %b
27 define amdgpu_vs float @fmul_f32(float inreg %a, float inreg %b) {
28 ; CHECK-LABEL: fmul_f32:
30 ; CHECK-NEXT: s_mul_f32 s0, s0, s1
31 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
32 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
33 ; CHECK-NEXT: ; return to shader part epilog
34 %mul = fmul float %a, %b
38 define amdgpu_vs float @fmin_f32(float inreg %a, float inreg %b) {
39 ; CHECK-LABEL: fmin_f32:
41 ; CHECK-NEXT: s_min_f32 s0, s0, s1
42 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
43 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
44 ; CHECK-NEXT: ; return to shader part epilog
45 %min = call float @llvm.minnum.f32(float %a, float %b)
49 define amdgpu_vs float @fmax_f32(float inreg %a, float inreg %b) {
50 ; CHECK-LABEL: fmax_f32:
52 ; CHECK-NEXT: s_max_f32 s0, s0, s1
53 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
54 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
55 ; CHECK-NEXT: ; return to shader part epilog
56 %max = call float @llvm.maxnum.f32(float %a, float %b)
60 define amdgpu_vs half @fadd_f16(half inreg %a, half inreg %b) {
61 ; CHECK-LABEL: fadd_f16:
63 ; CHECK-NEXT: s_add_f16 s0, s0, s1
64 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
65 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
66 ; CHECK-NEXT: ; return to shader part epilog
67 %add = fadd half %a, %b
71 define amdgpu_vs half @fsub_f16(half inreg %a, half inreg %b) {
72 ; CHECK-LABEL: fsub_f16:
74 ; CHECK-NEXT: s_sub_f16 s0, s0, s1
75 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
76 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
77 ; CHECK-NEXT: ; return to shader part epilog
78 %sub = fsub half %a, %b
82 define amdgpu_vs half @fmul_f16(half inreg %a, half inreg %b) {
83 ; CHECK-LABEL: fmul_f16:
85 ; CHECK-NEXT: s_mul_f16 s0, s0, s1
86 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
87 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
88 ; CHECK-NEXT: ; return to shader part epilog
89 %mul = fmul half %a, %b
93 define amdgpu_vs half @fmin_f16(half inreg %a, half inreg %b) {
94 ; CHECK-LABEL: fmin_f16:
96 ; CHECK-NEXT: s_min_f16 s0, s0, s1
97 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
98 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
99 ; CHECK-NEXT: ; return to shader part epilog
100 %min = call half @llvm.minnum.f16(half %a, half %b)
104 define amdgpu_vs half @fmax_f16(half inreg %a, half inreg %b) {
105 ; CHECK-LABEL: fmax_f16:
107 ; CHECK-NEXT: s_max_f16 s0, s0, s1
108 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
109 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
110 ; CHECK-NEXT: ; return to shader part epilog
111 %max = call half @llvm.maxnum.f16(half %a, half %b)
115 define amdgpu_vs <2 x half> @s_cvt_pkrtz_v2f16_f32(float inreg %x, float inreg %y) {
116 ; CHECK-LABEL: s_cvt_pkrtz_v2f16_f32:
118 ; CHECK-NEXT: s_cvt_pk_rtz_f16_f32 s0, s0, s1
119 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
120 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
121 ; CHECK-NEXT: ; return to shader part epilog
122 %result = call <2 x half> @llvm.amdgcn.cvt.pkrtz(float %x, float %y)
123 ret <2 x half> %result
126 define amdgpu_vs float @fmac_f32(float inreg %a, float inreg %b, float inreg %c) {
127 ; CHECK-LABEL: fmac_f32:
129 ; CHECK-NEXT: s_fmac_f32 s0, s1, s2
130 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
131 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
132 ; CHECK-NEXT: ; return to shader part epilog
133 %res = call float @llvm.fma.f32(float %b, float %c, float %a)
137 ; Check selection of mov + fmac if src2 of fmac has a use later on
138 define amdgpu_vs float @fmac_f32_with_mov(float inreg %a, float inreg %b, float inreg %c) {
139 ; CHECK-LABEL: fmac_f32_with_mov:
141 ; CHECK-NEXT: s_mov_b32 s3, s2
142 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_3)
143 ; CHECK-NEXT: s_fmac_f32 s3, s0, s1
144 ; CHECK-NEXT: s_add_f32 s0, s3, s2
145 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
146 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
147 ; CHECK-NEXT: ; return to shader part epilog
148 %fma = call float @llvm.fma.f32(float %a, float %b, float %c)
149 %res = fadd float %fma, %c
153 define amdgpu_vs half @fmac_f16(half inreg %a, half inreg %b, half inreg %c) {
154 ; CHECK-LABEL: fmac_f16:
156 ; CHECK-NEXT: s_fmac_f16 s0, s1, s2
157 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
158 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
159 ; CHECK-NEXT: ; return to shader part epilog
160 %res = call half @llvm.fma.f16(half %b, half %c, half %a)
164 ; Check selection of mov + fmac if src2 of fmac has a use later
165 define amdgpu_vs half @fmac_f16_with_mov(half inreg %a, half inreg %b, half inreg %c) {
166 ; CHECK-LABEL: fmac_f16_with_mov:
168 ; CHECK-NEXT: s_mov_b32 s3, s2
169 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_3)
170 ; CHECK-NEXT: s_fmac_f16 s3, s0, s1
171 ; CHECK-NEXT: s_add_f16 s0, s3, s2
172 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
173 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
174 ; CHECK-NEXT: ; return to shader part epilog
175 %fma = call half @llvm.fma.f16(half %a, half %b, half %c)
176 %res = fadd half %fma, %c
180 ; Regression test for crash in SIFoldOperands
181 define amdgpu_ps float @_amdgpu_ps_main() {
182 ; CHECK-LABEL: _amdgpu_ps_main:
183 ; CHECK: ; %bb.0: ; %bb
184 ; CHECK-NEXT: s_mov_b32 s0, 0
185 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_1)
186 ; CHECK-NEXT: s_mov_b32 s1, s0
187 ; CHECK-NEXT: s_mov_b32 s2, s0
188 ; CHECK-NEXT: s_mov_b32 s3, s0
189 ; CHECK-NEXT: s_buffer_load_b64 s[0:1], s[0:3], 0x0
190 ; CHECK-NEXT: s_waitcnt lgkmcnt(0)
191 ; CHECK-NEXT: s_fmamk_f32 s0, s1, 0x40800000, s0
192 ; CHECK-NEXT: s_delay_alu instid0(SALU_CYCLE_3)
193 ; CHECK-NEXT: v_mov_b32_e32 v0, s0
194 ; CHECK-NEXT: ; return to shader part epilog
196 %i = call i32 @llvm.amdgcn.s.buffer.load.i32(<4 x i32> zeroinitializer, i32 0, i32 0)
197 %i1 = bitcast i32 %i to float
198 %i2 = call i32 @llvm.amdgcn.s.buffer.load.i32(<4 x i32> zeroinitializer, i32 4, i32 0)
199 %i3 = bitcast i32 %i2 to float
200 %i4 = fmul contract float %i3, 4.0
201 %i5 = fadd contract float %i4, %i1
205 declare i32 @llvm.amdgcn.s.buffer.load.i32(<4 x i32>, i32, i32 immarg)
206 declare float @llvm.minnum.f32(float, float)
207 declare float @llvm.maxnum.f32(float, float)
208 declare half @llvm.minnum.f16(half, half)
209 declare half @llvm.maxnum.f16(half, half)
210 declare <2 x half> @llvm.amdgcn.cvt.pkrtz(float, float)
211 declare float @llvm.fma.f32(float, float, float) nounwind readnone
212 declare half @llvm.fma.f16(half, half, half) nounwind readnone