From: Samuel Pitoiset Date: Tue, 9 Jun 2020 06:36:17 +0000 (+0200) Subject: ac/nir: fix integer comparisons with pointers X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=commitdiff_plain;h=9b58c4958be690dc92278f4b435e729033add98c;hp=24ceb6a5946a9c76de5f9bd3009ed26bf0ca25dc ac/nir: fix integer comparisons with pointers If we get a comparison between a pointer and an integer, LLVM complains if the operands aren't of the same type. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3085 Signed-off-by: Samuel Pitoiset Reviewed-by: Marek Olšák Part-of: --- diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index 3e0f70d084d..b90a7e3dcf2 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -170,6 +170,17 @@ static LLVMValueRef emit_int_cmp(struct ac_llvm_context *ctx, LLVMIntPredicate pred, LLVMValueRef src0, LLVMValueRef src1) { + LLVMTypeRef src0_type = LLVMTypeOf(src0); + LLVMTypeRef src1_type = LLVMTypeOf(src1); + + if (LLVMGetTypeKind(src0_type) == LLVMPointerTypeKind && + LLVMGetTypeKind(src1_type) != LLVMPointerTypeKind) { + src1 = LLVMBuildIntToPtr(ctx->builder, src1, src0_type, ""); + } else if (LLVMGetTypeKind(src1_type) == LLVMPointerTypeKind && + LLVMGetTypeKind(src0_type) != LLVMPointerTypeKind) { + src0 = LLVMBuildIntToPtr(ctx->builder, src0, src1_type, ""); + } + LLVMValueRef result = LLVMBuildICmp(ctx->builder, pred, src0, src1, ""); return LLVMBuildSelect(ctx->builder, result, LLVMConstInt(ctx->i32, 0xFFFFFFFF, false),