Skip to content

nir/rematerialize: Rematerialize ALUs used only by compares with zero

Ian Romanick requested to merge idr/mesa:review/rematerialize-alus-too into main

This was 4th on the list of things to try in 3ee2e84c ("nir: Rematerialize compare instructions"). This is implemented as a separate subpass that tries to find ALU instructions (with restrictions) that are only used by comparisons with zero that are in turn only used as conditions for bcsel or if-statements.

There are two restrictions implemented. One of the sources must be a constant. This is done in an attempt to prevent increasing register pressure. Additionally, the opcode of the instruction must be one that has a high probablility of getting a conditional modifier on Intel GPUs. Not all instructions can have a conditional modifiers (e.g., min and max), so I don't think there is any benefit to moving these instructions.

Tiger Lake and Ice Lake had similar results. (Ice Lake shown)
total instructions in shared programs: 20250575 -> 20250300 (<.01%)
instructions in affected programs: 137660 -> 137385 (-0.20%)
helped: 166 / HURT: 0

total cycles in shared programs: 891849641 -> 891873121 (<.01%)
cycles in affected programs: 71217225 -> 71240705 (0.03%)
helped: 163 / HURT: 137

LOST:   0
GAINED: 1

Skylake
total instructions in shared programs: 18360738 -> 18360384 (<.01%)
instructions in affected programs: 130218 -> 129864 (-0.27%)
helped: 166 / HURT: 0

total cycles in shared programs: 877729788 -> 877499977 (-0.03%)
cycles in affected programs: 70055322 -> 69825511 (-0.33%)
helped: 195 / HURT: 102

total spills in shared programs: 6969 -> 6966 (-0.04%)
spills in affected programs: 168 -> 165 (-1.79%)
helped: 3 / HURT: 0

total fills in shared programs: 9599 -> 9563 (-0.38%)
fills in affected programs: 261 -> 225 (-13.79%)
helped: 3 / HURT: 0

LOST:   0
GAINED: 1

Broadwell
total instructions in shared programs: 18149445 -> 18148880 (<.01%)
instructions in affected programs: 135954 -> 135389 (-0.42%)
helped: 166 / HURT: 0

total cycles in shared programs: 939493074 -> 938494446 (-0.11%)
cycles in affected programs: 64865752 -> 63867124 (-1.54%)
helped: 171 / HURT: 105

total spills in shared programs: 18017 -> 17966 (-0.28%)
spills in affected programs: 1199 -> 1148 (-4.25%)
helped: 13 / HURT: 0

total fills in shared programs: 25916 -> 25830 (-0.33%)
fills in affected programs: 1405 -> 1319 (-6.12%)
helped: 13 / HURT: 0

Haswell
total instructions in shared programs: 17027530 -> 17027204 (<.01%)
instructions in affected programs: 110467 -> 110141 (-0.30%)
helped: 96 / HURT: 1

total cycles in shared programs: 921412692 -> 921083608 (-0.04%)
cycles in affected programs: 27979682 -> 27650598 (-1.18%)
helped: 106 / HURT: 90

total spills in shared programs: 15176 -> 15157 (-0.13%)
spills in affected programs: 504 -> 485 (-3.77%)
helped: 7 / HURT: 0

total fills in shared programs: 18021 -> 17969 (-0.29%)
fills in affected programs: 581 -> 529 (-8.95%)
helped: 7 / HURT: 0

LOST:   0
GAINED: 1

Ivy Bridge
total instructions in shared programs: 15864771 -> 15864618 (<.01%)
instructions in affected programs: 78362 -> 78209 (-0.20%)

total cycles in shared programs: 453016438 -> 452913180 (-0.02%)
cycles in affected programs: 12576985 -> 12473727 (-0.82%)
helped: 80 / HURT: 61

Sandy Bridge
total instructions in shared programs: 14061162 -> 14061146 (<.01%)
instructions in affected programs: 1617 -> 1601 (-0.99%)
helped: 10 / HURT: 0

total cycles in shared programs: 772320674 -> 772317758 (<.01%)
cycles in affected programs: 2664571 -> 2661655 (-0.11%)
helped: 61 / HURT: 47

Iron Lake and GM45 had similar results. (Iron Lake shown)
total cycles in shared programs: 249526662 -> 249528258 (<.01%)
cycles in affected programs: 2926424 -> 2928020 (0.05%)
helped: 10 / HURT: 105

Tiger Lake
Instructions in all programs: 160677329 -> 160651624 (-0.0%)
helped: 8208 / HURT: 5364

Cycles in all programs: 7585168038 -> 7586462880 (+0.0%)
helped: 7699 / HURT: 6976

Spills in all programs: 11437 -> 11221 (-1.9%)
helped: 33

Fills in all programs: 19721 -> 19516 (-1.0%)
helped: 19

Ice Lake and Skylake had similar results. (Ice Lake shown)
Instructions in all programs: 144734895 -> 144705402 (-0.0%)
helped: 14570

Cycles in all programs: 9170741954 -> 9169590664 (-0.0%)
helped: 10026 / HURT: 4216

Spills in all programs: 18216 -> 18012 (-1.1%)
Spills helped: 19

Fills in all programs: 30074 -> 29855 (-0.7%)
Fills helped: 19

Merge request reports