Commit 0afc884
authored
[RISCV] Use vnclip for scalable vector saturating truncation. (#88648)
Similar to #75145, but for scalable vectors.
Specifically, this patch works for the below optimization case:
## Source Code
```
define void @trunc_sat_i8i16_maxmin(ptr %x, ptr %y) {
%1 = load <vscale x 4 x i16>, ptr %x, align 16
%2 = tail call <vscale x 4 x i16> @llvm.smax.v4i16(<vscale x 4 x i16> %1, <vscale x 4 x i16> splat (i16 -128))
%3 = tail call <vscale x 4 x i16> @llvm.smin.v4i16(<vscale x 4 x i16> %2, <vscale x 4 x i16> splat (i16 127))
%4 = trunc <vscale x 4 x i16> %3 to <vscale x 4 x i8>
store <vscale x 4 x i8> %4, ptr %y, align 8
ret void
}
```
## Before this patch
[Compiler Explorer](https://godbolt.org/z/EKc9eGvo8)
```
trunc_sat_i8i16_maxmin:
vl1re16.v v8, (a0)
li a0, -128
vsetvli a2, zero, e16, m1, ta, ma
vmax.vx v8, v8, a0
li a0, 127
vmin.vx v8, v8, a0
vsetvli zero, zero, e8, mf2, ta, ma
vnsrl.wi v8, v8, 0
vse8.v v8, (a1)
ret
```
## After this patch
```
trunc_sat_i8i16_maxmin:
vsetivli zero, 4, e8, mf4, ta, ma
vle16.v v8, (a0)
vnclip.wi v8, v8, 0
vse8.v v8, (a1)
ret
```1 parent 808d794 commit 0afc884
File tree
4 files changed
+455
-61
lines changed- llvm
- lib/Target/RISCV
- test/CodeGen/RISCV/rvv
4 files changed
+455
-61
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1166 | 1166 | | |
1167 | 1167 | | |
1168 | 1168 | | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
1169 | 1210 | | |
1170 | 1211 | | |
1171 | 1212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2373 | 2373 | | |
2374 | 2374 | | |
2375 | 2375 | | |
2376 | | - | |
2377 | | - | |
2378 | | - | |
2379 | | - | |
2380 | | - | |
2381 | | - | |
2382 | | - | |
2383 | | - | |
2384 | | - | |
2385 | | - | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
2386 | 2387 | | |
2387 | | - | |
| 2388 | + | |
2388 | 2389 | | |
2389 | | - | |
| 2390 | + | |
2390 | 2391 | | |
2391 | 2392 | | |
2392 | | - | |
| 2393 | + | |
2393 | 2394 | | |
2394 | 2395 | | |
2395 | 2396 | | |
2396 | | - | |
2397 | | - | |
2398 | | - | |
2399 | | - | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
2400 | 2411 | | |
2401 | 2412 | | |
2402 | 2413 | | |
| |||
2405 | 2416 | | |
2406 | 2417 | | |
2407 | 2418 | | |
2408 | | - | |
2409 | | - | |
2410 | | - | |
2411 | | - | |
2412 | | - | |
2413 | | - | |
2414 | | - | |
2415 | | - | |
2416 | | - | |
2417 | | - | |
2418 | | - | |
2419 | | - | |
2420 | | - | |
2421 | | - | |
2422 | | - | |
2423 | | - | |
2424 | | - | |
2425 | | - | |
2426 | 2419 | | |
2427 | | - | |
2428 | 2420 | | |
2429 | 2421 | | |
2430 | 2422 | | |
2431 | | - | |
| 2423 | + | |
2432 | 2424 | | |
2433 | 2425 | | |
2434 | 2426 | | |
| |||
Lines changed: 15 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | | - | |
14 | 12 | | |
15 | | - | |
16 | 13 | | |
17 | 14 | | |
18 | 15 | | |
| |||
110 | 107 | | |
111 | 108 | | |
112 | 109 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
117 | 113 | | |
118 | 114 | | |
119 | 115 | | |
| |||
127 | 123 | | |
128 | 124 | | |
129 | 125 | | |
130 | | - | |
131 | | - | |
132 | | - | |
| 126 | + | |
| 127 | + | |
133 | 128 | | |
134 | 129 | | |
135 | 130 | | |
| |||
231 | 226 | | |
232 | 227 | | |
233 | 228 | | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
238 | 232 | | |
239 | 233 | | |
240 | 234 | | |
| |||
248 | 242 | | |
249 | 243 | | |
250 | 244 | | |
251 | | - | |
252 | | - | |
253 | | - | |
| 245 | + | |
| 246 | + | |
254 | 247 | | |
255 | 248 | | |
256 | 249 | | |
| |||
355 | 348 | | |
356 | 349 | | |
357 | 350 | | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
362 | 354 | | |
363 | 355 | | |
364 | 356 | | |
| |||
372 | 364 | | |
373 | 365 | | |
374 | 366 | | |
375 | | - | |
376 | | - | |
377 | | - | |
| 367 | + | |
| 368 | + | |
378 | 369 | | |
379 | 370 | | |
0 commit comments