ac/llvm: convert src operands to pointers if necessary
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 27 Nov 2019 14:32:45 +0000 (15:32 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 28 Nov 2019 07:26:51 +0000 (08:26 +0100)
To avoid generating invalid LLVM IR when both operands don't have
the same type. This might happen when performing pointer comparisons
with SPIRV 1.4.

Fixes invalid LLVM IR for:
dEQP-VK.spirv_assembly.instruction.spirv1p4.opptrequal.variable_pointers_ssbo_equal
dEQP-VK.spirv_assembly.instruction.spirv1p4.opptrnotequal.variable_pointers_ssbo_not_equal

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/llvm/ac_nir_to_llvm.c

index 589f39c3c0350994cdd337a9758ef4a8c6938285..c6e699567c9d70e06b264245f12572cb895fee6a 100644 (file)
@@ -234,8 +234,19 @@ static LLVMValueRef emit_intrin_3f_param(struct ac_llvm_context *ctx,
 static LLVMValueRef emit_bcsel(struct ac_llvm_context *ctx,
                               LLVMValueRef src0, LLVMValueRef src1, LLVMValueRef src2)
 {
+       LLVMTypeRef src1_type = LLVMTypeOf(src1);
+       LLVMTypeRef src2_type = LLVMTypeOf(src2);
+
        assert(LLVMGetTypeKind(LLVMTypeOf(src0)) != LLVMVectorTypeKind);
 
+       if (LLVMGetTypeKind(src1_type) == LLVMPointerTypeKind &&
+           LLVMGetTypeKind(src2_type) != LLVMPointerTypeKind) {
+               src2 = LLVMBuildIntToPtr(ctx->builder, src2, src1_type, "");
+       } else if (LLVMGetTypeKind(src2_type) == LLVMPointerTypeKind &&
+                  LLVMGetTypeKind(src1_type) != LLVMPointerTypeKind) {
+               src1 = LLVMBuildIntToPtr(ctx->builder, src1, src2_type, "");
+       }
+
        LLVMValueRef v = LLVMBuildICmp(ctx->builder, LLVMIntNE, src0,
                                       ctx->i32_0, "");
        return LLVMBuildSelect(ctx->builder, v,