Commit 46ee7f1
authored
[libclc] Avoid out-of-range float-to-int. (llvm#145698)
For a kernel such as
kernel void foo(__global double3 *z) {
double3 x = {0.6631661088,0.6612268107,0.1513627528};
int3 y = {-1980459213,-660855407,615708204};
*z = pown(x, y);
}
we were not storing anything to z, because the implementation of pown
relied on an floating-point-to-integer conversion where the
floating-point value was outside of the integer's range. Although in
LLVM IR we permit that operation so long as we end up ignoring its
result -- that is the general rule for poison -- one thing we are not
permitted to do is have conditional branches that depend on it, and
through the call to __clc_ldexp, we did have that.
To fix this, rather than changing expv at the end to INFINITY/0, we can
change v at the start to values that we know will produce INFINITY/0
without performing such out-of-range conversions.
Tested with
clang --target=nvptx64 -S -O3 -o - test.cl \
-Xclang -mlink-builtin-bitcode \
-Xclang runtimes/runtimes-bins/libclc/nvptx64--.bc
A grep showed that this exact same code existed in three more places, so
I changed it there too, though I did not do a broader search for other
similar code that potentially has the same problem.1 parent 8202c94 commit 46ee7f1
File tree
4 files changed
+36
-16
lines changed- libclc/clc/lib/generic/math
4 files changed
+36
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
333 | 342 | | |
334 | 343 | | |
335 | 344 | | |
| |||
357 | 366 | | |
358 | 367 | | |
359 | 368 | | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | 369 | | |
365 | 370 | | |
366 | 371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
320 | 329 | | |
321 | 330 | | |
322 | 331 | | |
| |||
344 | 353 | | |
345 | 354 | | |
346 | 355 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | 356 | | |
352 | 357 | | |
353 | 358 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
319 | 328 | | |
320 | 329 | | |
321 | 330 | | |
| |||
343 | 352 | | |
344 | 353 | | |
345 | 354 | | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | 355 | | |
351 | 356 | | |
352 | 357 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
326 | 335 | | |
327 | 336 | | |
328 | 337 | | |
| |||
350 | 359 | | |
351 | 360 | | |
352 | 361 | | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | 362 | | |
358 | 363 | | |
359 | 364 | | |
| |||
0 commit comments