https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83459
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amonakov at gcc dot gnu.org, | |jakub at gcc dot gnu.org, | |vmakarov at gcc dot gnu.org --- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> --- So, in this case we have: (gdb) p debug_rtx (first[0]) (insn 4 2 3 2 (set (reg/v:SI 95 [ e ]) (reg:SI 4 si [ e ])) "pr83459.c":6 86 {*movsi_internal} (expr_list:REG_DEAD (reg:SI 4 si [ e ]) (nil))) $21 = void (gdb) p debug_rtx (first[1]) (insn 15 14 16 4 (set (reg:SI 98 [ b ]) (sign_extend:SI (mem/c:HI (symbol_ref:DI ("b") [flags 0x2] <var_decl 0x7ffff7ff5ea0 b>) [1 b+0 S2 A16]))) "pr83459.c":8 153 {extendhisi2} (nil)) $22 = void (gdb) p debug_rtx (first[2]) (insn 9 3 10 2 (set (reg:SI 96 [ a ]) (sign_extend:SI (mem/c:HI (symbol_ref:DI ("a") [flags 0x2] <var_decl 0x7ffff7ff5e10 a>) [1 a+0 S2 A16]))) "pr83459.c":7 153 {extendhisi2} (nil)) and p rank_for_schedule (&first[0], &first[1]) $24 = -1 determined by val = (dep_list_size (tmp2, SD_LIST_FORW) - dep_list_size (tmp, SD_LIST_FORW)); if (flag_sched_dep_count_heuristic && val != 0) return rfs_result (RFS_DEP_COUNT, val, tmp, tmp2); where val is -1, then p rank_for_schedule (&first[1], &first[2]) $25 = -4 determined by: /* If insns are equally good, sort by INSN_LUID (original insn order), so that we make the sort stable. This minimizes instruction movement, thus minimizing sched's effect on debugging and cross-jumping. */ return rfs_result (RFS_TIE, INSN_LUID (tmp) - INSN_LUID (tmp2), tmp, tmp2); and finally: p rank_for_schedule (&first[0], &first[2]) $26 = 1 determined by: /* Prefer instructions that occur earlier in the model schedule. */ if (sched_pressure == SCHED_PRESSURE_MODEL && INSN_BB (tmp) == target_bb && INSN_BB (tmp2) == target_bb) { diff = model_index (tmp) - model_index (tmp2); gcc_assert (diff != 0); return rfs_result (RFS_PRESSURE_INDEX, diff, tmp, tmp2); } which is checked earliest. If we want a stable sort, I'm afraid for SCHED_PRESSURE_MODEL we need to sort insns where INSN_BB (tmp) == target_bb and INSN_BB (tmp2) != target_bb or INSN_BB (tmp2) == target_bb and INSN_BB (tmp) != target_bb regardless of dep_list_size. Thoughts on this?