1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1030 -verify-machineinstrs -disable-machine-sink=1 - < %s | FileCheck -check-prefix=GFX10 %s
4 define float @fold_abs_in_branch(float %arg1, float %arg2) {
5 ; GFX10-LABEL: fold_abs_in_branch:
6 ; GFX10: ; %bb.0: ; %entry
7 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
8 ; GFX10-NEXT: v_add_f32_e32 v0, v0, v1
9 ; GFX10-NEXT: s_mov_b32 s4, exec_lo
10 ; GFX10-NEXT: v_add_f32_e32 v1, v0, v1
11 ; GFX10-NEXT: v_add_f32_e64 v0, |v1|, |v1|
12 ; GFX10-NEXT: v_cmpx_nlt_f32_e32 1.0, v0
13 ; GFX10-NEXT: ; %bb.1: ; %if
14 ; GFX10-NEXT: v_mul_f32_e64 v0, 0x3e4ccccd, |v1|
15 ; GFX10-NEXT: ; %bb.2: ; %exit
16 ; GFX10-NEXT: s_or_b32 exec_lo, exec_lo, s4
17 ; GFX10-NEXT: s_setpc_b64 s[30:31]
19 %0 = fadd reassoc nnan nsz arcp contract afn float %arg1, %arg2
20 %1 = fadd reassoc nnan nsz arcp contract afn float %0, %arg2
21 %2 = call reassoc nnan nsz arcp contract afn float @llvm.fabs.f32(float %1)
22 %3 = fmul reassoc nnan nsz arcp contract afn float %2, 2.000000e+00
23 %4 = fcmp ule float %3, 1.000000e+00
24 br i1 %4, label %if, label %exit
27 %if.3 = fmul reassoc nnan nsz arcp contract afn float %2, 0x3FC99999A0000000
31 %ret = phi float [ %3, %entry ], [ %if.3, %if ]
35 define float @fold_abs_in_branch_multiple_users(float %arg1, float %arg2) {
36 ; GFX10-LABEL: fold_abs_in_branch_multiple_users:
37 ; GFX10: ; %bb.0: ; %entry
38 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
39 ; GFX10-NEXT: v_add_f32_e32 v0, v0, v1
40 ; GFX10-NEXT: s_mov_b32 s4, exec_lo
41 ; GFX10-NEXT: v_add_f32_e32 v0, v0, v1
42 ; GFX10-NEXT: v_add_f32_e64 v1, |v0|, |v0|
43 ; GFX10-NEXT: v_cmpx_nlt_f32_e32 1.0, v1
44 ; GFX10-NEXT: ; %bb.1: ; %if
45 ; GFX10-NEXT: v_mul_f32_e64 v1, 0x3e4ccccd, |v0|
46 ; GFX10-NEXT: ; %bb.2: ; %exit
47 ; GFX10-NEXT: s_or_b32 exec_lo, exec_lo, s4
48 ; GFX10-NEXT: v_add_f32_e64 v0, |v0|, 2.0
49 ; GFX10-NEXT: v_mul_f32_e32 v0, v0, v1
50 ; GFX10-NEXT: s_setpc_b64 s[30:31]
52 %0 = fadd reassoc nnan nsz arcp contract afn float %arg1, %arg2
53 %1 = fadd reassoc nnan nsz arcp contract afn float %0, %arg2
54 %2 = call reassoc nnan nsz arcp contract afn float @llvm.fabs.f32(float %1)
55 %3 = fmul reassoc nnan nsz arcp contract afn float %2, 2.000000e+00
56 %4 = fcmp ule float %3, 1.000000e+00
57 br i1 %4, label %if, label %exit
60 %if.3 = fmul reassoc nnan nsz arcp contract afn float %2, 0x3FC99999A0000000
64 %exit.phi = phi float [ %3, %entry ], [ %if.3, %if ]
65 %ret.0 = fadd reassoc nnan nsz arcp contract afn float %2, 2.000000e+00
66 %ret.1 = fmul float %ret.0, %exit.phi
70 define float @fold_abs_in_branch_undef(float %arg1, float %arg2) {
71 ; GFX10-LABEL: fold_abs_in_branch_undef:
72 ; GFX10: ; %bb.0: ; %entry
73 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
74 ; GFX10-NEXT: v_add_f32_e64 v0, |s4|, |s4|
75 ; GFX10-NEXT: v_cmp_lt_f32_e32 vcc_lo, 1.0, v0
76 ; GFX10-NEXT: s_cbranch_vccnz .LBB2_2
77 ; GFX10-NEXT: ; %bb.1: ; %if
78 ; GFX10-NEXT: v_mul_f32_e64 v0, 0x3e4ccccd, |s4|
79 ; GFX10-NEXT: .LBB2_2: ; %exit
80 ; GFX10-NEXT: s_setpc_b64 s[30:31]
82 %0 = fadd reassoc nnan nsz arcp contract afn float %arg1, %arg2
83 %1 = fadd reassoc nnan nsz arcp contract afn float %0, %arg2
84 %2 = call reassoc nnan nsz arcp contract afn float @llvm.fabs.f32(float undef)
85 %3 = fmul reassoc nnan nsz arcp contract afn float %2, 2.000000e+00
86 %4 = fcmp ule float %3, 1.000000e+00
87 br i1 %4, label %if, label %exit
90 %if.3 = fmul reassoc nnan nsz arcp contract afn float %2, 0x3FC99999A0000000
94 %ret = phi float [ %3, %entry ], [ %if.3, %if ]
98 define float @fold_abs_in_branch_poison(float %arg1, float %arg2) {
99 ; GFX10-LABEL: fold_abs_in_branch_poison:
100 ; GFX10: ; %bb.0: ; %entry
101 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
102 ; GFX10-NEXT: v_add_f32_e64 v0, |s4|, |s4|
103 ; GFX10-NEXT: v_cmp_lt_f32_e32 vcc_lo, 1.0, v0
104 ; GFX10-NEXT: s_cbranch_vccnz .LBB3_2
105 ; GFX10-NEXT: ; %bb.1: ; %if
106 ; GFX10-NEXT: v_mul_f32_e64 v0, 0x3e4ccccd, |s4|
107 ; GFX10-NEXT: .LBB3_2: ; %exit
108 ; GFX10-NEXT: s_setpc_b64 s[30:31]
110 %0 = fadd reassoc nnan nsz arcp contract afn float %arg1, %arg2
111 %1 = fadd reassoc nnan nsz arcp contract afn float %0, %arg2
112 %2 = call reassoc nnan nsz arcp contract afn float @llvm.fabs.f32(float poison)
113 %3 = fmul reassoc nnan nsz arcp contract afn float %2, 2.000000e+00
114 %4 = fcmp ule float %3, 1.000000e+00
115 br i1 %4, label %if, label %exit
118 %if.3 = fmul reassoc nnan nsz arcp contract afn float %2, 0x3FC99999A0000000
122 %ret = phi float [ %3, %entry ], [ %if.3, %if ]
126 define float @fold_abs_in_branch_fabs(float %arg1, float %arg2) {
127 ; GFX10-LABEL: fold_abs_in_branch_fabs:
128 ; GFX10: ; %bb.0: ; %entry
129 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
130 ; GFX10-NEXT: v_add_f32_e32 v0, v0, v1
131 ; GFX10-NEXT: s_mov_b32 s4, exec_lo
132 ; GFX10-NEXT: v_add_f32_e32 v1, v0, v1
133 ; GFX10-NEXT: v_add_f32_e64 v0, |v1|, |v1|
134 ; GFX10-NEXT: v_cmpx_nlt_f32_e32 1.0, v0
135 ; GFX10-NEXT: ; %bb.1: ; %if
136 ; GFX10-NEXT: v_mul_f32_e64 v0, 0x3e4ccccd, |v1|
137 ; GFX10-NEXT: ; %bb.2: ; %exit
138 ; GFX10-NEXT: s_or_b32 exec_lo, exec_lo, s4
139 ; GFX10-NEXT: s_setpc_b64 s[30:31]
141 %0 = fadd reassoc nnan nsz arcp contract afn float %arg1, %arg2
142 %1 = fadd reassoc nnan nsz arcp contract afn float %0, %arg2
143 %2 = call reassoc nnan nsz arcp contract afn float @llvm.fabs.f32(float %1)
144 %3 = fmul reassoc nnan nsz arcp contract afn float %2, 2.000000e+00
145 %4 = fcmp ule float %3, 1.000000e+00
146 br i1 %4, label %if, label %exit
149 %if.fabs = call reassoc nnan nsz arcp contract afn float @llvm.fabs.f32(float %2)
150 %if.3 = fmul reassoc nnan nsz arcp contract afn float %if.fabs, 0x3FC99999A0000000
154 %ret = phi float [ %3, %entry ], [ %if.3, %if ]
158 define float @fold_abs_in_branch_phi(float %arg1, float %arg2) {
159 ; GFX10-LABEL: fold_abs_in_branch_phi:
160 ; GFX10: ; %bb.0: ; %entry
161 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
162 ; GFX10-NEXT: v_add_f32_e32 v0, v0, v1
163 ; GFX10-NEXT: s_mov_b32 s4, exec_lo
164 ; GFX10-NEXT: v_add_f32_e32 v0, v0, v1
165 ; GFX10-NEXT: v_add_f32_e64 v0, |v0|, |v0|
166 ; GFX10-NEXT: v_cmpx_nlt_f32_e32 1.0, v0
167 ; GFX10-NEXT: s_cbranch_execz .LBB5_3
168 ; GFX10-NEXT: ; %bb.1: ; %header.preheader
169 ; GFX10-NEXT: ; implicit-def: $vgpr0
170 ; GFX10-NEXT: .LBB5_2: ; %header
171 ; GFX10-NEXT: ; =>This Inner Loop Header: Depth=1
172 ; GFX10-NEXT: v_mul_f32_e32 v0, 0x40400000, v0
173 ; GFX10-NEXT: v_cmp_lt_f32_e32 vcc_lo, -1.0, v0
174 ; GFX10-NEXT: v_and_b32_e32 v0, 0x7fffffff, v0
175 ; GFX10-NEXT: s_cbranch_vccnz .LBB5_2
176 ; GFX10-NEXT: .LBB5_3: ; %Flow1
177 ; GFX10-NEXT: s_or_b32 exec_lo, exec_lo, s4
178 ; GFX10-NEXT: s_setpc_b64 s[30:31]
180 %0 = fadd reassoc nnan nsz arcp contract afn float %arg1, %arg2
181 %1 = fadd reassoc nnan nsz arcp contract afn float %0, %arg2
182 %2 = call reassoc nnan nsz arcp contract afn float @llvm.fabs.f32(float %1)
183 %3 = fmul reassoc nnan nsz arcp contract afn float %2, 2.000000e+00
184 %4 = fcmp ule float %3, 1.000000e+00
185 br i1 %4, label %header, label %exit
188 %h.fabs.phi = phi float [ undef, %entry ], [ %l.fabs, %l ]
189 %h.fmul = fmul reassoc nnan nsz arcp contract afn float %h.fabs.phi, 2.000000e+00
190 %l.1 = fmul reassoc nnan nsz arcp contract afn float %h.fabs.phi, 3.000000e+00
194 %l.e = fcmp ule float %l.1, -1.000000e+00
195 %l.fabs = call reassoc nnan nsz arcp contract afn float @llvm.fabs.f32(float %l.1)
196 br i1 %l.e, label %exit, label %header
199 %ret = phi float [ %3, %entry ], [ %l.fabs, %l ]
203 define float @fold_neg_in_branch(float %arg1, float %arg2) {
204 ; GFX10-LABEL: fold_neg_in_branch:
205 ; GFX10: ; %bb.0: ; %entry
206 ; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
207 ; GFX10-NEXT: v_add_f32_e32 v0, v0, v1
208 ; GFX10-NEXT: s_mov_b32 s4, exec_lo
209 ; GFX10-NEXT: v_add_f32_e32 v0, v0, v1
210 ; GFX10-NEXT: v_mov_b32_e32 v1, v0
211 ; GFX10-NEXT: v_cmpx_nlt_f32_e32 1.0, v0
212 ; GFX10-NEXT: ; %bb.1: ; %if
213 ; GFX10-NEXT: v_rcp_f32_e64 v1, -v0
214 ; GFX10-NEXT: v_mul_f32_e64 v1, |v0|, v1
215 ; GFX10-NEXT: ; %bb.2: ; %exit
216 ; GFX10-NEXT: s_or_b32 exec_lo, exec_lo, s4
217 ; GFX10-NEXT: v_mul_f32_e64 v0, -v0, v1
218 ; GFX10-NEXT: s_setpc_b64 s[30:31]
220 %0 = fadd reassoc nnan nsz arcp contract afn float %arg1, %arg2
221 %1 = fadd reassoc nnan nsz arcp contract afn float %0, %arg2
222 %2 = fneg reassoc nnan nsz arcp contract afn float %1
223 %3 = fcmp ule float %1, 1.000000e+00
224 br i1 %3, label %if, label %exit
227 %if.fabs = call reassoc nnan nsz arcp contract afn float @llvm.fabs.f32(float %1)
228 %if.3 = fdiv reassoc nnan nsz arcp contract afn float %if.fabs, %2
232 %ret = phi float [ %1, %entry ], [ %if.3, %if ]
233 %ret.2 = fmul reassoc nnan nsz arcp contract afn float %2, %ret
237 declare float @llvm.fabs.f32(float)
238 declare float @llvm.fmuladd.f32(float, float, float) #0