diff options
| author | gingerBill <bill@gingerbill.org> | 2017-11-08 22:14:07 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2017-11-08 22:14:07 +0000 |
| commit | ac46b2053dec713d11d69d2780619e975721102e (patch) | |
| tree | 4588b76667533a36a975f0ca67369726b2684f7e /src/ir.cpp | |
| parent | 0ffcccdae5a8948021f9592a9dedc8ad411a7a4f (diff) | |
Remove unnecessary IR bound checks
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 51052e206..fddb80cee 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -5442,8 +5442,11 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } irValue *index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); irValue *elem = ir_emit_array_ep(proc, vector, index); - irValue *len = ir_const_int(a, t->Vector.count); - ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); + auto index_tv = type_and_value_of_expr(proc->module->info, ie->index); + if (index_tv.mode != Addressing_Constant) { + irValue *len = ir_const_int(a, t->Vector.count); + ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); + } return ir_addr(elem); break; } @@ -5460,8 +5463,12 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } irValue *index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); irValue *elem = ir_emit_array_ep(proc, array, index); - irValue *len = ir_const_int(a, t->Vector.count); - ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); + + auto index_tv = type_and_value_of_expr(proc->module->info, ie->index); + if (index_tv.mode != Addressing_Constant) { + irValue *len = ir_const_int(a, t->Vector.count); + ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); + } return ir_addr(elem); break; } @@ -5477,8 +5484,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } } irValue *elem = ir_slice_elem(proc, slice); - irValue *len = ir_slice_count(proc, slice); irValue *index = ir_emit_conv(proc, ir_build_expr(proc, ie->index), t_int); + irValue *len = ir_slice_count(proc, slice); ir_emit_bounds_check(proc, ast_node_token(ie->index), index, len); irValue *v = ir_emit_ptr_offset(proc, elem, index); return ir_addr(v); @@ -5604,8 +5611,13 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { if (high == nullptr) high = ir_array_len(proc, base); if (max == nullptr) max = ir_array_len(proc, base); - ir_emit_slice_bounds_check(proc, se->open, low, high, max, false); + bool low_const = type_and_value_of_expr(proc->module->info, se->low).mode == Addressing_Constant; + bool high_const = type_and_value_of_expr(proc->module->info, se->high).mode == Addressing_Constant; + bool max_const = type_and_value_of_expr(proc->module->info, se->max).mode == Addressing_Constant; + if (!low_const || !high_const || !max_const) { + ir_emit_slice_bounds_check(proc, se->open, low, high, max, false); + } irValue *elem = ir_emit_ptr_offset(proc, ir_array_elem(proc, addr), low); irValue *len = ir_emit_arith(proc, Token_Sub, high, low, t_int); irValue *cap = ir_emit_arith(proc, Token_Sub, max, low, t_int); |