public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] fold: Optimise fold_view_convert_expr
@ 2021-12-05 21:59 Richard Sandiford
  2021-12-06  7:58 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2021-12-05 21:59 UTC (permalink / raw)
  To: gcc-patches

When compiling an optabs.ii at -O2 with a release-checking build,
there were 210,172 calls to fold_view_convert_expr.  99.8% of them
were conversions of an INTEGER_CST to an ENUMERAL_TYPE, so this patch
adds a fast(er) path for that case.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


gcc/
	* fold-const.c (fold_view_convert_expr): Add a fast path for
	conversions of INTEGER_CSTs to other integral types.
---
 gcc/fold-const.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 0b9a42f764a..19613015ddb 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -9128,6 +9128,13 @@ fold_view_convert_vector_encoding (tree type, tree expr)
 static tree
 fold_view_convert_expr (tree type, tree expr)
 {
+  /* Conversions of INTEGER_CSTs to ENUMERAL_TYPEs are very common,
+     so handle them directly.  */
+  if (INTEGRAL_TYPE_P (type)
+      && TREE_CODE (expr) == INTEGER_CST
+      && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr)))
+    return wide_int_to_tree (type, wi::to_wide (expr));
+
   /* We support up to 512-bit values (for V8DFmode).  */
   unsigned char buffer[64];
   int len;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-06  7:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-05 21:59 [PATCH] fold: Optimise fold_view_convert_expr Richard Sandiford
2021-12-06  7:58 ` Richard Biener

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).