public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [AArch64]  PR target/71663 Improve Vector Initializtion
@ 2016-12-09  3:30 Hurugalawadi, Naveen
  2016-12-09  7:02 ` Hurugalawadi, Naveen
  2016-12-12  3:16 ` [PATCH] [AArch64] Implement popcount pattern Hurugalawadi, Naveen
  0 siblings, 2 replies; 28+ messages in thread
From: Hurugalawadi, Naveen @ 2016-12-09  3:30 UTC (permalink / raw)
  To: gcc-patches
  Cc: Pinski, Andrew, James Greenhalgh, Marcus Shawcroft, Richard Earnshaw

[-- Attachment #1: Type: text/plain, Size: 542 bytes --]

Hi,

The AArch64 vector initialization sequence can be optimized to generate
better code. The attached patch handles for the case where the vector
contains only variables. It checks for the common elements in the vector
and inserts the values in optimized way.

Bootstrapped and Regression tested on aarch64-thunder-linux.
Please review the patch and let us know if its okay?

2016-12-09  Andrew PInski  <apinski@cavium.com>

gcc
	* config/aarch64/aarch64.c (aarch64_expand_vector_init):
	Improve vector initialization code gen.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr71663.patch --]
[-- Type: text/x-diff; name="pr71663.patch", Size: 1807 bytes --]

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index e87831f..da5b6fa 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -11609,11 +11609,54 @@ aarch64_expand_vector_init (rtx target, rtx vals)
       aarch64_expand_vector_init (target, copy);
     }
 
-  /* Insert the variable lanes directly.  */
-
   enum insn_code icode = optab_handler (vec_set_optab, mode);
   gcc_assert (icode != CODE_FOR_nothing);
 
+  /* If there is only varables, try to optimize
+     the inseration using dup for the most common element
+     followed by insertations. */
+  if (n_var == n_elts && n_elts <= 16)
+    {
+      int matches[16][2];
+      int nummatches = 0;
+      memset (matches, 0, sizeof(matches));
+      for(int i = 0; i < n_elts; i++)
+	{
+	  for (int j = 0; j <= i; j++)
+	    {
+	      if (rtx_equal_p (XVECEXP (vals, 0, i), XVECEXP (vals, 0, j)))
+		{
+		  matches[i][0] = j;
+		  matches[j][1]++;
+		  if (i != j)
+		    nummatches++;
+		  break;
+		}
+	    }
+	}
+      int maxelement = 0;
+      int maxv = 0;
+      for (int i = 0; i < n_elts; i++)
+	if (matches[i][1] > maxv)
+	  maxelement = i, maxv = matches[i][1];
+
+      /* Create a duplicate of the most common element. */
+      rtx x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, maxelement));
+      aarch64_emit_move (target, gen_rtx_VEC_DUPLICATE (mode, x));
+      /* Insert the rest. */
+      for (int i = 0; i < n_elts; i++)
+	{
+	  rtx x = XVECEXP (vals, 0, i);
+	  if (matches[i][0] == maxelement)
+	    continue;
+	  x = copy_to_mode_reg (inner_mode, x);
+	  emit_insn (GEN_FCN (icode) (target, x, GEN_INT (i)));
+	}
+      return;
+    }
+
+  /* Insert the variable lanes directly.  */
+
   for (int i = 0; i < n_elts; i++)
     {
       rtx x = XVECEXP (vals, 0, i);

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

end of thread, other threads:[~2017-06-14  9:10 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-09  3:30 [PATCH] [AArch64] PR target/71663 Improve Vector Initializtion Hurugalawadi, Naveen
2016-12-09  7:02 ` Hurugalawadi, Naveen
2017-02-06  6:46   ` Hurugalawadi, Naveen
2017-04-25  7:03     ` [PING] " Hurugalawadi, Naveen
2017-04-25  8:37   ` Kyrill Tkachov
2017-04-26  9:04     ` Hurugalawadi, Naveen
2017-05-11  4:56       ` [PING] " Hurugalawadi, Naveen
2017-05-26  6:27         ` [PING 2] " Hurugalawadi, Naveen
2017-06-09 14:16       ` James Greenhalgh
2017-06-13 10:25         ` Hurugalawadi, Naveen
2017-06-13 13:56           ` James Greenhalgh
2017-06-14  8:53             ` Hurugalawadi, Naveen
2017-06-14  9:10               ` James Greenhalgh
2016-12-12  3:16 ` [PATCH] [AArch64] Implement popcount pattern Hurugalawadi, Naveen
2016-12-12 10:53   ` Kyrill Tkachov
2016-12-13 11:51     ` Hurugalawadi, Naveen
2016-12-13 11:59       ` Kyrill Tkachov
2017-01-25  8:07         ` [PATCH] [AArch64] Enable AES and cmp_branch fusion for Thunderx2t99 Hurugalawadi, Naveen
2017-01-25  9:29           ` Kyrill Tkachov
2017-02-02  5:03             ` Hurugalawadi, Naveen
2017-02-02 11:43               ` James Greenhalgh
2017-02-01 13:56         ` [PATCH] [AArch64] Implement popcount pattern James Greenhalgh
2017-02-02  4:03           ` Hurugalawadi, Naveen
2017-02-02 11:56             ` James Greenhalgh
2017-02-03  5:56               ` Andrew Pinski
2017-02-03  7:02                 ` Hurugalawadi, Naveen
2017-02-03 10:28                   ` Kyrill Tkachov
2017-02-04  4:04                   ` James Greenhalgh

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