[Mesa-dev] [PATCH v2 00/11] GLSL Copy Propagation

Caio Marcelo de Oliveira Filho caio.oliveira at intel.com
Mon Jul 9 17:53:14 UTC 2018

This series contains improvements to GLSL copy (and constant)
propagation. In most cases the numbers do not change (at least in the
Intel configurations I've tested) because the NIR passes pick up the

It all started with the patches "don't let an 'if' ...", which are
about cases like

    b = a;
    if (...) {
        c = b * 2; // This 'b' gets replaced with 'a'.
        b = 1;
    } else {
        c = b * 3; // This 'b' doesn't get replaced with 'a'.

where the then-branch and the else-branch get treated differently for
no particular reason. This happens because the "kill" in the
then-branch was causing 'b' to not be available in the else-branch.

These are relatively simple fixes in constant and copy propagation,
but in opt_copy_propagation_elements.cpp, we need to provide a proper
way to "clone" the data structures used there. To achieve that I've
ended up proposing a change to those data structures.

The first three patches are less intrusive, and could be considered
independently. Then the next six patches change how
opt_copy_propagation_elements.cpp work, ending with the "don't let an
'if' ..." for it.

The last two patches teach the opt_copy_propagation_elements.cpp how
to handle whole variables and remove opt_copy_propagation.cpp. I'm
marking those as RFC since I just made them work (hopefully) correctly
and didn't care much about performance. There are some low hanging
fruits but I'll invest only if there's interest.

Because NIR passes pick up most of the slack, another reasonable
approach could be just stick some comments in the GLSL passes about
the "if/else" case. So I don't mind doing that either.

v2: Adds some commentary about memory allocation.
    Adds unit tests for util/set changes (Eric Anholt).

Caio Marcelo de Oliveira Filho (11):
  glsl: don't let an 'if' then-branch kill const propagation for
  glsl: do second pass of const propagation in loops
  glsl: don't let an 'if' then-branch kill copy propagation for
  glsl: separate copy propagation state
  util/set: add a basic unit test
  util/set: add a clone function
  util/set: helper to remove entry by key
  glsl: change opt_copy_propagation_elements data structures
  glsl: don't let an 'if' then-branch kill copy propagation (elements)
    for else-branch
  glsl: teach copy_propagation_elements to deal with whole variables
  glsl: use only copy_propagation_elements

 src/compiler/Makefile.sources                 |   1 -
 src/compiler/glsl/glsl_parser_extras.cpp      |   1 -
 src/compiler/glsl/ir_optimization.h           |   1 -
 src/compiler/glsl/meson.build                 |   1 -
 .../glsl/opt_constant_propagation.cpp         |  72 ++-
 src/compiler/glsl/opt_copy_propagation.cpp    | 369 -------------
 .../glsl/opt_copy_propagation_elements.cpp    | 519 +++++++++++-------
 src/compiler/glsl/test_optpass.cpp            |   2 -
 src/util/Makefile.am                          |   3 +-
 src/util/meson.build                          |   1 +
 src/util/set.c                                |  32 ++
 src/util/set.h                                |   5 +
 src/util/tests/set/Makefile.am                |  42 ++
 src/util/tests/set/meson.build                |  30 +
 src/util/tests/set/set_test.cpp               | 115 ++++
 15 files changed, 591 insertions(+), 603 deletions(-)
 delete mode 100644 src/compiler/glsl/opt_copy_propagation.cpp
 create mode 100644 src/util/tests/set/Makefile.am
 create mode 100644 src/util/tests/set/meson.build
 create mode 100644 src/util/tests/set/set_test.cpp


More information about the mesa-dev mailing list