Skip to content

Commit

Permalink
[mono][jit] Reenable branch optimizations when running with llvm. (#9…
Browse files Browse the repository at this point in the history
…7189)

* [mono][jit] Reenable branch optimizations when running with llvm.

* [mono][llvm] Fix the return type of OP_SSE2_PACKUS.

This is supposed to return a 16xi8 so there is no need to cast it.
This only worked by accident because the phi handling code casted it
to the right type most of the time.

* Disable moving out of line bblocks to the end of code when using llvm.

* Fix a crash in OP_SETRET.
  • Loading branch information
vargaz authored Jan 29, 2024
1 parent 69f4f85 commit 027a43b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/mono/mono/mini/branch-opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ mono_if_conversion (MonoCompile *cfg)
}

void
mono_nullify_basic_block (MonoBasicBlock *bb)
mono_nullify_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
{
bb->in_count = 0;
bb->out_count = 0;
Expand Down Expand Up @@ -960,7 +960,7 @@ remove_block_if_useless (MonoCompile *cfg, MonoBasicBlock *bb, MonoBasicBlock *p
}

previous_bb->next_bb = bb->next_bb;
mono_nullify_basic_block (bb);
mono_nullify_basic_block (cfg, bb);

return TRUE;
} else {
Expand Down Expand Up @@ -1046,7 +1046,7 @@ mono_merge_basic_blocks (MonoCompile *cfg, MonoBasicBlock *bb, MonoBasicBlock *b
if (bb->next_bb == bbn)
bb->next_bb = bbn->next_bb;
}
mono_nullify_basic_block (bbn);
mono_nullify_basic_block (cfg, bbn);

/*
* If bbn fell through to its next bblock, have to add a branch, since bb
Expand Down Expand Up @@ -1291,7 +1291,7 @@ mono_optimize_branches (MonoCompile *cfg)
for (i = 0; i < bbn->out_count; i++)
replace_in_block (bbn->out_bb [i], bbn, NULL);

mono_nullify_basic_block (bbn);
mono_nullify_basic_block (cfg, bbn);
changed = TRUE;
}

Expand Down Expand Up @@ -1341,7 +1341,7 @@ mono_optimize_branches (MonoCompile *cfg)
for (i = 0; i < bbn->out_count; i++)
replace_in_block (bbn->out_bb [i], bbn, NULL);

mono_nullify_basic_block (bbn);
mono_nullify_basic_block (cfg, bbn);
changed = TRUE;
continue;
}
Expand Down Expand Up @@ -1463,7 +1463,7 @@ mono_optimize_branches (MonoCompile *cfg)
}

if (bb->last_ins && MONO_IS_COND_BRANCH_NOFP (bb->last_ins)) {
if (bb->last_ins->inst_false_bb && bb->last_ins->inst_false_bb->out_of_line && (bb->region == bb->last_ins->inst_false_bb->region) && !cfg->disable_out_of_line_bblocks) {
if (!COMPILE_LLVM (cfg) && bb->last_ins->inst_false_bb && bb->last_ins->inst_false_bb->out_of_line && (bb->region == bb->last_ins->inst_false_bb->region) && !cfg->disable_out_of_line_bblocks) {
/* Reverse the branch */
bb->last_ins->opcode = GUINT32_TO_OPCODE (mono_reverse_branch_op (bb->last_ins->opcode));
bbn = bb->last_ins->inst_false_bb;
Expand Down
6 changes: 2 additions & 4 deletions src/mono/mono/mini/mini-llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6147,7 +6147,7 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
break;
case LLVMArgVtypeAsScalar:
if (is_simd) {
retval = LLVMBuildBitCast (builder, values [ins->sreg1], ret_type, "setret_simd_vtype_as_scalar");
retval = LLVMBuildBitCast (builder, lhs, ret_type, "setret_simd_vtype_as_scalar");
} else {
g_assert (addresses [ins->sreg1]);
retval = LLVMBuildLoad2 (builder, ret_type, build_ptr_cast (builder, addresses [ins->sreg1]->value, pointer_type (ret_type)), "");
Expand Down Expand Up @@ -9579,9 +9579,7 @@ MONO_RESTORE_WARNING
LLVMValueRef args [2];
args [0] = convert (ctx, lhs, sse_i2_t);
args [1] = convert (ctx, rhs, sse_i2_t);
values [ins->dreg] = convert (ctx,
call_intrins (ctx, INTRINS_SSE_PACKUSWB, args, dname),
type_to_sse_type (GTMREG_TO_INT (ins->inst_c1)));
values [ins->dreg] = call_intrins (ctx, INTRINS_SSE_PACKUSWB, args, dname);
break;
}

Expand Down
4 changes: 1 addition & 3 deletions src/mono/mono/mini/mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -3549,8 +3549,6 @@ mini_method_compile (MonoMethod *method, guint32 opts, JitFlags flags, int parts
}

cfg->opt &= ~MONO_OPT_LINEARS;

cfg->opt &= ~MONO_OPT_BRANCH;
}

cfg->after_method_to_ir = TRUE;
Expand Down Expand Up @@ -3975,7 +3973,7 @@ mini_method_compile (MonoMethod *method, guint32 opts, JitFlags flags, int parts
if (!cfg->compile_aot)
mono_lldb_save_method_info (cfg);

if (cfg->verbose_level >= 2) {
if (cfg->verbose_level >= 2 && !cfg->llvm_only) {
char *id = mono_method_full_name (cfg->method, TRUE);
g_print ("\n*** ASM for %s ***\n", id);
mono_disassemble_code (cfg, cfg->native_code, cfg->code_len, id + 3);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/mini.h
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,7 @@ void mono_link_bblock (MonoCompile *cfg, MonoBasicBlock *f
void mono_unlink_bblock (MonoCompile *cfg, MonoBasicBlock *from, MonoBasicBlock* to);
gboolean mono_bblocks_linked (MonoBasicBlock *bb1, MonoBasicBlock *bb2);
void mono_remove_bblock (MonoCompile *cfg, MonoBasicBlock *bb);
void mono_nullify_basic_block (MonoBasicBlock *bb);
void mono_nullify_basic_block (MonoCompile *cfg, MonoBasicBlock *bb);
void mono_merge_basic_blocks (MonoCompile *cfg, MonoBasicBlock *bb, MonoBasicBlock *bbn);
void mono_optimize_branches (MonoCompile *cfg);

Expand Down

0 comments on commit 027a43b

Please sign in to comment.