Commit d8fe1a6
Mark wave intrinsics as convergent to prevent loop miscompilation
The JumpThreading pass could restructure loops containing wave intrinsics
by threading edges through the loop latch block. This moved wave ops
(WaveReadLaneFirst, WaveActiveCountBits, etc.) from inside the loop to
after it, changing the set of active lanes at the call site. On SIMT
hardware, this produced incorrect results because all lanes reconverge
at the post-loop point rather than only the matching subset.
Fix:
- DxilConvergentMark: Mark wave-sensitive HL functions with the
Attribute::Convergent attribute before optimizer passes run.
- JumpThreading: In ThreadEdge, walk backward from the latch to the
loop header to identify loop body blocks. If any contains a convergent
call, prevent threading through the latch.
- DxilOperations::GetOpFunc: Mark DXIL wave op functions with
Attribute::Convergent for post-dxilgen optimizer passes.
Fixes a bug where a material binning pattern using WaveReadLaneFirst +
WaveActiveCountBits in a while-loop produced correct results at -Od but
incorrect results with optimizations enabled.
Co-authored-by: Copilot <[email protected]>1 parent c44a383 commit d8fe1a6
4 files changed
Lines changed: 122 additions & 3 deletions
File tree
- lib
- DXIL
- HLSL
- Transforms/Scalar
- tools/clang/test/HLSLFileCheck/hlsl/intrinsics/wave/convergent
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6738 | 6738 | | |
6739 | 6739 | | |
6740 | 6740 | | |
| 6741 | + | |
| 6742 | + | |
| 6743 | + | |
| 6744 | + | |
| 6745 | + | |
| 6746 | + | |
| 6747 | + | |
| 6748 | + | |
6741 | 6749 | | |
6742 | 6750 | | |
6743 | 6751 | | |
| |||
6749 | 6757 | | |
6750 | 6758 | | |
6751 | 6759 | | |
| 6760 | + | |
| 6761 | + | |
| 6762 | + | |
6752 | 6763 | | |
6753 | 6764 | | |
6754 | 6765 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
47 | 63 | | |
48 | 64 | | |
49 | 65 | | |
50 | | - | |
| 66 | + | |
51 | 67 | | |
52 | 68 | | |
53 | | - | |
54 | | - | |
55 | 69 | | |
56 | 70 | | |
57 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
1388 | 1389 | | |
1389 | 1390 | | |
1390 | 1391 | | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
1391 | 1433 | | |
1392 | 1434 | | |
1393 | 1435 | | |
| |||
Lines changed: 52 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
0 commit comments