[store-merging] Use store order as tie-breaker in sort_by_bitpos
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Wed, 13 Sep 2017 13:49:50 +0000 (13:49 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Wed, 13 Sep 2017 13:49:50 +0000 (13:49 +0000)
As Alexander pointed out in the thread starting at [1] the sort_by_bitpos sorting function
was behaving badly when we had multiple stores at the same position.  He fixed that (thanks!)
but we can do better by not returning zero when the bitpositions are equal but by falling back
to comparing the order the stores appear in, which is guaranteed to be unique (barring other
bugs elsewhere).

This patch does that.

Bootstrapped and tested on aarch64-none-linux-gnu.

[1] https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00895.html

* gimple-ssa-store-merging.c (sort_by_bitpos): Compare store order
when bitposition is the same.

From-SVN: r252084

gcc/ChangeLog
gcc/gimple-ssa-store-merging.c

index ef793e4..0e0257d 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-13  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * gimple-ssa-store-merging.c (sort_by_bitpos): Compare store order
+       when bitposition is the same.
+
 2017-09-13  Richard Biener  <rguenther@suse.de>
 
        * dwarf2out.c (output_die_symbol): Remove.
index a4a38b1..cb76403 100644 (file)
@@ -521,7 +521,9 @@ sort_by_bitpos (const void *x, const void *y)
   else if ((*tmp)->bitpos > (*tmp2)->bitpos)
     return 1;
   else
-    return 0;
+    /* If they are the same let's use the order which is guaranteed to
+       be different.  */
+    return (*tmp)->order - (*tmp2)->order;
 }
 
 /* Sorting function for store_immediate_info objects.