Patchwork [i386] : Implement AVX2 all-ones load using vpcmpeqd insn

login
register
mail settings
Submitter Uros Bizjak
Date Sept. 8, 2011, 6:26 p.m.
Message ID <CAFULd4YTyg2fV8POb7Up3a_d_Ush2U5=LeevLOxwZB=szozC_g@mail.gmail.com>
Download mbox | patch
Permalink /patch/113930/
State New
Headers show

Comments

Uros Bizjak - Sept. 8, 2011, 6:26 p.m.
Hello!

2011-09-08  Uros Bizjak  <ubizjak@gmail.com>

	* config/i386/i386.c (standard_sse_constant_p): Handle AVX2 modes.
	(standard_sse_constant_opcode) <case 2>: Change vpcmpeqd template.

testsuite/ChangeLog:

2011-09-08  Uros Bizjak  <ubizjak@gmail.com>

	* gcc.target/i386/all_one_m256i.c: New test.

Tested on x86_64-pc-linux-gnu {,-m32}, committed to mainline SVN.

Uros.
Uros Bizjak - Sept. 8, 2011, 6:33 p.m.
On Thu, Sep 8, 2011 at 8:26 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
> Hello!
>
> 2011-09-08  Uros Bizjak  <ubizjak@gmail.com>
>
>        * config/i386/i386.c (standard_sse_constant_p): Handle AVX2 modes.
>        (standard_sse_constant_opcode) <case 2>: Change vpcmpeqd template.
>
> testsuite/ChangeLog:
>
> 2011-09-08  Uros Bizjak  <ubizjak@gmail.com>
>
>        * gcc.target/i386/all_one_m256i.c: New test.
>
> Tested on x86_64-pc-linux-gnu {,-m32}, committed to mainline SVN.

The sse_constant_opcode_p part of the patch should in fact read:

    case 2:
      if (TARGET_AVX)
	return "vpcmpeqd\t%0, %0, %0";
      else
	return "pcmpeqd\t%0>

Uros.

Patch

Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 178695)
+++ config/i386/i386.c	(working copy)
@@ -8176,7 +8176,7 @@  standard_80387_constant_rtx (int idx)
 }
 
 /* Return 1 if X is all 0s and 2 if x is all 1s
-   in supported SSE vector mode.  */
+   in supported SSE/AVX vector mode.  */
 
 int
 standard_sse_constant_p (rtx x)
@@ -8194,6 +8194,12 @@  standard_sse_constant_p (rtx x)
       case V2DImode:
 	if (TARGET_SSE2)
 	  return 2;
+      case V32QImode:
+      case V16HImode:
+      case V8SImode:
+      case V4DImode:
+	if (TARGET_AVX2)
+	  return 2;
       default:
 	break;
       }
@@ -8235,7 +8241,8 @@  standard_sse_constant_opcode (rtx insn, rtx x)
 	}
 
     case 2:
-      return "%vpcmpeqd\t%0, %d0";
+      return "%vpcmpeqd\t%0, %0, %0";
+
     default:
       break;
     }
Index: testsuite/gcc.target/i386/all_one_m256i.c
===================================================================
--- testsuite/gcc.target/i386/all_one_m256i.c	(revision 0)
+++ testsuite/gcc.target/i386/all_one_m256i.c	(revision 0)
@@ -0,0 +1,14 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx2" } */
+
+typedef long long __m256i __attribute__ ((__vector_size__ (32)));
+typedef int __v8si __attribute__ ((__vector_size__ (32)));
+
+__m256i foo ()
+{
+  __m256i minus_1 = (__m256i) (__v8si) { -1, -1, -1, -1, -1, -1, -1, -1 };
+
+  return minus_1;
+}
+
+/* { dg-final { scan-assembler "vpcmpeqd" } } */