ac/llvm: add ac_build_canonicalize() helper
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 14 Oct 2019 12:23:35 +0000 (14:23 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 18 Oct 2019 14:55:48 +0000 (16:55 +0200)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/llvm/ac_llvm_build.c
src/amd/llvm/ac_llvm_build.h
src/amd/llvm/ac_nir_to_llvm.c

index cda2daab6f51be2c63ce34c0cdc83c4028460a28..87adf2b44324549d941e72739d0f9bbcbc271463 100644 (file)
@@ -4369,6 +4369,31 @@ ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0,
                                  AC_FUNC_ATTR_READNONE);
 }
 
+LLVMValueRef
+ac_build_canonicalize(struct ac_llvm_context *ctx, LLVMValueRef src0,
+                     unsigned bitsize)
+{
+       LLVMTypeRef type;
+       char *intr;
+
+       if (bitsize == 16) {
+               intr = "llvm.canonicalize.f16";
+               type = ctx->f16;
+       } else if (bitsize == 32) {
+               intr = "llvm.canonicalize.f32";
+               type = ctx->f32;
+       } else if (bitsize == 64) {
+               intr = "llvm.canonicalize.f64";
+               type = ctx->f64;
+       }
+
+       LLVMValueRef params[] = {
+               src0,
+       };
+       return ac_build_intrinsic(ctx, intr, type, params, 1,
+                                 AC_FUNC_ATTR_READNONE);
+}
+
 /*
  * this takes an I,J coordinate pair,
  * and works out the X and Y derivatives.
index 013bf00041ac5876db24c1624b09f57abbfd1010..a67e1d49d4d48faa4c63afbe5af17027cb80ca58 100644 (file)
@@ -715,6 +715,10 @@ LLVMValueRef
 ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0,
                    unsigned bitsize);
 
+LLVMValueRef
+ac_build_canonicalize(struct ac_llvm_context *ctx, LLVMValueRef src0,
+                     unsigned bitsize);
+
 LLVMValueRef
 ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij);
 
index b08483e5cf4e8e25bc5c54100107deca2caf6232..ab042d360835981a2976c8725041b3ad93f3bb96 100644 (file)
@@ -740,9 +740,8 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                if (ctx->ac.chip_class < GFX9 &&
                    instr->dest.dest.ssa.bit_size == 32) {
                        /* Only pre-GFX9 chips do not flush denorms. */
-                       result = emit_intrin_1f_param(&ctx->ac, "llvm.canonicalize",
-                                                     ac_to_float_type(&ctx->ac, def_type),
-                                                     result);
+                       result = ac_build_canonicalize(&ctx->ac, result,
+                                                      instr->dest.dest.ssa.bit_size);
                }
                break;
        case nir_op_fmin:
@@ -751,9 +750,8 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                if (ctx->ac.chip_class < GFX9 &&
                    instr->dest.dest.ssa.bit_size == 32) {
                        /* Only pre-GFX9 chips do not flush denorms. */
-                       result = emit_intrin_1f_param(&ctx->ac, "llvm.canonicalize",
-                                                     ac_to_float_type(&ctx->ac, def_type),
-                                                     result);
+                       result = ac_build_canonicalize(&ctx->ac, result,
+                                                      instr->dest.dest.ssa.bit_size);
                }
                break;
        case nir_op_ffma: