Skip to content

Commit 027a43b

Browse files
authored
[mono][jit] Reenable branch optimizations when running with llvm. (#97189)
* [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.
1 parent 69f4f85 commit 027a43b

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

src/mono/mono/mini/branch-opts.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ mono_if_conversion (MonoCompile *cfg)
776776
}
777777

778778
void
779-
mono_nullify_basic_block (MonoBasicBlock *bb)
779+
mono_nullify_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
780780
{
781781
bb->in_count = 0;
782782
bb->out_count = 0;
@@ -960,7 +960,7 @@ remove_block_if_useless (MonoCompile *cfg, MonoBasicBlock *bb, MonoBasicBlock *p
960960
}
961961

962962
previous_bb->next_bb = bb->next_bb;
963-
mono_nullify_basic_block (bb);
963+
mono_nullify_basic_block (cfg, bb);
964964

965965
return TRUE;
966966
} else {
@@ -1046,7 +1046,7 @@ mono_merge_basic_blocks (MonoCompile *cfg, MonoBasicBlock *bb, MonoBasicBlock *b
10461046
if (bb->next_bb == bbn)
10471047
bb->next_bb = bbn->next_bb;
10481048
}
1049-
mono_nullify_basic_block (bbn);
1049+
mono_nullify_basic_block (cfg, bbn);
10501050

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

1294-
mono_nullify_basic_block (bbn);
1294+
mono_nullify_basic_block (cfg, bbn);
12951295
changed = TRUE;
12961296
}
12971297

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

1344-
mono_nullify_basic_block (bbn);
1344+
mono_nullify_basic_block (cfg, bbn);
13451345
changed = TRUE;
13461346
continue;
13471347
}
@@ -1463,7 +1463,7 @@ mono_optimize_branches (MonoCompile *cfg)
14631463
}
14641464

14651465
if (bb->last_ins && MONO_IS_COND_BRANCH_NOFP (bb->last_ins)) {
1466-
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) {
1466+
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) {
14671467
/* Reverse the branch */
14681468
bb->last_ins->opcode = GUINT32_TO_OPCODE (mono_reverse_branch_op (bb->last_ins->opcode));
14691469
bbn = bb->last_ins->inst_false_bb;

src/mono/mono/mini/mini-llvm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6147,7 +6147,7 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
61476147
break;
61486148
case LLVMArgVtypeAsScalar:
61496149
if (is_simd) {
6150-
retval = LLVMBuildBitCast (builder, values [ins->sreg1], ret_type, "setret_simd_vtype_as_scalar");
6150+
retval = LLVMBuildBitCast (builder, lhs, ret_type, "setret_simd_vtype_as_scalar");
61516151
} else {
61526152
g_assert (addresses [ins->sreg1]);
61536153
retval = LLVMBuildLoad2 (builder, ret_type, build_ptr_cast (builder, addresses [ins->sreg1]->value, pointer_type (ret_type)), "");
@@ -9579,9 +9579,7 @@ MONO_RESTORE_WARNING
95799579
LLVMValueRef args [2];
95809580
args [0] = convert (ctx, lhs, sse_i2_t);
95819581
args [1] = convert (ctx, rhs, sse_i2_t);
9582-
values [ins->dreg] = convert (ctx,
9583-
call_intrins (ctx, INTRINS_SSE_PACKUSWB, args, dname),
9584-
type_to_sse_type (GTMREG_TO_INT (ins->inst_c1)));
9582+
values [ins->dreg] = call_intrins (ctx, INTRINS_SSE_PACKUSWB, args, dname);
95859583
break;
95869584
}
95879585

src/mono/mono/mini/mini.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,8 +3549,6 @@ mini_method_compile (MonoMethod *method, guint32 opts, JitFlags flags, int parts
35493549
}
35503550

35513551
cfg->opt &= ~MONO_OPT_LINEARS;
3552-
3553-
cfg->opt &= ~MONO_OPT_BRANCH;
35543552
}
35553553

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

3978-
if (cfg->verbose_level >= 2) {
3976+
if (cfg->verbose_level >= 2 && !cfg->llvm_only) {
39793977
char *id = mono_method_full_name (cfg->method, TRUE);
39803978
g_print ("\n*** ASM for %s ***\n", id);
39813979
mono_disassemble_code (cfg, cfg->native_code, cfg->code_len, id + 3);

src/mono/mono/mini/mini.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@ void mono_link_bblock (MonoCompile *cfg, MonoBasicBlock *f
21842184
void mono_unlink_bblock (MonoCompile *cfg, MonoBasicBlock *from, MonoBasicBlock* to);
21852185
gboolean mono_bblocks_linked (MonoBasicBlock *bb1, MonoBasicBlock *bb2);
21862186
void mono_remove_bblock (MonoCompile *cfg, MonoBasicBlock *bb);
2187-
void mono_nullify_basic_block (MonoBasicBlock *bb);
2187+
void mono_nullify_basic_block (MonoCompile *cfg, MonoBasicBlock *bb);
21882188
void mono_merge_basic_blocks (MonoCompile *cfg, MonoBasicBlock *bb, MonoBasicBlock *bbn);
21892189
void mono_optimize_branches (MonoCompile *cfg);
21902190

0 commit comments

Comments
 (0)