[1/2] Fix unstable sort

Message ID 1515790698-6489-2-git-send-email-lists@coryfields.com
State New
Headers show
Series
  • Fix unstable sorts affecting codegen
Related show

Commit Message

Cory Fields Jan. 12, 2018, 8:58 p.m.
From: Cory Fields <cory-nospam-@coryfields.com>

2018-01-12  Cory Fields  <cory-nospam-@coryfields.com>
       * tree-ssa-loop-im.c (sort_bbs_in_loop_postorder_cmp): stabilize sort
---
 gcc/ChangeLog          | 3 +++
 gcc/tree-ssa-loop-im.c | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

Comments

Jeff Law Jan. 15, 2018, 6:06 a.m. | #1
On 01/12/2018 01:58 PM, lists@coryfields.com wrote:
> From: Cory Fields <cory-nospam-@coryfields.com>
> 
> 2018-01-12  Cory Fields  <cory-nospam-@coryfields.com>
>        * tree-ssa-loop-im.c (sort_bbs_in_loop_postorder_cmp): stabilize sort
Thanks.  Installed onto the trunk.
jeff

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4b4b577..ab96bd6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,6 @@ 
+2018-01-12  Cory Fields  <cory-nospam-@coryfields.com>
+	* tree-ssa-loop-im.c (sort_bbs_in_loop_postorder_cmp): stabilize sort
+
 2018-01-12  Jakub Jelinek  <jakub@redhat.com>
 
 	PR debug/81155
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c
index 7d95621..7864fbd 100644
--- a/gcc/tree-ssa-loop-im.c
+++ b/gcc/tree-ssa-loop-im.c
@@ -1496,7 +1496,7 @@  sort_bbs_in_loop_postorder_cmp (const void *bb1_, const void *bb2_)
   struct loop *loop1 = bb1->loop_father;
   struct loop *loop2 = bb2->loop_father;
   if (loop1->num == loop2->num)
-    return 0;
+    return bb1->index - bb2->index;
   return bb_loop_postorder[loop1->num] < bb_loop_postorder[loop2->num] ? -1 : 1;
 }