ir3/sched: Speed up live_effect
authorConnor Abbott <cwabbott0@gmail.com>
Tue, 1 Jun 2021 16:18:14 +0000 (18:18 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 28 Jun 2021 16:26:24 +0000 (16:26 +0000)
If we've identified another use that isn't scheduled yet, we can break
right away rather than iterating through all the other uses. While this
could be optimized further, this simple change makes
dEQP-VK.subgroups.ballot_broadcast.compute.subgroupbroadcast_ivec4 go
from 40 seconds to 1.9 seconds on a release build according to my
unscientific testing.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11613>

src/freedreno/ir3/ir3_sched.c

index 7900af1..69281d3 100644 (file)
@@ -486,14 +486,15 @@ nearest_use(struct ir3_instruction *instr)
        return nearest;
 }
 
-static int
-use_count(struct ir3_instruction *instr)
+static bool
+is_only_nonscheduled_use(struct ir3_instruction *instr, struct ir3_instruction *use)
 {
-       unsigned cnt = 0;
-       foreach_ssa_use (use, instr)
-               if (!is_scheduled(use))
-                       cnt++;
-       return cnt;
+       foreach_ssa_use (other_use, instr) {
+               if (other_use != use && !is_scheduled(other_use))
+                       return false;
+       }
+
+       return true;
 }
 
 /* find net change to live values if instruction were scheduled: */
@@ -517,7 +518,7 @@ live_effect(struct ir3_instruction *instr)
                if (instr->block != src->block)
                        continue;
 
-               if (use_count(src) == 1)
+               if (is_only_nonscheduled_use(src, instr))
                        freed_live += dest_regs(src);
        }