Hello, The autopref_rank_for_schedule qsort sub-comparator is not actually a proper comparator. For instance, it lacks transitivity: if there's insns A, B, C such that B has AUTOPREF_MULTUPASS_DATA_IRRELEVANT status, but A and C compare such that C < A, we can have A == B == C < A according to this sub-comparator, and A < B < C < A if the following tie-breakers order A before B and B before C.
I'm not sure this heuristic fits well into the overall scheduler sorting, but if we want to just fix this comparison step, we should never skip calls to autopref_rank_data. Bootstrapped and regtested on x86-64 with PARAM_SCHED_AUTOPREF_QUEUE_DEPTH set to '0' (otherwise this sub-comparator is unused). OK to apply? Thanks. Alexander * haifa-sched.c (autopref_rank_for_schedule): Always invoke autopref_rank_data. diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c index af0ed27b18f..031a0af96db 100644 --- a/gcc/haifa-sched.c +++ b/gcc/haifa-sched.c @@ -5707,7 +5707,8 @@ autopref_rank_data (autopref_multipass_data_t data1, static int autopref_rank_for_schedule (const rtx_insn *insn1, const rtx_insn *insn2) { - for (int write = 0; write < 2; ++write) + int r = 0; + for (int write = 0; write < 2 && !r; ++write) { autopref_multipass_data_t data1 = &INSN_AUTOPREF_MULTIPASS_DATA (insn1)[write]; @@ -5716,21 +5717,14 @@ autopref_rank_for_schedule (const rtx_insn *insn1, const rtx_insn *insn2) if (data1->status == AUTOPREF_MULTIPASS_DATA_UNINITIALIZED) autopref_multipass_init (insn1, write); - if (data1->status == AUTOPREF_MULTIPASS_DATA_IRRELEVANT) - continue; if (data2->status == AUTOPREF_MULTIPASS_DATA_UNINITIALIZED) autopref_multipass_init (insn2, write); - if (data2->status == AUTOPREF_MULTIPASS_DATA_IRRELEVANT) - continue; - if (!rtx_equal_p (data1->base, data2->base)) - continue; - - return autopref_rank_data (data1, data2); + r = autopref_rank_data (data1, data2); } - return 0; + return r; } /* True if header of debug dump was printed. */