From: Martin Liska Date: Thu, 19 Sep 2019 13:13:21 +0000 (+0200) Subject: Speed up qsort in IPA ICF. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=37bc3aa0474f21b7a678b09951634de3205d014e;p=gcc.git Speed up qsort in IPA ICF. 2019-09-19 Martin Liska * ipa-icf.c (sort_sem_items_by_decl_uid): Simplify comparator. (sort_congruence_classes_by_decl_uid): Likewise. (sort_congruence_class_groups_by_decl_uid): Use std::pair for easier sorting. (sem_item_optimizer::merge_classes): Likewise. From-SVN: r275961 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1810fe92af0..cbddb904bff 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-09-19 Martin Liska + + * ipa-icf.c (sort_sem_items_by_decl_uid): Simplify comparator. + (sort_congruence_classes_by_decl_uid): Likewise. + (sort_congruence_class_groups_by_decl_uid): Use std::pair for + easier sorting. + (sem_item_optimizer::merge_classes): Likewise. + 2019-09-19 Richard Biener PR tree-optimization/91812 diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index c9c3cb4a331..59b7f8b1b9d 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -3350,13 +3350,7 @@ sort_sem_items_by_decl_uid (const void *a, const void *b) int uid1 = DECL_UID (i1->decl); int uid2 = DECL_UID (i2->decl); - - if (uid1 < uid2) - return -1; - else if (uid1 > uid2) - return 1; - else - return 0; + return uid1 - uid2; } /* Sort pair of congruence_classes A and B by DECL_UID of the first member. */ @@ -3369,13 +3363,7 @@ sort_congruence_classes_by_decl_uid (const void *a, const void *b) int uid1 = DECL_UID (c1->members[0]->decl); int uid2 = DECL_UID (c2->members[0]->decl); - - if (uid1 < uid2) - return -1; - else if (uid1 > uid2) - return 1; - else - return 0; + return uid1 - uid2; } /* Sort pair of congruence_class_groups A and B by @@ -3384,20 +3372,11 @@ sort_congruence_classes_by_decl_uid (const void *a, const void *b) static int sort_congruence_class_groups_by_decl_uid (const void *a, const void *b) { - const congruence_class_group *g1 - = *(const congruence_class_group * const *)a; - const congruence_class_group *g2 - = *(const congruence_class_group * const *)b; - - int uid1 = DECL_UID (g1->classes[0]->members[0]->decl); - int uid2 = DECL_UID (g2->classes[0]->members[0]->decl); - - if (uid1 < uid2) - return -1; - else if (uid1 > uid2) - return 1; - else - return 0; + const std::pair *g1 + = *(const std::pair *const *) a; + const std::pair *g2 + = *(const std::pair *const *) b; + return g1->second - g2->second; } /* After reduction is done, we can declare all items in a group @@ -3445,10 +3424,14 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count) } } - auto_vec classes (m_classes.elements ()); + auto_vec > classes ( + m_classes.elements ()); for (hash_table::iterator it = m_classes.begin (); it != m_classes.end (); ++it) - classes.quick_push (*it); + { + int uid = DECL_UID ((*it)->classes[0]->members[0]->decl); + classes.quick_push (std::pair (*it, uid)); + } classes.qsort (sort_congruence_class_groups_by_decl_uid); @@ -3470,11 +3453,11 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count) } unsigned int l; - congruence_class_group *it; + std::pair *it; FOR_EACH_VEC_ELT (classes, l, it) - for (unsigned int i = 0; i < it->classes.length (); i++) + for (unsigned int i = 0; i < it->first->classes.length (); i++) { - congruence_class *c = it->classes[i]; + congruence_class *c = it->first->classes[i]; if (c->members.length () == 1) continue;