ac: revert new LLVM 7.0 behavior for fdiv
authorMarek Olšák <marek.olsak@amd.com>
Sat, 25 Aug 2018 03:00:37 +0000 (23:00 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 10 Sep 2018 19:19:56 +0000 (15:19 -0400)
Cc: 18.2 <mesa-stable@lists.freedesktop.org>
Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de>
src/amd/common/ac_llvm_build.c

index c741a1ab62d9b93b22bbe35890364d02eac9613f..629cd2a7527a4fcd469e18be1b071c4b95c842b9 100644 (file)
@@ -561,7 +561,14 @@ ac_build_fdiv(struct ac_llvm_context *ctx,
              LLVMValueRef num,
              LLVMValueRef den)
 {
-       LLVMValueRef ret = LLVMBuildFDiv(ctx->builder, num, den, "");
+       /* If we do (num / den), LLVM >= 7.0 does:
+        *    return num * v_rcp_f32(den * (fabs(den) > 0x1.0p+96f ? 0x1.0p-32f : 1.0f));
+        *
+        * If we do (num * (1 / den)), LLVM does:
+        *    return num * v_rcp_f32(den);
+        */
+       LLVMValueRef rcp = LLVMBuildFDiv(ctx->builder, ctx->f32_1, den, "");
+       LLVMValueRef ret = LLVMBuildFMul(ctx->builder, num, rcp, "");
 
        /* Use v_rcp_f32 instead of precise division. */
        if (!LLVMIsConstant(ret))