This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Stabilize qsort of switch cases
- From: Richard Sandiford <richard at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 20 Jan 2006 12:12:57 +0000
- Subject: Stabilize qsort of switch cases
In a similar vein to PR rtl-optimization/20365, we were comparing
the output of two cross compilers for the same target, one hosted
on Windows and the other on GNU/Linux. The code generated for some
case statements was different (but equivalent) because of an unstable
sort in emit_case_bit_tests. This patch fixes it.
Bootstrapped & regression tested on i686-pc-linux-gnu. Approved
offline by Mark and applied to trunk.
Richard
* stmt.c (case_bit_test_cmp): Stabilize the sort using code
label numbers.
Index: gcc/stmt.c
===================================================================
--- gcc/stmt.c (revision 110020)
+++ gcc/stmt.c (working copy)
@@ -2170,7 +2170,11 @@ case_bit_test_cmp (const void *p1, const
const struct case_bit_test *d1 = p1;
const struct case_bit_test *d2 = p2;
- return d2->bits - d1->bits;
+ if (d2->bits != d1->bits)
+ return d2->bits - d1->bits;
+
+ /* Stabilize the sort. */
+ return CODE_LABEL_NUMBER (d2->label) - CODE_LABEL_NUMBER (d1->label);
}
/* Expand a switch statement by a short sequence of bit-wise