Module: Mesa
Branch: main
Commit: 2d928c7fee5f6c797c2cde6a9605305b31bfb1ce
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=2d928c7fee5f6c797c2cde6a9605305b31bfb1ce

Author: Marek Olšák <[email protected]>
Date:   Wed Aug  2 20:24:04 2023 -0400

ac/llvm: set !fpmath 3.0 for llvm.sqrt

LLVM will be changed to increase precision with additional instructions,
which we don't want.

Reviewed-by: Timur Kristóf <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25492>

---

 src/amd/llvm/ac_llvm_build.c  | 7 +++++--
 src/amd/llvm/ac_llvm_build.h  | 2 ++
 src/amd/llvm/ac_nir_to_llvm.c | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/amd/llvm/ac_llvm_build.c b/src/amd/llvm/ac_llvm_build.c
index 6aa6ce1f7e5..f532c64b17d 100644
--- a/src/amd/llvm/ac_llvm_build.c
+++ b/src/amd/llvm/ac_llvm_build.c
@@ -100,12 +100,15 @@ void ac_llvm_context_init(struct ac_llvm_context *ctx, 
struct ac_llvm_compiler *
    ctx->i1true = LLVMConstInt(ctx->i1, 1, false);
 
    ctx->range_md_kind = LLVMGetMDKindIDInContext(ctx->context, "range", 5);
-
    ctx->invariant_load_md_kind = LLVMGetMDKindIDInContext(ctx->context, 
"invariant.load", 14);
-
    ctx->uniform_md_kind = LLVMGetMDKindIDInContext(ctx->context, 
"amdgpu.uniform", 14);
+   ctx->fpmath_md_kind = LLVMGetMDKindIDInContext(ctx->context, "fpmath", 6);
 
    ctx->empty_md = LLVMMDNodeInContext(ctx->context, NULL, 0);
+
+   LLVMValueRef three = LLVMConstReal(ctx->f32, 3);
+   ctx->three_md = LLVMMDNodeInContext(ctx->context, &three, 1);
+
    ctx->flow = calloc(1, sizeof(*ctx->flow));
 
    ctx->ring_offsets_index = INT32_MAX;
diff --git a/src/amd/llvm/ac_llvm_build.h b/src/amd/llvm/ac_llvm_build.h
index 00ce0a9ed39..bede3ff2e0e 100644
--- a/src/amd/llvm/ac_llvm_build.h
+++ b/src/amd/llvm/ac_llvm_build.h
@@ -121,7 +121,9 @@ struct ac_llvm_context {
    unsigned range_md_kind;
    unsigned invariant_load_md_kind;
    unsigned uniform_md_kind;
+   unsigned fpmath_md_kind;
    LLVMValueRef empty_md;
+   LLVMValueRef three_md;
 
    const struct radeon_info *info;
    enum amd_gfx_level gfx_level;
diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c
index 2583544040b..b0a335fb881 100644
--- a/src/amd/llvm/ac_nir_to_llvm.c
+++ b/src/amd/llvm/ac_nir_to_llvm.c
@@ -801,6 +801,7 @@ static bool visit_alu(struct ac_nir_context *ctx, const 
nir_alu_instr *instr)
    case nir_op_fsqrt:
       result =
          emit_intrin_1f_param(&ctx->ac, "llvm.sqrt", 
ac_to_float_type(&ctx->ac, def_type), src[0]);
+      LLVMSetMetadata(result, ctx->ac.fpmath_md_kind, ctx->ac.three_md);
       break;
    case nir_op_fexp2:
       result =

Reply via email to