[Mesa-dev] [PATCH 04/10] ac: add ac_build_umax() and use it where possible

Samuel Pitoiset samuel.pitoiset at gmail.com
Wed Apr 10 15:16:49 UTC 2019


This changes the predicate from LessThan to Equal.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/amd/common/ac_llvm_build.c  |  7 +++++++
 src/amd/common/ac_llvm_build.h  |  1 +
 src/amd/common/ac_nir_to_llvm.c | 20 +++++---------------
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index 3e3ca5c7fdb..6a1ba5de0e0 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -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);
diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h
index c3277fd2d13..61689f6a07e 100644
--- a/src/amd/common/ac_llvm_build.h
+++ b/src/amd/common/ac_llvm_build.h
@@ -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 {
diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index 69c418f2ca0..1287507628a 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -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;
 	}
 
-- 
2.21.0



More information about the mesa-dev mailing list