Mesa (master): ac/llvm: open code fpow on LLVM 12 using fmul.legacy

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Mar 3 20:17:18 UTC 2021


Module: Mesa
Branch: master
Commit: a0cc0b3a154dfc4370c6eea4271d8a80c6616abb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a0cc0b3a154dfc4370c6eea4271d8a80c6616abb

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Fri Feb 12 01:06:18 2021 -0500

ac/llvm: open code fpow on LLVM 12 using fmul.legacy

A quick look at the asm shows that this enables source modifiers
(neg, abs) for v_mul_legacy_f32.

Totals from affected shaders:
SGPRS: 110104 -> 110400 (0.27 %)
VGPRS: 57632 -> 57636 (0.01 %)
Spilled SGPRs: 66 -> 63 (-4.55 %)
Spilled VGPRs: 0 -> 0 (0.00 %)
Private memory VGPRs: 0 -> 0 (0.00 %)
Scratch size: 0 -> 0 (0.00 %) dwords per thread
Code Size: 3290412 -> 3283068 (-0.22 %) bytes
Max Waves: 32141 -> 32141 (0.00 %)

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9395>

---

 src/amd/llvm/ac_nir_to_llvm.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c
index a3e84029909..789557a3252 100644
--- a/src/amd/llvm/ac_nir_to_llvm.c
+++ b/src/amd/llvm/ac_nir_to_llvm.c
@@ -852,6 +852,17 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                                        ac_to_float_type(&ctx->ac, def_type), result);
          break;
       }
+      if (LLVM_VERSION_MAJOR >= 12) {
+         result = emit_intrin_1f_param(&ctx->ac, "llvm.log2",
+                                       ac_to_float_type(&ctx->ac, def_type), src[0]);
+         result = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.fmul.legacy", ctx->ac.f32,
+                                     (LLVMValueRef[]){result, ac_to_float(&ctx->ac, src[1])},
+                                     2, AC_FUNC_ATTR_READNONE);
+         result = emit_intrin_1f_param(&ctx->ac, "llvm.exp2",
+                                       ac_to_float_type(&ctx->ac, def_type), result);
+         break;
+      }
+      /* Older LLVM doesn't have fmul.legacy. */
       result = emit_intrin_2f_param(&ctx->ac, "llvm.pow", ac_to_float_type(&ctx->ac, def_type),
                                     src[0], src[1]);
       break;



More information about the mesa-commit mailing list