Mesa (master): ac/llvm: force fneg/fabs to flush denorms to zero if requested

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 18 15:16:41 UTC 2019


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

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Mon Oct 14 15:39:06 2019 +0200

ac/llvm: force fneg/fabs to flush denorms to zero if requested

LLVM optimizes these instructions with XOR/AND and it loses
the sign bit.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>

---

 src/amd/llvm/ac_nir_to_llvm.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c
index ab042d36083..cd7091ad163 100644
--- a/src/amd/llvm/ac_nir_to_llvm.c
+++ b/src/amd/llvm/ac_nir_to_llvm.c
@@ -516,6 +516,13 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
 	case nir_op_fneg:
 	        src[0] = ac_to_float(&ctx->ac, src[0]);
 		result = LLVMBuildFNeg(ctx->ac.builder, src[0], "");
+		if (ctx->ac.float_mode == AC_FLOAT_MODE_DENORM_FLUSH_TO_ZERO) {
+			/* fneg will be optimized by backend compiler with sign
+			 * bit removed via XOR. This is probably a LLVM bug.
+			 */
+			result = ac_build_canonicalize(&ctx->ac, result,
+						       instr->dest.dest.ssa.bit_size);
+		}
 		break;
 	case nir_op_ineg:
 		result = LLVMBuildNeg(ctx->ac.builder, src[0], "");
@@ -646,6 +653,13 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
 	case nir_op_fabs:
 		result = emit_intrin_1f_param(&ctx->ac, "llvm.fabs",
 		                              ac_to_float_type(&ctx->ac, def_type), src[0]);
+		if (ctx->ac.float_mode == AC_FLOAT_MODE_DENORM_FLUSH_TO_ZERO) {
+			/* fabs will be optimized by backend compiler with sign
+			 * bit removed via AND.
+			 */
+			result = ac_build_canonicalize(&ctx->ac, result,
+						       instr->dest.dest.ssa.bit_size);
+		}
 		break;
 	case nir_op_iabs:
 		result = emit_iabs(&ctx->ac, src[0]);




More information about the mesa-commit mailing list