aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-02-06 13:47:52 +0000
committergingerBill <bill@gingerbill.org>2019-02-06 13:47:52 +0000
commitbc5c37ebb188384d0a44b0b35aec9e01bc9104f0 (patch)
treeb8f6df09e06baa2011617c6799096a1f6aa39765 /src/ir.cpp
parent0133dd90343261c3d8c877bfcdd6e74d0e596944 (diff)
Extra checks to reduce mem.zero calls
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 79c07a91b..32c2c7d64 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -2740,12 +2740,16 @@ void ir_value_set_debug_location(irProcedure *proc, irValue *v) {
void ir_emit_zero_init(irProcedure *p, irValue *address, Ast *expr) {
gbAllocator a = ir_allocator();
Type *t = type_deref(ir_type(address));
- auto args = array_make<irValue *>(a, 2);
- args[0] = ir_emit_conv(p, address, t_rawptr);
- args[1] = ir_const_int(type_size_of(t));
- AstPackage *pkg = get_core_package(p->module->info, str_lit("mem"));
- if (p->entity != nullptr && p->entity->token.string != "zero" && p->entity->pkg != pkg) {
- irValue *v = ir_emit_package_call(p, "mem", "zero", args, expr, ProcInlining_no_inline);
+ isize sz = type_size_of(t);
+ if (!(gb_is_power_of_two(sz) && sz <= build_context.max_align)) {
+ // TODO(bill): Is this a good idea?
+ auto args = array_make<irValue *>(a, 2);
+ args[0] = ir_emit_conv(p, address, t_rawptr);
+ args[1] = ir_const_int(type_size_of(t));
+ AstPackage *pkg = get_core_package(p->module->info, str_lit("mem"));
+ if (p->entity != nullptr && p->entity->token.string != "zero" && p->entity->pkg != pkg) {
+ irValue *v = ir_emit_package_call(p, "mem", "zero", args, expr, ProcInlining_no_inline);
+ }
}
ir_emit(p, ir_instr_zero_init(p, address));
}