Skip to content

agx: Schedule for register pressure

Alyssa Rosenzweig requested to merge alyssa/mesa:agx/sched-pressure into main

What does this MR do and why?

agx: Schedule for register pressure

Since we register allocate in SSA, the number of registers required (register demand) equals to the maximum number of simultaneous live values (register pressure). So if we can reduce register pressure, we are guaranteed to reduce register demand. Even an ineffective heuristic like randomly swapping instructions can only reduce pressure as long as it's conservative.

This implements one such heuristic: in each block, schedule backwards select the free instruction that looks like it will reduce liveness the most. In other words, the greedy algorithm to reduce register pressure. At the end of the block, if we haven't actually reduced pressure, we bail. This isn't optimal, but it's well-motivated and optimally handles special cases (like 0-source instructions).

This is based on the scheduler I originally wrote for Mali.

In my Dolphin ubershader branch, this improved performance at native 4K by 10fps (105fps->115fps) when I measured together with some other optimizations. On top of my current next, this commit alone goes (53fps->54fps) which is considerably less impressive :-p

shader-db results are a win, but not as large as we might hope. Instruction count win seems to be from the smaller live ranges being easier on RA (fewer swaps / moves). The two shaders affected for thread count are from fifa mobile, which go from 640 threads -> 1024 (full occupancy). In other words... this heuristic does an excellent job in a small subset of shaders. The Dolphin ubershader win was real, though :~)

   total instructions in shared programs: 1766635 -> 1763496 (-0.18%)
   instructions in affected programs: 445855 -> 442716 (-0.70%)
   helped: 1963
   HURT: 350
   Instructions are helped.

   total bytes in shared programs: 11597648 -> 11586924 (-0.09%)
   bytes in affected programs: 3106230 -> 3095506 (-0.35%)
   helped: 2003
   HURT: 374
   Bytes are helped.

   total halfregs in shared programs: 504609 -> 481980 (-4.48%)
   halfregs in affected programs: 138322 -> 115693 (-16.36%)
   helped: 3405
   HURT: 311
   Halfregs are helped.

   total threads in shared programs: 18839936 -> 18840704 (<.01%)
   threads in affected programs: 1280 -> 2048 (60.00%)
   helped: 2
   HURT: 0

Signed-off-by: Alyssa Rosenzweig alyssa@rosenzweig.io

Edited by Alyssa Rosenzweig

Merge request reports