Improve scalar -> array assignment when the scalar is constant in LLVM

This commit is contained in:
gingerBill
2024-04-12 14:20:46 +01:00
parent caa344c88d
commit 4240e0025e

View File

@@ -2138,12 +2138,34 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
if (is_type_array_like(dst)) {
Type *elem = base_array_type(dst);
lbValue e = lb_emit_conv(p, value, elem);
// NOTE(bill): Doesn't need to be zero because it will be initialized in the loops
lbAddr v = lb_add_local_generated(p, t, false);
isize index_count = cast(isize)get_array_type_count(dst);
if (type_size_of(dst) > build_context.max_simd_align) {
isize inlineable = type_size_of(dst) <= build_context.max_simd_align;
lbValue e = lb_emit_conv(p, value, elem);
if (inlineable && lb_is_const(e)) {
lbAddr v = {};
if (e.value) {
TEMPORARY_ALLOCATOR_GUARD();
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, index_count);
for (isize i = 0; i < index_count; i++) {
values[i] = e.value;
}
lbValue array_const_value = {};
array_const_value.type = t;
array_const_value.value = LLVMConstArray(lb_type(m, elem), values, cast(unsigned)index_count);
v = lb_add_global_generated(m, t, array_const_value);
} else {
v = lb_add_global_generated(m, t);
}
lb_make_global_private_const(v);
return lb_addr_load(p, v);
}
// NOTE(bill): Doesn't need to be zero because it will be initialized in the loops
lbAddr v = lb_add_local_generated(p, t, false);
if (!inlineable) {
auto loop_data = lb_loop_start(p, index_count, t_int);
lbValue elem = lb_emit_array_ep(p, v.addr, loop_data.idx);