2 * local-propagation.c: Local constant, copy and tree propagation.
4 * To make some sense of the tree mover, read mono/docs/tree-mover.txt
7 * Paolo Molaro (lupus@ximian.com)
8 * Dietmar Maurer (dietmar@ximian.com)
9 * Massimiliano Mantione (massi@ximian.com)
11 * (C) 2006 Novell, Inc. http://www.novell.com
12 * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
24 #include <mono/metadata/debug-helpers.h>
25 #include <mono/metadata/mempool.h>
26 #include <mono/metadata/opcodes.h>
30 #ifndef MONO_ARCH_IS_OP_MEMBASE
31 #define MONO_ARCH_IS_OP_MEMBASE(opcode) FALSE
34 static inline MonoBitSet*
35 mono_bitset_mp_new_noinit (MonoMemPool *mp, guint32 max_size)
37 int size = mono_bitset_alloc_size (max_size, 0);
40 mem = mono_mempool_alloc (mp, size);
41 return mono_bitset_mem_new (mem, max_size, MONO_BITSET_DONT_FREE);
45 * Replaces ins with optimized opcodes.
47 * We can emit to cbb the equivalent instructions which will be used as
48 * replacement for ins, or simply change the fields of ins. Spec needs to
49 * be updated if we silently change the opcode of ins.
51 * Returns TRUE if additional vregs were allocated.
54 mono_strength_reduction_ins (MonoCompile *cfg, MonoInst *ins, const char **spec)
56 gboolean allocated_vregs = FALSE;
58 /* FIXME: Add long/float */
59 switch (ins->opcode) {
62 if (ins->dreg == ins->sreg1) {
70 #if SIZEOF_REGISTER == 8
74 if (ins->inst_imm == 0) {
75 ins->opcode = OP_MOVE;
80 #if SIZEOF_REGISTER == 8
83 if (ins->inst_imm == 0) {
84 ins->opcode = (ins->opcode == OP_LMUL_IMM) ? OP_I8CONST : OP_ICONST;
87 } else if (ins->inst_imm == 1) {
88 ins->opcode = OP_MOVE;
89 } else if ((ins->opcode == OP_IMUL_IMM) && (ins->inst_imm == -1)) {
90 ins->opcode = OP_INEG;
91 } else if ((ins->opcode == OP_LMUL_IMM) && (ins->inst_imm == -1)) {
92 ins->opcode = OP_LNEG;
94 int power2 = mono_is_power_of_two (ins->inst_imm);
96 ins->opcode = (ins->opcode == OP_MUL_IMM) ? OP_SHL_IMM : ((ins->opcode == OP_LMUL_IMM) ? OP_LSHL_IMM : OP_ISHL_IMM);
97 ins->inst_imm = power2;
102 case OP_IDIV_UN_IMM: {
103 int c = ins->inst_imm;
104 int power2 = mono_is_power_of_two (c);
107 if (ins->opcode == OP_IREM_UN_IMM) {
108 ins->opcode = OP_IAND_IMM;
110 ins->inst_imm = (1 << power2) - 1;
111 } else if (ins->opcode == OP_IDIV_UN_IMM) {
112 ins->opcode = OP_ISHR_UN_IMM;
114 ins->inst_imm = power2;
120 int c = ins->inst_imm;
121 int power2 = mono_is_power_of_two (c);
124 int r1 = mono_alloc_ireg (cfg);
126 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ISHR_UN_IMM, r1, ins->sreg1, 31);
127 MONO_EMIT_NEW_BIALU (cfg, OP_IADD, r1, r1, ins->sreg1);
128 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ISHR_IMM, ins->dreg, r1, 1);
130 allocated_vregs = TRUE;
131 } else if (power2 > 0 && power2 < 31) {
132 int r1 = mono_alloc_ireg (cfg);
134 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ISHR_IMM, r1, ins->sreg1, 31);
135 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ISHR_UN_IMM, r1, r1, (32 - power2));
136 MONO_EMIT_NEW_BIALU (cfg, OP_IADD, r1, r1, ins->sreg1);
137 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ISHR_IMM, ins->dreg, r1, power2);
139 allocated_vregs = TRUE;
143 #if SIZEOF_REGISTER == 8
147 int power = mono_is_power_of_two (ins->inst_imm);
148 if (ins->inst_imm == 1) {
149 ins->opcode = OP_ICONST;
150 MONO_INST_NULLIFY_SREGS (ins);
155 } else if ((ins->inst_imm > 0) && (ins->inst_imm < (1LL << 32)) && (power != -1)) {
156 gboolean is_long = ins->opcode == OP_LREM_IMM;
157 int compensator_reg = alloc_ireg (cfg);
158 int intermediate_reg;
160 /* Based on gcc code */
162 /* Add compensation for negative numerators */
165 intermediate_reg = compensator_reg;
166 MONO_EMIT_NEW_BIALU_IMM (cfg, is_long ? OP_LSHR_IMM : OP_ISHR_IMM, intermediate_reg, ins->sreg1, is_long ? 63 : 31);
168 intermediate_reg = ins->sreg1;
171 MONO_EMIT_NEW_BIALU_IMM (cfg, is_long ? OP_LSHR_UN_IMM : OP_ISHR_UN_IMM, compensator_reg, intermediate_reg, (is_long ? 64 : 32) - power);
172 MONO_EMIT_NEW_BIALU (cfg, is_long ? OP_LADD : OP_IADD, ins->dreg, ins->sreg1, compensator_reg);
173 /* Compute remainder */
174 MONO_EMIT_NEW_BIALU_IMM (cfg, is_long ? OP_LAND_IMM : OP_AND_IMM, ins->dreg, ins->dreg, (1 << power) - 1);
175 /* Remove compensation */
176 MONO_EMIT_NEW_BIALU (cfg, is_long ? OP_LSUB : OP_ISUB, ins->dreg, ins->dreg, compensator_reg);
178 allocated_vregs = TRUE;
188 *spec = INS_INFO (ins->opcode);
189 return allocated_vregs;
195 * A combined local copy and constant propagation pass.
198 mono_local_cprop (MonoCompile *cfg)
200 MonoBasicBlock *bb, *bb_opt;
204 int filter = FILTER_IL_SEQ_POINT;
205 int initial_max_vregs = cfg->next_vreg;
207 max = cfg->next_vreg;
208 defs = (MonoInst **)mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * cfg->next_vreg);
209 def_index = (gint32 *)mono_mempool_alloc (cfg->mempool, sizeof (guint32) * cfg->next_vreg);
210 cfg->cbb = bb_opt = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoBasicBlock));
212 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
217 /* Manually init the defs entries used by the bblock */
218 MONO_BB_FOR_EACH_INS (bb, ins) {
219 int sregs [MONO_MAX_SRC_REGS];
222 if (ins->dreg != -1) {
223 #if SIZEOF_REGISTER == 4
224 const char *spec = INS_INFO (ins->opcode);
225 if (spec [MONO_INST_DEST] == 'l') {
226 defs [ins->dreg + 1] = NULL;
227 defs [ins->dreg + 2] = NULL;
230 defs [ins->dreg] = NULL;
233 num_sregs = mono_inst_get_src_registers (ins, sregs);
234 for (i = 0; i < num_sregs; ++i) {
235 int sreg = sregs [i];
236 #if SIZEOF_REGISTER == 4
237 const char *spec = INS_INFO (ins->opcode);
238 if (spec [MONO_INST_SRC1 + i] == 'l') {
239 defs [sreg + 1] = NULL;
240 defs [sreg + 2] = NULL;
248 last_call_index = -1;
249 MONO_BB_FOR_EACH_INS (bb, ins) {
250 const char *spec = INS_INFO (ins->opcode);
251 int regtype, srcindex, sreg;
253 int sregs [MONO_MAX_SRC_REGS];
255 if (ins->opcode == OP_NOP) {
256 MONO_DELETE_INS (bb, ins);
260 g_assert (ins->opcode > MONO_CEE_LAST);
262 /* FIXME: Optimize this */
263 if (ins->opcode == OP_LDADDR) {
264 MonoInst *var = (MonoInst *)ins->inst_p0;
266 defs [var->dreg] = NULL;
268 if (!MONO_TYPE_ISSTRUCT (var->inst_vtype))
273 if (MONO_IS_STORE_MEMBASE (ins)) {
277 if ((regtype == 'i') && (sreg != -1) && defs [sreg]) {
278 MonoInst *def = defs [sreg];
280 if ((def->opcode == OP_MOVE) && (!defs [def->sreg1] || (def_index [def->sreg1] < def_index [sreg])) && !vreg_is_volatile (cfg, def->sreg1)) {
281 int vreg = def->sreg1;
282 if (cfg->verbose_level > 2) printf ("CCOPY: R%d -> R%d\n", sreg, vreg);
288 num_sregs = mono_inst_get_src_registers (ins, sregs);
289 for (srcindex = 0; srcindex < num_sregs; ++srcindex) {
292 mono_inst_get_src_registers (ins, sregs);
294 regtype = spec [MONO_INST_SRC1 + srcindex];
295 sreg = sregs [srcindex];
297 if ((regtype == ' ') || (sreg == -1) || (!defs [sreg]))
302 /* Copy propagation */
304 * The first check makes sure the source of the copy did not change since
306 * The second check avoids volatile variables.
307 * The third check avoids copy propagating local vregs through a call,
308 * since the lvreg will be spilled
309 * The fourth check avoids copy propagating a vreg in cases where
310 * it would be eliminated anyway by reverse copy propagation later,
311 * because propagating it would create another use for it, thus making
312 * it impossible to use reverse copy propagation.
314 /* Enabling this for floats trips up the fp stack */
316 * Enabling this for floats on amd64 seems to cause a failure in
317 * basic-math.cs, most likely because it gets rid of some r8->r4
320 if (MONO_IS_MOVE (def) &&
321 (!defs [def->sreg1] || (def_index [def->sreg1] < def_index [sreg])) &&
322 !vreg_is_volatile (cfg, def->sreg1) &&
323 /* This avoids propagating local vregs across calls */
324 ((get_vreg_to_inst (cfg, def->sreg1) || !defs [def->sreg1] || (def_index [def->sreg1] >= last_call_index) || (def->opcode == OP_VMOVE))) &&
325 !(defs [def->sreg1] && mono_inst_next (defs [def->sreg1], filter) == def) &&
326 (!MONO_ARCH_USE_FPSTACK || (def->opcode != OP_FMOVE)) &&
327 (def->opcode != OP_FMOVE)) {
328 int vreg = def->sreg1;
330 if (cfg->verbose_level > 2) printf ("CCOPY/2: R%d -> R%d\n", sreg, vreg);
331 sregs [srcindex] = vreg;
332 mono_inst_set_src_registers (ins, sregs);
334 /* Allow further iterations */
339 /* Constant propagation */
340 /* FIXME: Make is_inst_imm a macro */
341 /* FIXME: Make is_inst_imm take an opcode argument */
342 /* is_inst_imm is only needed for binops */
343 if ((((def->opcode == OP_ICONST) || ((sizeof (gpointer) == 8) && (def->opcode == OP_I8CONST))) &&
344 (((srcindex == 0) && (ins->sreg2 == -1)) || mono_arch_is_inst_imm (def->inst_c0))) ||
345 (!MONO_ARCH_USE_FPSTACK && (def->opcode == OP_R8CONST))) {
348 /* srcindex == 1 -> binop, ins->sreg2 == -1 -> unop */
349 if ((srcindex == 1) && (ins->sreg1 != -1) && defs [ins->sreg1] && (defs [ins->sreg1]->opcode == OP_ICONST) && defs [ins->sreg2]) {
350 /* Both arguments are constants, perform cfold */
351 mono_constant_fold_ins (cfg, ins, defs [ins->sreg1], defs [ins->sreg2], TRUE);
352 } else if ((srcindex == 0) && (ins->sreg2 != -1) && defs [ins->sreg2]) {
353 /* Arg 1 is constant, swap arguments if possible */
354 int opcode = ins->opcode;
355 mono_constant_fold_ins (cfg, ins, defs [ins->sreg1], defs [ins->sreg2], TRUE);
356 if (ins->opcode != opcode) {
357 /* Allow further iterations */
361 } else if ((srcindex == 0) && (ins->sreg2 == -1)) {
362 /* Constant unop, perform cfold */
363 mono_constant_fold_ins (cfg, ins, defs [ins->sreg1], NULL, TRUE);
366 opcode2 = mono_op_to_op_imm (ins->opcode);
367 if ((opcode2 != -1) && mono_arch_is_inst_imm (def->inst_c0) && ((srcindex == 1) || (ins->sreg2 == -1))) {
368 ins->opcode = opcode2;
369 if ((def->opcode == OP_I8CONST) && (sizeof (gpointer) == 4)) {
370 ins->inst_ls_word = def->inst_ls_word;
371 ins->inst_ms_word = def->inst_ms_word;
373 ins->inst_imm = def->inst_c0;
375 sregs [srcindex] = -1;
376 mono_inst_set_src_registers (ins, sregs);
378 if ((opcode2 == OP_VOIDCALL) || (opcode2 == OP_CALL) || (opcode2 == OP_LCALL) || (opcode2 == OP_FCALL))
379 ((MonoCallInst*)ins)->fptr = (gpointer)ins->inst_imm;
381 /* Allow further iterations */
387 #if defined(TARGET_X86) || defined(TARGET_AMD64)
388 if ((ins->opcode == OP_X86_LEA) && (srcindex == 1)) {
389 #if SIZEOF_REGISTER == 8
390 /* FIXME: Use OP_PADD_IMM when the new JIT is done */
391 ins->opcode = OP_LADD_IMM;
393 ins->opcode = OP_ADD_IMM;
395 ins->inst_imm += def->inst_c0 << ins->backend.shift_amount;
399 opcode2 = mono_load_membase_to_load_mem (ins->opcode);
400 if ((srcindex == 0) && (opcode2 != -1) && mono_arch_is_inst_imm (def->inst_c0)) {
401 ins->opcode = opcode2;
402 ins->inst_imm = def->inst_c0 + ins->inst_offset;
407 else if (((def->opcode == OP_ADD_IMM) || (def->opcode == OP_LADD_IMM)) && (MONO_IS_LOAD_MEMBASE (ins) || MONO_ARCH_IS_OP_MEMBASE (ins->opcode))) {
408 /* ADD_IMM is created by spill_global_vars */
410 * We have to guarantee that def->sreg1 haven't changed since def->dreg
411 * was defined. cfg->frame_reg is assumed to remain constant.
413 if ((def->sreg1 == cfg->frame_reg) || ((mono_inst_next (def, filter) == ins) && (def->dreg != def->sreg1))) {
414 ins->inst_basereg = def->sreg1;
415 ins->inst_offset += def->inst_imm;
417 } else if ((ins->opcode == OP_ISUB_IMM) && (def->opcode == OP_IADD_IMM) && (mono_inst_next (def, filter) == ins) && (def->dreg != def->sreg1)) {
418 ins->sreg1 = def->sreg1;
419 ins->inst_imm -= def->inst_imm;
420 } else if ((ins->opcode == OP_IADD_IMM) && (def->opcode == OP_ISUB_IMM) && (mono_inst_next (def, filter) == ins) && (def->dreg != def->sreg1)) {
421 ins->sreg1 = def->sreg1;
422 ins->inst_imm -= def->inst_imm;
423 } else if (ins->opcode == OP_STOREI1_MEMBASE_REG &&
424 (def->opcode == OP_ICONV_TO_U1 || def->opcode == OP_ICONV_TO_I1 || def->opcode == OP_SEXT_I4 || (SIZEOF_REGISTER == 8 && def->opcode == OP_LCONV_TO_U1)) &&
425 (!defs [def->sreg1] || (def_index [def->sreg1] < def_index [sreg]))) {
426 /* Avoid needless sign extension */
427 ins->sreg1 = def->sreg1;
428 } else if (ins->opcode == OP_STOREI2_MEMBASE_REG &&
429 (def->opcode == OP_ICONV_TO_U2 || def->opcode == OP_ICONV_TO_I2 || def->opcode == OP_SEXT_I4 || (SIZEOF_REGISTER == 8 && def->opcode == OP_LCONV_TO_I2)) &&
430 (!defs [def->sreg1] || (def_index [def->sreg1] < def_index [sreg]))) {
431 /* Avoid needless sign extension */
432 ins->sreg1 = def->sreg1;
433 } else if (ins->opcode == OP_COMPARE_IMM && def->opcode == OP_LDADDR && ins->inst_imm == 0) {
436 memset (&dummy_arg1, 0, sizeof (MonoInst));
437 dummy_arg1.opcode = OP_ICONST;
438 dummy_arg1.inst_c0 = 1;
440 mono_constant_fold_ins (cfg, ins, &dummy_arg1, NULL, TRUE);
444 g_assert (cfg->cbb == bb_opt);
445 g_assert (!bb_opt->code);
446 /* Do strength reduction here */
447 if (mono_strength_reduction_ins (cfg, ins, &spec) && max < cfg->next_vreg) {
448 MonoInst **defs_prev = defs;
449 gint32 *def_index_prev = def_index;
450 guint32 prev_max = max;
451 guint32 additional_vregs = cfg->next_vreg - initial_max_vregs;
453 /* We have more vregs so we need to reallocate defs and def_index arrays */
454 max = initial_max_vregs + additional_vregs * 2;
455 defs = (MonoInst **)mono_mempool_alloc (cfg->mempool, sizeof (MonoInst*) * max);
456 def_index = (gint32 *)mono_mempool_alloc (cfg->mempool, sizeof (guint32) * max);
458 /* Keep the entries for the previous vregs, zero the rest */
459 memcpy (defs, defs_prev, sizeof (MonoInst*) * prev_max);
460 memset (defs + prev_max, 0, sizeof (MonoInst*) * (max - prev_max));
461 memcpy (def_index, def_index_prev, sizeof (guint32) * prev_max);
462 memset (def_index + prev_max, 0, sizeof (guint32) * (max - prev_max));
465 if (cfg->cbb->code || (cfg->cbb != bb_opt)) {
466 MonoInst *saved_prev = ins->prev;
468 /* If we have code in cbb, we need to replace ins with the decomposition */
469 mono_replace_ins (cfg, bb, ins, &ins->prev, bb_opt, cfg->cbb);
470 bb_opt->code = bb_opt->last_ins = NULL;
471 bb_opt->in_count = bb_opt->out_count = 0;
474 /* ins is hanging, continue scanning the emitted code */
479 if (spec [MONO_INST_DEST] != ' ') {
480 MonoInst *def = defs [ins->dreg];
482 if (def && (def->opcode == OP_ADD_IMM) && (def->sreg1 == cfg->frame_reg) && (MONO_IS_STORE_MEMBASE (ins))) {
483 /* ADD_IMM is created by spill_global_vars */
484 /* cfg->frame_reg is assumed to remain constant */
485 ins->inst_destbasereg = def->sreg1;
486 ins->inst_offset += def->inst_imm;
490 if ((spec [MONO_INST_DEST] != ' ') && !MONO_IS_STORE_MEMBASE (ins) && !vreg_is_volatile (cfg, ins->dreg)) {
491 defs [ins->dreg] = ins;
492 def_index [ins->dreg] = ins_index;
495 if (MONO_IS_CALL (ins))
496 last_call_index = ins_index;
503 static inline gboolean
504 reg_is_softreg_no_fpstack (int reg, const char spec)
506 return (spec == 'i' && reg >= MONO_MAX_IREGS)
507 || ((spec == 'f' && reg >= MONO_MAX_FREGS) && !MONO_ARCH_USE_FPSTACK)
508 #ifdef MONO_ARCH_SIMD_INTRINSICS
509 || (spec == 'x' && reg >= MONO_MAX_XREGS)
514 static inline gboolean
515 reg_is_softreg (int reg, const char spec)
517 return (spec == 'i' && reg >= MONO_MAX_IREGS)
518 || (spec == 'f' && reg >= MONO_MAX_FREGS)
519 #ifdef MONO_ARCH_SIMD_INTRINSICS
520 || (spec == 'x' && reg >= MONO_MAX_XREGS)
525 static inline gboolean
526 mono_is_simd_accessor (MonoInst *ins)
528 switch (ins->opcode) {
529 #ifdef MONO_ARCH_SIMD_INTRINSICS
537 case OP_INSERTX_U1_SLOW:
538 case OP_INSERTX_I4_SLOW:
539 case OP_INSERTX_R4_SLOW:
540 case OP_INSERTX_R8_SLOW:
541 case OP_INSERTX_I8_SLOW:
552 * Get rid of the dead assignments to local vregs like the ones created by the
556 mono_local_deadce (MonoCompile *cfg)
559 MonoInst *ins, *prev;
560 MonoBitSet *used, *defined;
562 //mono_print_code (cfg, "BEFORE LOCAL-DEADCE");
565 * Assignments to global vregs can't be eliminated so this pass must come
566 * after the handle_global_vregs () pass.
569 used = mono_bitset_mp_new_noinit (cfg->mempool, cfg->next_vreg + 1);
570 defined = mono_bitset_mp_new_noinit (cfg->mempool, cfg->next_vreg + 1);
572 /* First pass: collect liveness info */
573 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
574 /* Manually init the defs entries used by the bblock */
575 MONO_BB_FOR_EACH_INS (bb, ins) {
576 const char *spec = INS_INFO (ins->opcode);
577 int sregs [MONO_MAX_SRC_REGS];
580 if (spec [MONO_INST_DEST] != ' ') {
581 mono_bitset_clear_fast (used, ins->dreg);
582 mono_bitset_clear_fast (defined, ins->dreg);
583 #if SIZEOF_REGISTER == 4
585 mono_bitset_clear_fast (used, ins->dreg + 1);
586 mono_bitset_clear_fast (defined, ins->dreg + 1);
589 num_sregs = mono_inst_get_src_registers (ins, sregs);
590 for (i = 0; i < num_sregs; ++i) {
591 mono_bitset_clear_fast (used, sregs [i]);
592 #if SIZEOF_REGISTER == 4
593 mono_bitset_clear_fast (used, sregs [i] + 1);
599 * Make a reverse pass over the instruction list
601 MONO_BB_FOR_EACH_INS_REVERSE_SAFE (bb, prev, ins) {
602 const char *spec = INS_INFO (ins->opcode);
603 int sregs [MONO_MAX_SRC_REGS];
605 MonoInst *prev_f = mono_inst_prev (ins, FILTER_NOP | FILTER_IL_SEQ_POINT);
607 if (ins->opcode == OP_NOP) {
608 MONO_DELETE_INS (bb, ins);
612 g_assert (ins->opcode > MONO_CEE_LAST);
614 if (MONO_IS_NON_FP_MOVE (ins) && prev_f) {
619 spec2 = INS_INFO (def->opcode);
622 * Perform a limited kind of reverse copy propagation, i.e.
623 * transform B <- FOO; A <- B into A <- FOO
624 * This isn't copyprop, not deadce, but it can only be performed
625 * after handle_global_vregs () has run.
627 if (!get_vreg_to_inst (cfg, ins->sreg1) && (spec2 [MONO_INST_DEST] != ' ') && (def->dreg == ins->sreg1) && !mono_bitset_test_fast (used, ins->sreg1) && !MONO_IS_STORE_MEMBASE (def) && reg_is_softreg (ins->sreg1, spec [MONO_INST_DEST]) && !mono_is_simd_accessor (def)) {
628 if (cfg->verbose_level > 2) {
629 printf ("\tReverse copyprop in BB%d on ", bb->block_num);
630 mono_print_ins (ins);
633 def->dreg = ins->dreg;
634 MONO_DELETE_INS (bb, ins);
635 spec = INS_INFO (ins->opcode);
639 /* Enabling this on x86 could screw up the fp stack */
640 if (reg_is_softreg_no_fpstack (ins->dreg, spec [MONO_INST_DEST])) {
642 * Assignments to global vregs can only be eliminated if there is another
643 * assignment to the same vreg later in the same bblock.
645 if (!mono_bitset_test_fast (used, ins->dreg) &&
646 (!get_vreg_to_inst (cfg, ins->dreg) || (!bb->extended && !vreg_is_volatile (cfg, ins->dreg) && mono_bitset_test_fast (defined, ins->dreg))) &&
647 MONO_INS_HAS_NO_SIDE_EFFECT (ins)) {
648 /* Happens with CMOV instructions */
649 if (prev_f && prev_f->opcode == OP_ICOMPARE_IMM) {
650 MonoInst *prev = prev_f;
652 * Can't use DELETE_INS since that would interfere with the
657 //printf ("DEADCE: "); mono_print_ins (ins);
658 MONO_DELETE_INS (bb, ins);
659 spec = INS_INFO (ins->opcode);
662 if (spec [MONO_INST_DEST] != ' ')
663 mono_bitset_clear_fast (used, ins->dreg);
666 if (spec [MONO_INST_DEST] != ' ')
667 mono_bitset_set_fast (defined, ins->dreg);
668 num_sregs = mono_inst_get_src_registers (ins, sregs);
669 for (i = 0; i < num_sregs; ++i)
670 mono_bitset_set_fast (used, sregs [i]);
671 if (MONO_IS_STORE_MEMBASE (ins))
672 mono_bitset_set_fast (used, ins->dreg);
674 if (MONO_IS_CALL (ins)) {
675 MonoCallInst *call = (MonoCallInst*)ins;
678 if (call->out_ireg_args) {
679 for (l = call->out_ireg_args; l; l = l->next) {
680 guint32 regpair, reg;
682 regpair = (guint32)(gssize)(l->data);
683 reg = regpair & 0xffffff;
685 mono_bitset_set_fast (used, reg);
689 if (call->out_freg_args) {
690 for (l = call->out_freg_args; l; l = l->next) {
691 guint32 regpair, reg;
693 regpair = (guint32)(gssize)(l->data);
694 reg = regpair & 0xffffff;
696 mono_bitset_set_fast (used, reg);
703 //mono_print_code (cfg, "AFTER LOCAL-DEADCE");
706 #endif /* DISABLE_JIT */