Skip to content

nir/algebraic: Optimize many patterns involving isnan or isfinite

Ian Romanick requested to merge idr/mesa:review/isfinite-isnan into main

People sure are creative with ways to open-code isfinite. This doesn't cover all the possible patterns, but it does capture everything that I have observed "in the wild." With these patterns added, nothing in my fossil-db generates any X cmp X.

I was originally looking to see if there was a use for Intel's CMPN instruction. This instruction is (x cmp y) || isnan(y).

shader-db:

All Intel platforms had similar results. (Meteor Lake shown)
total instructions in shared programs: 19874221 -> 19873885 (<.01%)
instructions in affected programs: 106530 -> 106194 (-0.32%)
helped: 103 / HURT: 0

total cycles in shared programs: 936154303 -> 936141744 (<.01%)
cycles in affected programs: 14866221 -> 14853662 (-0.08%)
helped: 87 / HURT: 16

fossil-db:

All Intel platforms had similar results. (Meteor Lake shown)
Totals:
Instrs: 153527262 -> 153442540 (-0.06%); split: -0.06%, +0.00%
Cycle count: 16426316190 -> 16424941342 (-0.01%); split: -0.01%, +0.00%
Spill count: 130979 -> 130981 (+0.00%)
Fill count: 236742 -> 236740 (-0.00%); split: -0.00%, +0.00%
Max live registers: 32569234 -> 32587354 (+0.06%); split: -0.01%, +0.06%
Max dispatch width: 5545768 -> 5542440 (-0.06%); split: +0.06%, -0.12%

Totals from 63496 (10.05% of 631598) affected shaders:
Instrs: 13874124 -> 13789402 (-0.61%); split: -0.61%, +0.00%
Cycle count: 326654593 -> 325279745 (-0.42%); split: -0.64%, +0.22%
Spill count: 3014 -> 3016 (+0.07%)
Fill count: 7873 -> 7871 (-0.03%); split: -0.05%, +0.03%
Max live registers: 3686647 -> 3704767 (+0.49%); split: -0.06%, +0.55%
Max dispatch width: 650080 -> 646752 (-0.51%); split: +0.51%, -1.02%

Merge request reports