broadcom/compiler: add more lowerings/optimizations on v3d_optimize_nir
authorAlejandro Piñeiro <apinheiro@igalia.com>
Mon, 13 Jun 2022 10:43:12 +0000 (12:43 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 26 Oct 2022 12:29:30 +0000 (12:29 +0000)
commit0bf31b0710f10da51d5cfea1d1050bb30b1f51b7
treec7a293d7ae23579d7668674f3f77ad0a7e4ee718
parent9cbc3ab239f08b54115f2449d5dfef153b8d5111
broadcom/compiler: add more lowerings/optimizations on v3d_optimize_nir

Optimizations that we are already calling on the Vulkan driver. As
preparation to the Vulkan frontend to use v3d_optimize_nir too.

We need to add a new parameter to v3d_optimize_nir in order to know if
we can call nir_opt_find_array_copies. As we don't track if we are
calling nir_var_lower_copies, we explicitly call it when we create the
uncompiled shader create. So instead of tracking, we assume that each
driver (v3d/v3dv) would call it when the shader is created. So when
v3d_optimize_nir is called as part of the process to compile it at the
compiler, we call it with allow_copies as false.

We exclude on purpose nir_opt_gcm as it is a case of a optimization
that could help performance even if it hurts shader db stats.

shaderdb stats:
  total instructions in shared programs: 11705923 -> 11705034 (<.01%)
  instructions in affected programs: 88350 -> 87461 (-1.01%)
  helped: 201
  HURT: 80
  Instructions are helped.

  total threads in shared programs: 375552 -> 375558 (<.01%)
  threads in affected programs: 6 -> 12 (100.00%)
  helped: 3
  HURT: 0

  total uniforms in shared programs: 3486108 -> 3485789 (<.01%)
  uniforms in affected programs: 7473 -> 7154 (-4.27%)
  helped: 90
  HURT: 1
  Uniforms are helped.

  total max-temps in shared programs: 2021860 -> 2021802 (<.01%)
  max-temps in affected programs: 800 -> 742 (-7.25%)
  helped: 21
  HURT: 3
  Max-temps are helped.

  total sfu-stalls in shared programs: 19299 -> 19296 (-0.02%)
  sfu-stalls in affected programs: 18 -> 15 (-16.67%)
  helped: 10
  HURT: 7
  Inconclusive result (value mean confidence interval includes 0).

  total inst-and-stalls in shared programs: 11725222 -> 11724330 (<.01%)
  inst-and-stalls in affected programs: 88402 -> 87510 (-1.01%)
  helped: 201
  HURT: 80
  Inst-and-stalls are helped.

  total nops in shared programs: 269674 -> 269386 (-0.11%)
  nops in affected programs: 3641 -> 3353 (-7.91%)
  helped: 103
  HURT: 29
  Nops are helped.

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17185>
src/broadcom/compiler/nir_to_vir.c
src/broadcom/compiler/v3d_compiler.h
src/broadcom/compiler/vir.c
src/gallium/drivers/v3d/v3d_program.c