From 66426ce119b3b647f9ace62b74f18342cacd43a4 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 25 Mar 2020 18:17:06 +0100 Subject: [PATCH 1/1] ac/nir: use llvm.amdgcn.rcp for nir_op_frcp MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Instead of emitting 1.0 / x which includes a slow division that LLVM doesn't always optimize even if the metadata is correctly set. pipeline-db (VEG10/LLVM 9): Totals from affected shaders: SGPRS: 50384 -> 50312 (-0.14 %) VGPRS: 42572 -> 42696 (0.29 %) Spilled SGPRs: 1372 -> 1372 (0.00 %) Code Size: 5692040 -> 5691428 (-0.01 %) bytes Max Waves: 3954 -> 3951 (-0.08 %) pipeline-db (VEG10/LLVM 10): Totals from affected shaders: SGPRS: 78512 -> 78464 (-0.06 %) VGPRS: 62408 -> 62484 (0.12 %) Spilled SGPRs: 1502 -> 1502 (0.00 %) Code Size: 8106188 -> 8103372 (-0.03 %) bytes Max Waves: 7759 -> 7753 (-0.08 %) pipeline-db (VEGA10/LLVM 11 - 92744f62478): Totals from affected shaders: SGPRS: 112760 -> 113232 (0.42 %) VGPRS: 111132 -> 110568 (-0.51 %) Spilled SGPRs: 5870 -> 5940 (1.19 %) Spilled VGPRs: 650 -> 652 (0.31 %) Code Size: 11887232 -> 11561744 (-2.74 %) bytes Max Waves: 8964 -> 9015 (0.57 %) LLVM 11 (master) is more affected than previous versions, but based on the small impact with LLVM 9/10, I decided to emit it unconditionally. Cc: 20.0 Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Reviewed-by: Marek Olšák Part-of: --- src/amd/llvm/ac_nir_to_llvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index 871c6abc17f..1e7e9511693 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -688,8 +688,8 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr) result = LLVMBuildFMul(ctx->ac.builder, src[0], src[1], ""); break; case nir_op_frcp: - src[0] = ac_to_float(&ctx->ac, src[0]); - result = ac_build_fdiv(&ctx->ac, LLVMConstReal(LLVMTypeOf(src[0]), 1.0), src[0]); + result = emit_intrin_1f_param(&ctx->ac, "llvm.amdgcn.rcp", + ac_to_float_type(&ctx->ac, def_type), src[0]); break; case nir_op_iand: result = LLVMBuildAnd(ctx->ac.builder, src[0], src[1], ""); -- 2.30.2