ac: add ac_build_umax() and use it where possible
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 10 Apr 2019 15:16:49 +0000 (17:16 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 12 Apr 2019 15:30:55 +0000 (17:30 +0200)
This changes the predicate from LessThan to Equal.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c

index 3e3ca5c7fdb36cff6a80cd556946d93f1ea0b395..6a1ba5de0e03921bc050d7faf42c7137666a9cd6 100644 (file)
@@ -2042,6 +2042,13 @@ LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a,
        return LLVMBuildSelect(ctx->builder, cmp, a, b, "");
 }
 
+LLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a,
+                          LLVMValueRef b)
+{
+       LLVMValueRef cmp = LLVMBuildICmp(ctx->builder, LLVMIntUGE, a, b, "");
+       return LLVMBuildSelect(ctx->builder, cmp, a, b, "");
+}
+
 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value)
 {
        LLVMTypeRef t = LLVMTypeOf(value);
index c3277fd2d13f400a7b63db7b042f5657477b5599..61689f6a07e46731b383f2554f10b9e74a0c3ea4 100644 (file)
@@ -443,6 +443,7 @@ LLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a,
 LLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a,
                           LLVMValueRef b);
 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
+LLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
 
 struct ac_export_args {
index 5995e001330ab370d36371d866be84d856731fd8..d983ac77ebdf050ffa2af01bef02b46b36199f65 100644 (file)
@@ -277,16 +277,6 @@ static LLVMValueRef emit_bcsel(struct ac_llvm_context *ctx,
                               ac_to_integer_or_pointer(ctx, src2), "");
 }
 
-static LLVMValueRef emit_minmax_int(struct ac_llvm_context *ctx,
-                                   LLVMIntPredicate pred,
-                                   LLVMValueRef src0, LLVMValueRef src1)
-{
-       return LLVMBuildSelect(ctx->builder,
-                              LLVMBuildICmp(ctx->builder, pred, src0, src1, ""),
-                              src0,
-                              src1, "");
-
-}
 static LLVMValueRef emit_iabs(struct ac_llvm_context *ctx,
                              LLVMValueRef src0)
 {
@@ -754,7 +744,7 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                result = ac_build_imin(&ctx->ac, src[0], src[1]);
                break;
        case nir_op_umax:
-               result = emit_minmax_int(&ctx->ac, LLVMIntUGT, src[0], src[1]);
+               result = ac_build_umax(&ctx->ac, src[0], src[1]);
                break;
        case nir_op_umin:
                result = ac_build_umin(&ctx->ac, src[0], src[1]);
@@ -1119,8 +1109,8 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                                                ac_to_float_type(&ctx->ac, def_type), result, src[2]);
                break;
        case nir_op_umax3:
-               result = emit_minmax_int(&ctx->ac, LLVMIntUGT, src[0], src[1]);
-               result = emit_minmax_int(&ctx->ac, LLVMIntUGT, result, src[2]);
+               result = ac_build_umax(&ctx->ac, src[0], src[1]);
+               result = ac_build_umax(&ctx->ac, result, src[2]);
                break;
        case nir_op_imax3:
                result = ac_build_imax(&ctx->ac, src[0], src[1]);
@@ -1143,9 +1133,9 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
        }
        case nir_op_umed3: {
                LLVMValueRef tmp1 = ac_build_umin(&ctx->ac, src[0], src[1]);
-               LLVMValueRef tmp2 = emit_minmax_int(&ctx->ac, LLVMIntUGT, src[0], src[1]);
+               LLVMValueRef tmp2 = ac_build_umax(&ctx->ac, src[0], src[1]);
                tmp2 = ac_build_umin(&ctx->ac, tmp2, src[2]);
-               result = emit_minmax_int(&ctx->ac, LLVMIntUGT, tmp1, tmp2);
+               result = ac_build_umax(&ctx->ac, tmp1, tmp2);
                break;
        }