Skip to content

nir/algebraic: Use udiv for source of txf

Ian Romanick requested to merge idr/mesa:review/udiv-for-txf into main

Many of the shaders in various Civilization games use a 4Kx4K texture to emulate a large TexBO. This texture is accessed using a pattern like:

texelFetch(..., vec2(index % 4096, index / 4096));

Unfortunately, index is declared as an int, so idiv is used to implement the division. This leads to suboptimal optimization of the division by a constant. Replacing the idiv with udiv leads to some dramatic improvements.

All of the shaders affected are in Civilization VI or Civilization Beyond Earth.

No fossil-db changes on any Intel platform.

Tiger Lake, Ice Lake, and Skylake had similar results. (Ice Lake shown)
Ice Lake
total instructions in shared programs: 19945897 -> 19932187 (-0.07%)
instructions in affected programs: 66348 -> 52638 (-20.66%)
helped: 110
HURT: 0
helped stats (abs) min: 12 max: 516 x̄: 124.64 x̃: 126
helped stats (rel) min: 6.45% max: 43.32% x̄: 21.56% x̃: 18.86%
95% mean confidence interval for instructions value: -146.20 -103.08
95% mean confidence interval for instructions %-change: -23.20% -19.92%
Instructions are helped.

total cycles in shared programs: 858774298 -> 858435366 (-0.04%)
cycles in affected programs: 1974486 -> 1635554 (-17.17%)
helped: 108
HURT: 2
helped stats (abs) min: 40 max: 98748 x̄: 3145.02 x̃: 687
helped stats (rel) min: 1.28% max: 57.28% x̄: 8.89% x̃: 6.63%
HURT stats (abs)   min: 80 max: 650 x̄: 365.00 x̃: 365
HURT stats (rel)   min: 0.39% max: 23.41% x̄: 11.90% x̃: 11.90%
95% mean confidence interval for cycles value: -5571.49 -590.91
95% mean confidence interval for cycles %-change: -10.58% -6.44%
Cycles are helped.

LOST:   0
GAINED: 5

Broadwell
total instructions in shared programs: 17826441 -> 17817433 (-0.05%)
instructions in affected programs: 61716 -> 52708 (-14.60%)
helped: 108
HURT: 0
helped stats (abs) min: 8 max: 344 x̄: 83.41 x̃: 84
helped stats (rel) min: 5.10% max: 28.57% x̄: 15.23% x̃: 13.12%
95% mean confidence interval for instructions value: -98.24 -68.57
95% mean confidence interval for instructions %-change: -16.37% -14.10%
Instructions are helped.

total cycles in shared programs: 904824765 -> 904261086 (-0.06%)
cycles in affected programs: 2734531 -> 2170852 (-20.61%)
helped: 106
HURT: 2
helped stats (abs) min: 3 max: 87147 x̄: 5318.56 x̃: 505
helped stats (rel) min: 0.11% max: 67.09% x̄: 8.53% x̃: 5.04%
HURT stats (abs)   min: 26 max: 62 x̄: 44.00 x̃: 44
HURT stats (rel)   min: 0.41% max: 1.66% x̄: 1.04% x̃: 1.04%
95% mean confidence interval for cycles value: -8687.19 -1751.31
95% mean confidence interval for cycles %-change: -11.09% -5.61%
Cycles are helped.

total spills in shared programs: 17882 -> 17879 (-0.02%)
spills in affected programs: 66 -> 63 (-4.55%)
helped: 3
HURT: 0

total fills in shared programs: 25531 -> 25507 (-0.09%)
fills in affected programs: 87 -> 63 (-27.59%)
helped: 3
HURT: 0

Haswell and Ivy Bridge had similar results. (Haswell shown)
total instructions in shared programs: 16711930 -> 16700652 (-0.07%)
instructions in affected programs: 61671 -> 50393 (-18.29%)
helped: 108
HURT: 0
helped stats (abs) min: 12 max: 310 x̄: 104.43 x̃: 126
helped stats (rel) min: 7.45% max: 42.06% x̄: 19.13% x̃: 15.03%
95% mean confidence interval for instructions value: -120.62 -88.24
95% mean confidence interval for instructions %-change: -20.89% -17.38%
Instructions are helped.

total cycles in shared programs: 881120952 -> 880257804 (-0.10%)
cycles in affected programs: 2930681 -> 2067533 (-29.45%)
helped: 94
HURT: 14
helped stats (abs) min: 32 max: 86820 x̄: 9300.83 x̃: 2080
helped stats (rel) min: 1.09% max: 66.39% x̄: 15.54% x̃: 7.77%
HURT stats (abs)   min: 22 max: 2324 x̄: 795.00 x̃: 598
HURT stats (rel)   min: 0.36% max: 41.00% x̄: 14.66% x̃: 9.34%
95% mean confidence interval for cycles value: -12241.97 -3742.25
95% mean confidence interval for cycles %-change: -15.60% -7.65%
Cycles are helped.

total spills in shared programs: 14937 -> 14925 (-0.08%)
spills in affected programs: 12 -> 0
helped: 9
HURT: 0

total fills in shared programs: 17569 -> 17557 (-0.07%)
fills in affected programs: 12 -> 0
helped: 9
HURT: 0

Sandy Bridge
total instructions in shared programs: 13909126 -> 13906406 (-0.02%)
instructions in affected programs: 11469 -> 8749 (-23.72%)
helped: 31
HURT: 0
helped stats (abs) min: 13 max: 301 x̄: 87.74 x̃: 28
helped stats (rel) min: 6.01% max: 40.89% x̄: 21.95% x̃: 18.55%
95% mean confidence interval for instructions value: -127.20 -48.29
95% mean confidence interval for instructions %-change: -25.97% -17.92%
Instructions are helped.

total cycles in shared programs: 741019966 -> 741006472 (<.01%)
cycles in affected programs: 459434 -> 445940 (-2.94%)
helped: 26
HURT: 4
helped stats (abs) min: 14 max: 2664 x̄: 594.77 x̃: 150
helped stats (rel) min: 0.25% max: 18.22% x̄: 3.50% x̃: 1.76%
HURT stats (abs)   min: 16 max: 1914 x̄: 492.50 x̃: 20
HURT stats (rel)   min: 0.33% max: 85.29% x̄: 21.61% x̃: 0.40%
95% mean confidence interval for cycles value: -770.92 -128.68
95% mean confidence interval for cycles %-change: -6.44% 6.13%
Inconclusive result (%-change mean confidence interval includes 0).

No shader-db changes on any other Intel platform.

Merge request reports