ac/nir: fix translation of nir_op_fsign for doubles
authorTimothy Arceri <tarceri@itsqueeze.com>
Thu, 11 Jan 2018 11:10:47 +0000 (22:10 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Thu, 11 Jan 2018 22:29:18 +0000 (09:29 +1100)
Without this we end up with the llvm error message:

"Both operands to a binary operator are not of the same type!"

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/common/ac_nir_to_llvm.c

index 7b348d97f0a086346e393be605c91f8fb2dd1589..6ab93b367831e3d1891c8e269f792b9a4b414c7d 100644 (file)
@@ -1338,14 +1338,26 @@ static LLVMValueRef emit_iabs(struct ac_llvm_context *ctx,
 }
 
 static LLVMValueRef emit_fsign(struct ac_llvm_context *ctx,
-                              LLVMValueRef src0)
+                              LLVMValueRef src0,
+                              unsigned bitsize)
 {
-       LLVMValueRef cmp, val;
+       LLVMValueRef cmp, val, zero, one;
+       LLVMTypeRef type;
+
+       if (bitsize == 32) {
+               type = ctx->f32;
+               zero = ctx->f32_0;
+               one = ctx->f32_1;
+       } else {
+               type = ctx->f64;
+               zero = ctx->f64_0;
+               one = ctx->f64_1;
+       }
 
-       cmp = LLVMBuildFCmp(ctx->builder, LLVMRealOGT, src0, ctx->f32_0, "");
-       val = LLVMBuildSelect(ctx->builder, cmp, ctx->f32_1, src0, "");
-       cmp = LLVMBuildFCmp(ctx->builder, LLVMRealOGE, val, ctx->f32_0, "");
-       val = LLVMBuildSelect(ctx->builder, cmp, val, LLVMConstReal(ctx->f32, -1.0), "");
+       cmp = LLVMBuildFCmp(ctx->builder, LLVMRealOGT, src0, zero, "");
+       val = LLVMBuildSelect(ctx->builder, cmp, one, src0, "");
+       cmp = LLVMBuildFCmp(ctx->builder, LLVMRealOGE, val, zero, "");
+       val = LLVMBuildSelect(ctx->builder, cmp, val, LLVMConstReal(type, -1.0), "");
        return val;
 }
 
@@ -1799,7 +1811,7 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                break;
        case nir_op_fsign:
                src[0] = ac_to_float(&ctx->ac, src[0]);
-               result = emit_fsign(&ctx->ac, src[0]);
+               result = emit_fsign(&ctx->ac, src[0], instr->dest.dest.ssa.bit_size);
                break;
        case nir_op_ffloor:
                result = emit_intrin_1f_param(&ctx->ac, "llvm.floor",