Skip to content

Commit

Permalink
improve codegen for variables that are assigned but never used. (ref #…
Browse files Browse the repository at this point in the history
…9343)

this builds and passes tests with LLVM assertions, but we should be
on the lookout for regressions here.
  • Loading branch information
JeffBezanson committed Dec 15, 2014
1 parent 326d9f1 commit ad0722d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,10 @@ static void simple_escape_analysis(jl_value_t *expr, bool esc, jl_codectx_t *ctx
simple_escape_analysis(jl_exprarg(e,1), esc, ctx);
simple_escape_analysis(jl_exprarg(e,2), esc, ctx);
}
else if (e->head == assign_sym) {
// don't consider assignment LHS as a variable "use"
simple_escape_analysis(jl_exprarg(e,1), esc, ctx);
}
else if (e->head != line_sym) {
size_t elen = jl_array_dim0(e->args);
for(i=0; i < elen; i++) {
Expand Down Expand Up @@ -2770,6 +2774,8 @@ static void emit_assignment(jl_value_t *l, jl_value_t *r, jl_codectx_t *ctx)
}
else {
rval = emit_expr(r, ctx, true);
if (!vi.used) // don't actually do the assignment if the var is never read
return;
// Make sure this is already boxed. If not, there was
// something wrong in the earlier analysis as this should
// have been alloca'd
Expand Down

0 comments on commit ad0722d

Please sign in to comment.