ac/llvm: fix invalid IR if image stores are shrinked using the format
It's not always v4f32 (or v4f16 for 16-bit) when image stores are
shrinked using the format.
This fixes a ton of crashes with RADV_DEBUG=checkir,llvm.
Fixes: e4d75c22beb ("nir/opt_shrink_vectors: shrink image stores using the format")
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6882>
diff --git a/src/amd/llvm/ac_llvm_build.c b/src/amd/llvm/ac_llvm_build.c
index 506ea58..fb4ecbb 100644
--- a/src/amd/llvm/ac_llvm_build.c
+++ b/src/amd/llvm/ac_llvm_build.c
@@ -2225,6 +2225,20 @@
unreachable("invalid dim");
}
+ LLVMTypeRef data_type;
+ char data_type_str[8];
+
+ if (atomic) {
+ data_type = ctx->i32;
+ } else if (a->opcode == ac_image_store || a->opcode == ac_image_store_mip) {
+ /* Image stores might have been shrinked using the format. */
+ data_type = LLVMTypeOf(a->data[0]);
+ } else {
+ data_type = a->d16 ? ctx->v4f16 : ctx->v4f32;
+ }
+
+ ac_build_type_name_for_intr(data_type, data_type_str, sizeof(data_type_str));
+
bool lod_suffix = a->lod && (a->opcode == ac_image_sample || a->opcode == ac_image_gather4);
char intr_name[96];
snprintf(intr_name, sizeof(intr_name),
@@ -2234,7 +2248,7 @@
name, atomic_subop, a->compare ? ".c" : "",
a->bias ? ".b" : lod_suffix ? ".l" : a->derivs[0] ? ".d" : a->level_zero ? ".lz" : "",
a->min_lod ? ".cl" : "", a->offset ? ".o" : "", dimname,
- atomic ? "i32" : (a->d16 ? "v4f16" : "v4f32"), overload[0], overload[1], overload[2]);
+ data_type_str, overload[0], overload[1], overload[2]);
LLVMTypeRef retty;
if (atomic)