Skip to content

nir: Combine if_uses with instruction uses

Alyssa Rosenzweig requested to merge alyssa/mesa:nir/remove-if-uses into main

Every nir_ssa_def is part of a chain of uses, implemented with doubly linked lists. That means each requires 2 * 64-bit = 16 bytes per def, which is memory intensive. Together they require 32 bytes per def. Not cool.

To cut that memory use in half, we can combine the two linked lists into a single use list that contains both regular instruction uses and if-uses. To do this, we augment the nir_src with a boolean "is_if", and reimplement the abstract if-uses operations on top of that list. That boolean should fit into the padding already in nir_src so should not actually affect memory use, and in the future we sneak it into the bottom bit of a pointer.

However, this creates a new inefficiency: now iterating over regular uses separate from if-uses is (nominally) more expensive. It turns out virtually every caller of nir_foreach_if_use(_safe) also calls nir_foreach_use(_safe) immediately before, so we rewrite most of the callers to instead call a new single nir_foreach_use_including_if(_safe) which predicates the logic based on src->is_if. This should mitigate the performance difference.

There's a bit of churn, but this is largely a mechanical set of changes.


Emma reports (from first version of this MR):

steam shader-db runtime -6.3328% +/- 1.52813% here. Congrats!

Edited by Alyssa Rosenzweig

Merge request reports