Browse Source

Simplify scalar -> array conversions in LLVM to use a loop after a certain size

gingerBill 1 year ago
parent
commit
caa344c88d
2 changed files with 11 additions and 12 deletions
  1. 11 2
      src/llvm_backend_expr.cpp
  2. 0 10
      src/llvm_backend_general.cpp

+ 11 - 2
src/llvm_backend_expr.cpp

@@ -2143,9 +2143,18 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
 		lbAddr v = lb_add_local_generated(p, t, false);
 		lbAddr v = lb_add_local_generated(p, t, false);
 		isize index_count = cast(isize)get_array_type_count(dst);
 		isize index_count = cast(isize)get_array_type_count(dst);
 
 
-		for (isize i = 0; i < index_count; i++) {
-			lbValue elem = lb_emit_array_epi(p, v.addr, i);
+		if (type_size_of(dst) > build_context.max_simd_align) {
+			auto loop_data = lb_loop_start(p, index_count, t_int);
+
+			lbValue elem = lb_emit_array_ep(p, v.addr, loop_data.idx);
 			lb_emit_store(p, elem, e);
 			lb_emit_store(p, elem, e);
+
+			lb_loop_end(p, loop_data);
+		} else {
+			for (isize i = 0; i < index_count; i++) {
+				lbValue elem = lb_emit_array_epi(p, v.addr, i);
+				lb_emit_store(p, elem, e);
+			}
 		}
 		}
 		return lb_addr_load(p, v);
 		return lb_addr_load(p, v);
 	}
 	}

+ 0 - 10
src/llvm_backend_general.cpp

@@ -954,16 +954,6 @@ gb_internal void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) {
 	GB_ASSERT(value.value != nullptr);
 	GB_ASSERT(value.value != nullptr);
 	value = lb_emit_conv(p, value, lb_addr_type(addr));
 	value = lb_emit_conv(p, value, lb_addr_type(addr));
 
 
-	// if (lb_is_const_or_global(value)) {
-	// 	// NOTE(bill): Just bypass the actual storage and set the initializer
-	// 	if (LLVMGetValueKind(addr.addr.value) == LLVMGlobalVariableValueKind) {
-	// 		LLVMValueRef dst = addr.addr.value;
-	// 		LLVMValueRef src = value.value;
-	// 		LLVMSetInitializer(dst, src);
-	// 		return;
-	// 	}
-	// }
-
 	lb_emit_store(p, addr.addr, value);
 	lb_emit_store(p, addr.addr, value);
 }
 }