diff mbox series

Improve PR85574

Message ID alpine.LSU.2.20.1812211817130.1827@zhemvz.fhfr.qr
State New
Headers show
Series Improve PR85574 | expand

Commit Message

Richard Biener Dec. 21, 2018, 5:19 p.m. UTC
It looks like IPA ICF does code generation based on the order of
a hahstable walk which is keyed on pointers.  That's a no-no.
Fixing that doesn't solve the cc1 miscompare for LTO bootstrap
but at least the IPA ICF WPA dumps are now consistent between
stages.

[LTO] Bootstrapped and tested on x86_64-unknown-linux-gnu, ok
for trunk (and branches)?

Will only get to applying after Christmas holidays so in case
you want to poke further feel free to apply yourself.

Thanks,
Richard.

2018-12-21  Richard Biener  <rguenther@suse.de>

	PR ipa/85574
	* ipa-icf.h (sem_item_optimizer::sort_congruence_split): Declare.
	* ipa-icf.c (sem_item_optimizer::sort_congruence_split): New
	function.
	(sem_item_optimizer::do_congruence_step_f): Sort the congruence
	set after UIDs before splitting them.

Comments

Richard Biener Jan. 2, 2019, 8:50 a.m. UTC | #1
On Fri, 21 Dec 2018, Richard Biener wrote:

> 
> It looks like IPA ICF does code generation based on the order of
> a hahstable walk which is keyed on pointers.  That's a no-no.
> Fixing that doesn't solve the cc1 miscompare for LTO bootstrap
> but at least the IPA ICF WPA dumps are now consistent between
> stages.
> 
> [LTO] Bootstrapped and tested on x86_64-unknown-linux-gnu, ok
> for trunk (and branches)?

Now applied to trunk.  Will continue poking at PR85574 after
digging through backlog.

Richard.

> Will only get to applying after Christmas holidays so in case
> you want to poke further feel free to apply yourself.
> 
> Thanks,
> Richard.
> 
> 2018-12-21  Richard Biener  <rguenther@suse.de>
> 
> 	PR ipa/85574
> 	* ipa-icf.h (sem_item_optimizer::sort_congruence_split): Declare.
> 	* ipa-icf.c (sem_item_optimizer::sort_congruence_split): New
> 	function.
> 	(sem_item_optimizer::do_congruence_step_f): Sort the congruence
> 	set after UIDs before splitting them.
> 
> Index: gcc/ipa-icf.c
> ===================================================================
> --- gcc/ipa-icf.c	(revision 267301)
> +++ gcc/ipa-icf.c	(working copy)
> @@ -3117,6 +3117,18 @@ sem_item_optimizer::traverse_congruence_
>    return true;
>  }
>  
> +int
> +sem_item_optimizer::sort_congruence_split (const void *a_, const void *b_)
> +{
> +  const std::pair<congruence_class *, bitmap> *a = (const std::pair<congruence_class *, bitmap> *)a_;
> +  const std::pair<congruence_class *, bitmap> *b = (const std::pair<congruence_class *, bitmap> *)b_;
> +  if (a->first->id < b->first->id)
> +    return -1;
> +  else if (a->first->id > b->first->id)
> +    return 1;
> +  return 0;
> +}
> +
>  /* Tests if a class CLS used as INDEXth splits any congruence classes.
>     Bitmap stack BMSTACK is used for bitmap allocation.  */
>  
> @@ -3157,13 +3169,20 @@ sem_item_optimizer::do_congruence_step_f
>  	}
>      }
>  
> +  auto_vec<std::pair<congruence_class *, bitmap> > to_split;
> +  to_split.reserve_exact (split_map.elements ());
> +  for (hash_map <congruence_class *, bitmap>::iterator i = split_map.begin ();
> +       i != split_map.end (); ++i)
> +    to_split.safe_push (*i);
> +  to_split.qsort (sort_congruence_split);
> +
>    traverse_split_pair pair;
>    pair.optimizer = this;
>    pair.cls = cls;
>  
>    splitter_class_removed = false;
> -  split_map.traverse <traverse_split_pair *,
> -		      sem_item_optimizer::traverse_congruence_split> (&pair);
> +  for (unsigned i = 0; i < to_split.length (); ++i)
> +    traverse_congruence_split (to_split[i].first, to_split[i].second, &pair);
>  
>    /* Bitmap clean-up.  */
>    split_map.traverse <traverse_split_pair *,
> Index: gcc/ipa-icf.h
> ===================================================================
> --- gcc/ipa-icf.h	(revision 267301)
> +++ gcc/ipa-icf.h	(working copy)
> @@ -599,6 +599,8 @@ private:
>  					 bitmap const &b,
>  					 traverse_split_pair *pair);
>  
> +  static int sort_congruence_split (const void *, const void *);
> +
>    /* Reads a section from LTO stream file FILE_DATA. Input block for DATA
>       contains LEN bytes.  */
>    void read_section (lto_file_decl_data *file_data, const char *data,
>
diff mbox series

Patch

Index: gcc/ipa-icf.c
===================================================================
--- gcc/ipa-icf.c	(revision 267301)
+++ gcc/ipa-icf.c	(working copy)
@@ -3117,6 +3117,18 @@  sem_item_optimizer::traverse_congruence_
   return true;
 }
 
+int
+sem_item_optimizer::sort_congruence_split (const void *a_, const void *b_)
+{
+  const std::pair<congruence_class *, bitmap> *a = (const std::pair<congruence_class *, bitmap> *)a_;
+  const std::pair<congruence_class *, bitmap> *b = (const std::pair<congruence_class *, bitmap> *)b_;
+  if (a->first->id < b->first->id)
+    return -1;
+  else if (a->first->id > b->first->id)
+    return 1;
+  return 0;
+}
+
 /* Tests if a class CLS used as INDEXth splits any congruence classes.
    Bitmap stack BMSTACK is used for bitmap allocation.  */
 
@@ -3157,13 +3169,20 @@  sem_item_optimizer::do_congruence_step_f
 	}
     }
 
+  auto_vec<std::pair<congruence_class *, bitmap> > to_split;
+  to_split.reserve_exact (split_map.elements ());
+  for (hash_map <congruence_class *, bitmap>::iterator i = split_map.begin ();
+       i != split_map.end (); ++i)
+    to_split.safe_push (*i);
+  to_split.qsort (sort_congruence_split);
+
   traverse_split_pair pair;
   pair.optimizer = this;
   pair.cls = cls;
 
   splitter_class_removed = false;
-  split_map.traverse <traverse_split_pair *,
-		      sem_item_optimizer::traverse_congruence_split> (&pair);
+  for (unsigned i = 0; i < to_split.length (); ++i)
+    traverse_congruence_split (to_split[i].first, to_split[i].second, &pair);
 
   /* Bitmap clean-up.  */
   split_map.traverse <traverse_split_pair *,
Index: gcc/ipa-icf.h
===================================================================
--- gcc/ipa-icf.h	(revision 267301)
+++ gcc/ipa-icf.h	(working copy)
@@ -599,6 +599,8 @@  private:
 					 bitmap const &b,
 					 traverse_split_pair *pair);
 
+  static int sort_congruence_split (const void *, const void *);
+
   /* Reads a section from LTO stream file FILE_DATA. Input block for DATA
      contains LEN bytes.  */
   void read_section (lto_file_decl_data *file_data, const char *data,