Skip to content

Commit

Permalink
Optimize ADD of CONST to ADDR
Browse files Browse the repository at this point in the history
For pointer-sized operands, we can optimize a constant addition to
ADDR nodes. (This happens for example in the templates for
sp_p6oget_*).
  • Loading branch information
bdw committed Sep 4, 2018
1 parent 59f4334 commit 5b4a263
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/jit/todo.org
Expand Up @@ -663,7 +663,7 @@ Walks should be single-visit.

*** DONE IDX CONST to ADDR conversion
Uses one register fewer, simpler operation
*** TODO ADD CONST to ADDR conversion
*** DONE ADD CONST to ADDR conversion
Only allowed if user is pointerlike (e.g. LOAD)
*** DONE COPY insertion
=======
Expand Down
17 changes: 17 additions & 0 deletions src/jit/optimize.c
Expand Up @@ -119,6 +119,23 @@ static void optimize_postorder(MVMThreadContext *tc, MVMJitTreeTraverser *traver
}
break;
}
case MVM_JIT_ADD:
{
MVMJitExprInfo *info = MVM_JIT_EXPR_INFO(tree, node);
MVMint32 *links = MVM_JIT_EXPR_LINKS(tree, node);
MVMint32 lhs = links[0];
MVMint32 rhs = links[1];
if (tree->nodes[rhs] == MVM_JIT_CONST) {
MVMint32 cv = MVM_JIT_EXPR_ARGS(tree, rhs)[0];
if (cv != 0 && info->size == MVM_JIT_PTR_SZ) {
_DEBUG("Replacing ADD CONST %d to ADDR for pointer-sized addition", cv, cv);
replacement = MVM_jit_expr_apply_template_adhoc(tc, tree, "ns..", MVM_JIT_ADDR, 1, lhs, cv);
} else if (cv == 0) {
replacement = lhs;
}
}
break;
}
}

if (replacement > 0) {
Expand Down

0 comments on commit 5b4a263

Please sign in to comment.