ac/llvm,radv: implement uadd_sat/iadd_sat
authorRhys Perry <pendingchaos02@gmail.com>
Mon, 30 Aug 2021 13:02:38 +0000 (14:02 +0100)
committerMarge Bot <eric+marge@anholt.net>
Fri, 3 Sep 2021 13:21:27 +0000 (13:21 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12617>

src/amd/llvm/ac_nir_to_llvm.c
src/amd/vulkan/radv_pipeline.c

index c25c677..804a1dc 100644 (file)
@@ -626,6 +626,15 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
       else
          result = LLVMBuildAdd(ctx->ac.builder, src[0], src[1], "");
       break;
+   case nir_op_uadd_sat:
+   case nir_op_iadd_sat: {
+      char name[64], type[64];
+      ac_build_type_name_for_intr(def_type, type, sizeof(type));
+      snprintf(name, sizeof(name), "llvm.%cadd.sat.%s",
+               instr->op == nir_op_uadd_sat ? 'u' : 's', type);
+      result = ac_build_intrinsic(&ctx->ac, name, def_type, src, 2, AC_FUNC_ATTR_READNONE);
+      break;
+   }
    case nir_op_fadd:
       src[0] = ac_to_float(&ctx->ac, src[0]);
       src[1] = ac_to_float(&ctx->ac, src[1]);
index 2f39744..3b01545 100644 (file)
@@ -3495,9 +3495,7 @@ radv_create_shaders(struct radv_pipeline *pipeline, struct radv_device *device,
          /* lower ALU operations */
          nir_lower_int64(nir[i]);
 
-         /* TODO: Implement nir_op_uadd_sat with LLVM. */
-         if (!radv_use_llvm_for_stage(device, i))
-            nir_opt_idiv_const(nir[i], 8);
+         nir_opt_idiv_const(nir[i], 8);
 
          nir_lower_idiv(nir[i],
                         &(nir_lower_idiv_options){