aboutsummaryrefslogtreecommitdiff
path: root/gcc/bb-reorder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/bb-reorder.cc')
-rw-r--r--gcc/bb-reorder.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/gcc/bb-reorder.cc b/gcc/bb-reorder.cc
index e4efdee..0bcd0e5 100644
--- a/gcc/bb-reorder.cc
+++ b/gcc/bb-reorder.cc
@@ -2377,7 +2377,11 @@ reorder_basic_blocks_software_trace_cache (void)
FREE (bbd);
}
-/* Order edges by execution frequency, higher first. */
+/* Order edges by execution frequency, higher first.
+ Return:
+ 1 iff frequency (VE1) < frequency (VE2)
+ 0 iff frequency (VE1) == frequency (VE2)
+ -1 iff frequency (VE1) > frequency (VE2) */
static int
edge_order (const void *ve1, const void *ve2)
@@ -2392,7 +2396,12 @@ edge_order (const void *ve1, const void *ve2)
gcov_type gc1 = c1.initialized_p () ? c1.to_gcov_type () : 0;
gcov_type gc2 = c2.initialized_p () ? c2.to_gcov_type () : 0;
gcov_type m = MAX (gc1, gc2);
- return (m == gc1) - (m == gc2);
+ int low_to_high_cmp = (m == gc1) - (m == gc2);
+ /* gcc_stablesort sorts values in low-to-high order. But edges should
+ be sorted in the opposite order - with highest execution frequency first.
+ So return an inverted comparison to trick gcc_stablesort into
+ performing a reversed sorting order. */
+ return -1 * low_to_high_cmp;
}
/* Reorder basic blocks using the "simple" algorithm. This tries to