Module: Mesa Branch: master Commit: 89c4bba8bce40edbb621af9ddc121ea498658338 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=89c4bba8bce40edbb621af9ddc121ea498658338
Author: Rhys Perry <[email protected]> Date: Fri Jun 19 11:30:27 2020 +0100 nir/algebraic: better propagate constants up fadd chains Make the optimization create more mad-friendly code if the order of the fadd's operands is unlucky. fossil-db (Navi): Totals from 9259 (8.07% of 114665) affected shaders: SGPRs: 615991 -> 616191 (+0.03%); split: -0.05%, +0.08% VGPRs: 442184 -> 443568 (+0.31%); split: -0.10%, +0.41% CodeSize: 32674876 -> 32625572 (-0.15%); split: -0.17%, +0.02% MaxWaves: 108560 -> 108152 (-0.38%); split: +0.07%, -0.44% Instrs: 6126473 -> 6120463 (-0.10%); split: -0.13%, +0.03% Signed-off-by: Rhys Perry <[email protected]> Reviewed-by: Marek Olšák <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5631> --- .gitlab-ci/traces-virgl.yml | 2 +- src/compiler/nir/nir_opt_algebraic.py | 2 ++ src/compiler/nir/nir_search_helpers.h | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci/traces-virgl.yml b/.gitlab-ci/traces-virgl.yml index 86154abfbf1..4e27a3c498b 100644 --- a/.gitlab-ci/traces-virgl.yml +++ b/.gitlab-ci/traces-virgl.yml @@ -21,7 +21,7 @@ traces: - path: gputest/pixmark-piano.trace expectations: - device: gl-virgl - checksum: 43b2c4db0d6810cca945071b9a645561 + checksum: 8293e59b818715ddf1c23e9f60b17851 - path: gputest/triangle.trace expectations: - device: gl-virgl diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 973656595cb..d095591f37b 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1241,6 +1241,8 @@ optimizations.extend([ # Propagate constants up multiplication chains (('~fmul(is_used_once)', ('fmul(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), '#c'), ('fmul', ('fmul', a, c), b)), (('imul(is_used_once)', ('imul(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), '#c'), ('imul', ('imul', a, c), b)), + # Prefer moving out a multiplication for more MAD/FMA-friendly code + (('~fadd(is_used_once)', ('fadd(is_used_once)', 'a(is_not_const)', 'b(is_fmul)'), '#c'), ('fadd', ('fadd', a, c), b)), (('~fadd(is_used_once)', ('fadd(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), '#c'), ('fadd', ('fadd', a, c), b)), (('iadd(is_used_once)', ('iadd(is_used_once)', 'a(is_not_const)', 'b(is_not_const)'), '#c'), ('iadd', ('iadd', a, c), b)), diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h index abfd660ae79..ef3e6526682 100644 --- a/src/compiler/nir/nir_search_helpers.h +++ b/src/compiler/nir/nir_search_helpers.h @@ -225,6 +225,22 @@ is_not_fmul(struct hash_table *ht, nir_alu_instr *instr, unsigned src, return src_alu->op != nir_op_fmul; } +static inline bool +is_fmul(struct hash_table *ht, nir_alu_instr *instr, unsigned src, + UNUSED unsigned num_components, UNUSED const uint8_t *swizzle) +{ + nir_alu_instr *src_alu = + nir_src_as_alu_instr(instr->src[src].src); + + if (src_alu == NULL) + return false; + + if (src_alu->op == nir_op_fneg) + return is_fmul(ht, src_alu, 0, 0, NULL); + + return src_alu->op == nir_op_fmul; +} + static inline bool is_fsign(nir_alu_instr *instr, unsigned src, UNUSED unsigned num_components, UNUSED const uint8_t *swizzle) _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
