aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-coalesce.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2007-08-31 14:28:38 +0000
committerNick Clifton <nickc@gcc.gnu.org>2007-08-31 14:28:38 +0000
commit7562df8122d83aa86ddbc2e096a96ef16e85045f (patch)
tree186057dc0dca9f422aab0bbbc925c792aee79361 /gcc/tree-ssa-coalesce.c
parent3681df8fe1eac5d26deefddeb621d2d74bbf5bb9 (diff)
downloadgcc-7562df8122d83aa86ddbc2e096a96ef16e85045f.zip
gcc-7562df8122d83aa86ddbc2e096a96ef16e85045f.tar.gz
gcc-7562df8122d83aa86ddbc2e096a96ef16e85045f.tar.bz2
tree-ssa-coalesce.c (compare_pairs): Use the elements as secondary keys in order to obtain a stable sort.
* tree-ssa-coalesce.c (compare_pairs): Use the elements as secondary keys in order to obtain a stable sort. From-SVN: r127993
Diffstat (limited to 'gcc/tree-ssa-coalesce.c')
-rw-r--r--gcc/tree-ssa-coalesce.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/gcc/tree-ssa-coalesce.c b/gcc/tree-ssa-coalesce.c
index 1b63635..ef1ebca 100644
--- a/gcc/tree-ssa-coalesce.c
+++ b/gcc/tree-ssa-coalesce.c
@@ -314,8 +314,22 @@ add_coalesce (coalesce_list_p cl, int p1, int p2,
static int
compare_pairs (const void *p1, const void *p2)
{
- return (*(const_coalesce_pair_p const*)p1)->cost
- - (*(const_coalesce_pair_p const*)p2)->cost;
+ const_coalesce_pair_p const * pp1 = p1;
+ const_coalesce_pair_p const * pp2 = p2;
+ int result;
+
+ result = (* pp2)->cost - (* pp1)->cost;
+ /* Since qsort does not guarantee stability we use the elements
+ as a secondary key. This provides us with independence from
+ the host's implementation of the sorting algorithm. */
+ if (result == 0)
+ {
+ result = (* pp2)->first_element - (* pp1)->first_element;
+ if (result == 0)
+ result = (* pp2)->second_element - (* pp1)->second_element;
+ }
+
+ return result;
}