From: "Martin Liška" <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Cc: Alexander Monakov <amonakov@ispras.ru>
Subject: [PATCH] Speed up qsort in IPA ICF
Date: Thu, 19 Sep 2019 09:06:00 -0000 [thread overview]
Message-ID: <e787c43e-2be4-ee92-7820-b8968856a3ea@suse.cz> (raw)
[-- Attachment #1: Type: text/plain, Size: 943 bytes --]
Hi.
As Alexander pointed out, the sort_congruence_class_groups_by_decl_uid is the most
expensive qsort operator in tramp3d compilation. It does unfortunate 7 pointer dereferences
via: DECL_UID (classes[i]->classes[0]->members[0]->decl). I'm suggesting to cache that
in congruence_class_group.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
gcc/ChangeLog:
2019-09-19 Martin Liska <mliska@suse.cz>
* 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
congruence_class_group::uid.
(sem_item_optimizer::merge_classes): Cache
DECL_UID (classes[i]->classes[0]->members[0]->decl).
* ipa-icf.h (struct congruence_class_group): New field.
---
gcc/ipa-icf.c | 29 +++++------------------------
gcc/ipa-icf.h | 1 +
2 files changed, 6 insertions(+), 24 deletions(-)
[-- Attachment #2: 0001-Speed-up-qsort-in-IPA-ICF.patch --]
[-- Type: text/x-patch, Size: 2044 bytes --]
diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index c9c3cb4a331..d78635ad6b3 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
@@ -3388,16 +3376,7 @@ sort_congruence_class_groups_by_decl_uid (const void *a, const void *b)
= *(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;
+ return g1->uid - g2->uid;
}
/* After reduction is done, we can declare all items in a group
@@ -3450,6 +3429,8 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count)
it != m_classes.end (); ++it)
classes.quick_push (*it);
+ for (unsigned i = 0; i < classes.length (); i++)
+ classes[i]->uid = DECL_UID (classes[i]->classes[0]->members[0]->decl);
classes.qsort (sort_congruence_class_groups_by_decl_uid);
if (dump_file)
diff --git a/gcc/ipa-icf.h b/gcc/ipa-icf.h
index 2bf0f156ef6..e7bb4afcfee 100644
--- a/gcc/ipa-icf.h
+++ b/gcc/ipa-icf.h
@@ -461,6 +461,7 @@ struct congruence_class_group
{
hashval_t hash;
sem_item_type type;
+ int uid;
vec <congruence_class *> classes;
};
next reply other threads:[~2019-09-19 9:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-19 9:06 Martin Liška [this message]
2019-09-19 11:01 ` Richard Biener
2019-09-19 13:02 ` Martin Liška
2019-09-19 13:09 ` Richard Biener
2019-09-19 13:15 ` Alexander Monakov
2019-09-19 13:18 ` Richard Biener
2019-09-19 13:32 ` Martin Liška
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e787c43e-2be4-ee92-7820-b8968856a3ea@suse.cz \
--to=mliska@suse.cz \
--cc=amonakov@ispras.ru \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).