ac: fix fast division
authorMarek Olšák <marek.olsak@amd.com>
Fri, 20 Mar 2020 20:35:45 +0000 (16:35 -0400)
committerMarge Bot <eric+marge@anholt.net>
Sat, 21 Mar 2020 22:34:17 +0000 (22:34 +0000)
This stopped working with LLVM 11 and might occasionally have been broken
on older LLVM, because the metadata was set on the mul, not on the rcp.

Cc: 19.3 20.0 <mesa-stable@lists.freedesktop.org>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4268>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4268>

src/amd/llvm/ac_llvm_build.c

index dcbd4efeacf2e0755291ff55fcbdf2e141105338..373eb77b4a0c35b1e9126707de98cc200929b9c2 100644 (file)
@@ -715,12 +715,11 @@ ac_build_fdiv(struct ac_llvm_context *ctx,
         */
        LLVMValueRef one = LLVMConstReal(LLVMTypeOf(num), 1.0);
        LLVMValueRef rcp = LLVMBuildFDiv(ctx->builder, one, den, "");
-       LLVMValueRef ret = LLVMBuildFMul(ctx->builder, num, rcp, "");
-
        /* Use v_rcp_f32 instead of precise division. */
-       if (!LLVMIsConstant(ret))
-               LLVMSetMetadata(ret, ctx->fpmath_md_kind, ctx->fpmath_md_2p5_ulp);
-       return ret;
+       if (!LLVMIsConstant(rcp))
+               LLVMSetMetadata(rcp, ctx->fpmath_md_kind, ctx->fpmath_md_2p5_ulp);
+
+       return LLVMBuildFMul(ctx->builder, num, rcp, "");
 }
 
 /* See fast_idiv_by_const.h. */