diff options
author | Samuel Pitoiset <[email protected]> | 2019-10-14 15:39:06 +0200 |
---|---|---|
committer | Samuel Pitoiset <[email protected]> | 2019-10-18 16:55:55 +0200 |
commit | 2c2aaf275c1edba38c552ac74de4d46bb2ebfbe8 (patch) | |
tree | cb66a28410c2c0d008f4e13170426f142e7bfc9f | |
parent | 7dfb15fff1d765689353419c0a0ac9c96786b021 (diff) |
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 <[email protected]>
Reviewed-by: Bas Nieuwenhuizen <[email protected]>
-rw-r--r-- | src/amd/llvm/ac_nir_to_llvm.c | 14 |
1 files changed, 14 insertions, 0 deletions
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]); |