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 <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28607>
This commit is contained in:
Marek Olšák 2023-03-06 21:41:12 -05:00
parent c7e30cdbbb
commit 8597870dcb

View file

@ -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);
}
}