From 8597870dcb2fd3eb39d530c754bba11a95f8c17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 6 Mar 2023 21:41:12 -0500 Subject: [PATCH] ac/llvm: simplify the optimization barrier and apply it to the whole vector Use the same code as the pointer type. It works with all types and works with any vector, but we need to handle i1 and v3i16 as special cases, otherwise LLVM fails when it sees them. The previous code only extracted the first component, which is not what we want. Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/amd/llvm/ac_llvm_build.c | 50 ++++++++---------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/src/amd/llvm/ac_llvm_build.c b/src/amd/llvm/ac_llvm_build.c index 5d8da90b6f1..66d26406c97 100644 --- a/src/amd/llvm/ac_llvm_build.c +++ b/src/amd/llvm/ac_llvm_build.c @@ -412,54 +412,26 @@ void ac_build_optimization_barrier(struct ac_llvm_context *ctx, LLVMValueRef *pg LLVMTypeRef ftype = LLVMFunctionType(ctx->voidt, NULL, 0, false); LLVMValueRef inlineasm = LLVMConstInlineAsm(ftype, code, "", true, false); LLVMBuildCall2(builder, ftype, inlineasm, NULL, 0, ""); - } else if (LLVMTypeOf(*pgpr) == ctx->i32) { - /* Simple version for i32 that allows the caller to set LLVM metadata on the call - * instruction. */ - LLVMTypeRef ftype = LLVMFunctionType(ctx->i32, &ctx->i32, 1, false); - LLVMValueRef inlineasm = LLVMConstInlineAsm(ftype, code, constraint, true, false); + } else { + LLVMTypeRef old_type = LLVMTypeOf(*pgpr); - *pgpr = LLVMBuildCall2(builder, ftype, inlineasm, pgpr, 1, ""); - } else if (LLVMTypeOf(*pgpr) == ctx->i16) { - /* Simple version for i16 that allows the caller to set LLVM metadata on the call - * instruction. */ - LLVMTypeRef ftype = LLVMFunctionType(ctx->i16, &ctx->i16, 1, false); - LLVMValueRef inlineasm = LLVMConstInlineAsm(ftype, code, constraint, true, false); + if (old_type == ctx->i1) + *pgpr = LLVMBuildZExt(builder, *pgpr, ctx->i32, ""); + + if (old_type == LLVMVectorType(ctx->i16, 3)) + *pgpr = ac_build_expand_to_vec4(ctx, *pgpr, 4); - *pgpr = LLVMBuildCall2(builder, ftype, inlineasm, pgpr, 1, ""); - } else if (LLVMGetTypeKind(LLVMTypeOf(*pgpr)) == LLVMPointerTypeKind) { LLVMTypeRef type = LLVMTypeOf(*pgpr); LLVMTypeRef ftype = LLVMFunctionType(type, &type, 1, false); LLVMValueRef inlineasm = LLVMConstInlineAsm(ftype, code, constraint, true, false); *pgpr = LLVMBuildCall2(builder, ftype, inlineasm, pgpr, 1, ""); - } else { - LLVMTypeRef ftype = LLVMFunctionType(ctx->i32, &ctx->i32, 1, false); - LLVMValueRef inlineasm = LLVMConstInlineAsm(ftype, code, constraint, true, false); - LLVMTypeRef type = LLVMTypeOf(*pgpr); - unsigned bitsize = ac_get_elem_bits(ctx, type); - LLVMValueRef vgpr = *pgpr; - LLVMTypeRef vgpr_type; - unsigned vgpr_size; - LLVMValueRef vgpr0; - if (bitsize < 32) - vgpr = LLVMBuildZExt(ctx->builder, vgpr, ctx->i32, ""); + if (old_type == ctx->i1) + *pgpr = LLVMBuildTrunc(builder, *pgpr, old_type, ""); - vgpr_type = LLVMTypeOf(vgpr); - vgpr_size = ac_get_type_size(vgpr_type); - - assert(vgpr_size % 4 == 0); - - vgpr = LLVMBuildBitCast(builder, vgpr, LLVMVectorType(ctx->i32, vgpr_size / 4), ""); - vgpr0 = LLVMBuildExtractElement(builder, vgpr, ctx->i32_0, ""); - vgpr0 = LLVMBuildCall2(builder, ftype, inlineasm, &vgpr0, 1, ""); - vgpr = LLVMBuildInsertElement(builder, vgpr, vgpr0, ctx->i32_0, ""); - vgpr = LLVMBuildBitCast(builder, vgpr, vgpr_type, ""); - - if (bitsize < 32) - vgpr = LLVMBuildTrunc(builder, vgpr, type, ""); - - *pgpr = vgpr; + if (old_type == LLVMVectorType(ctx->i16, 3)) + *pgpr = ac_extract_components(ctx, *pgpr, 0, 3); } }