nir: spir-v: First batch of NaN-related fixes
The big change in this series is setting the "exact" flag on comparisons generated from SPIR-V shaders. The other commits in the series either support this change (by preventing / fixing some regressions), document some other NaN-related behavior, or fix some other issues.
OpenGL GLSL, OpenGL ARB assembly shaders, and DX9 are pretty loose about the behavior in the presense of NaNs. Many GPUs that implement these specifications do not even have a representation of NaN. However, OpenCL and Vulkan SPIR-V are not so lax. Both actually have some required behavior in the presense of NaN, and, of the two, OpenCL is the most strict.
For years we have implemented SPIR-V by using the same comparison opcodes as we use for OpenGL GLSL and OpenGL assembly shaders. This has repeatedly caused problems where an optimization that is valid in the NaN-relaxed world is not valid in Vulkan or OpenCL. To fix this, set the "exact" flag on comparisons instructions generated from SPIR-V. This will block optimizations that may have different NaN behavior.
The overall changes across the whole series are pretty small.
shader-db on Ice Lake:
total instructions in shared programs: 19815115 -> 19814998 (<.01%)
instructions in affected programs: 10037 -> 9920 (-1.17%)
helped: 22
HURT: 5
helped stats (abs) min: 1 max: 27 x̄: 5.95 x̃: 2
helped stats (rel) min: 0.02% max: 13.71% x̄: 5.23% x̃: 2.73%
HURT stats (abs) min: 1 max: 6 x̄: 2.80 x̃: 3
HURT stats (rel) min: 1.30% max: 18.75% x̄: 10.44% x̃: 15.00%
95% mean confidence interval for instructions value: -7.56 -1.10
95% mean confidence interval for instructions %-change: -5.66% 1.01%
Inconclusive result (%-change mean confidence interval includes 0).
total cycles in shared programs: 491021519 -> 491019688 (<.01%)
cycles in affected programs: 111117 -> 109286 (-1.65%)
helped: 29
HURT: 11
helped stats (abs) min: 4 max: 684 x̄: 67.97 x̃: 12
helped stats (rel) min: 0.02% max: 35.96% x̄: 3.36% x̃: 1.29%
HURT stats (abs) min: 1 max: 48 x̄: 12.73 x̃: 4
HURT stats (rel) min: 0.06% max: 1.93% x̄: 0.62% x̃: 0.20%
95% mean confidence interval for cycles value: -93.47 1.92
95% mean confidence interval for cycles %-change: -4.36% -0.17%
Inconclusive result (value mean confidence interval includes 0).
fossil-db on Ice Lake:
Instructions in all programs: 140457761 -> 140452990 (-0.0%)
SENDs in all programs: 6530329 -> 6530329 (+0.0%)
Loops in all programs: 35267 -> 35267 (+0.0%)
Cycles in all programs: 3493572324 -> 3493260989 (-0.0%)
Spills in all programs: 242716 -> 242840 (+0.1%)
Fills in all programs: 361629 -> 361753 (+0.0%)
All of the hurt spills and fills are in Shadow of the Tomb Raider. A bunch of shaders are hurt by one spill and one fill each.
There are probably two more follow-up series in this area that are not quite ready yet.