i386: Enable AVX512 memory broadcast for FMA

Many AVX512 vector operations can broadcast from a scalar memory source.
This patch enables memory broadcast for FMA operations.

gcc/

	PR target/72782
	* config/i386/sse.md (VF_AVX512): New.
	(avx512bcst): Likewise.
	(*<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name>_bcst_1):
	Likewise.
	(*<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name>_bcst_2):
	Likewise.
	(*<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name>_bcst_3):
	Likewise.

gcc/testsuite/

	PR target/72782
	* gcc.target/i386/avx512-fma-1.h: New file.
	* gcc.target/i386/avx512-fma-2.h: Likewise.
	* gcc.target/i386/avx512-fma-3.h: Likewise.
	* gcc.target/i386/avx512-fma-4.h: Likewise.
	* gcc.target/i386/avx512-fma-5.h: Likewise.
	* gcc.target/i386/avx512-fma-6.h: Likewise.
	* gcc.target/i386/avx512-fma-7.h: Likewise.
	* gcc.target/i386/avx512-fma-8.h: Likewise.
	* gcc.target/i386/avx512f-fmadd-df-zmm-1.c: Likewise.
	* gcc.target/i386/avx512f-fmadd-sf-zmm-1.c: Likewise.
	* gcc.target/i386/avx512f-fmadd-sf-zmm-2.c: Likewise.
	* gcc.target/i386/avx512f-fmadd-sf-zmm-3.c: Likewise.
	* gcc.target/i386/avx512f-fmadd-sf-zmm-4.c: Likewise.
	* gcc.target/i386/avx512f-fmadd-sf-zmm-5.c: Likewise.
	* gcc.target/i386/avx512f-fmadd-sf-zmm-6.c: Likewise.
	* gcc.target/i386/avx512f-fmadd-sf-zmm-7.c: Likewise.
	* gcc.target/i386/avx512f-fmadd-sf-zmm-8.c: Likewise.
	* gcc.target/i386/avx512vl-fmadd-sf-xmm-1.c: Likewise.
	* gcc.target/i386/avx512vl-fmadd-sf-ymm-1.c: Likewise.

From-SVN: r265288
This commit is contained in:
H.J. Lu 2018-10-18 20:38:41 +00:00 committed by H.J. Lu
parent 955fe731e3
commit 9a91ed2a2e
22 changed files with 323 additions and 0 deletions

View File

@ -1,3 +1,15 @@
2018-10-18 H.J. Lu <hongjiu.lu@intel.com>
PR target/72782
* config/i386/sse.md (VF_AVX512): New.
(avx512bcst): Likewise.
(*<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name>_bcst_1):
Likewise.
(*<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name>_bcst_2):
Likewise.
(*<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name>_bcst_3):
Likewise.
2018-10-18 Jonathan Wakely <jwakely@redhat.com>
* doc/invoke.texi (-dumpversion): Improve grammar.

View File

@ -650,6 +650,16 @@
(V2DI "TARGET_AVX512VL") (V2DF "TARGET_AVX512VL")])
(define_mode_iterator VI48F_256 [V8SI V8SF V4DI V4DF])
(define_mode_iterator VF_AVX512
[(V4SF "TARGET_AVX512VL") (V2DF "TARGET_AVX512VL")
(V8SF "TARGET_AVX512VL") (V4DF "TARGET_AVX512VL")
V16SF V8DF])
(define_mode_attr avx512bcst
[(V4SF "%{1to4%}") (V2DF "%{1to2%}")
(V8SF "%{1to8%}") (V4DF "%{1to4%}")
(V16SF "%{1to16%}") (V8DF "%{1to8%}")])
;; Mapping from float mode to required SSE level
(define_mode_attr sse
[(SF "sse") (DF "sse2")
@ -3736,6 +3746,46 @@
[(set_attr "type" "ssemuladd")
(set_attr "mode" "<MODE>")])
(define_insn "*<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name>_bcst_1"
[(set (match_operand:VF_AVX512 0 "register_operand" "=v,v")
(fma:VF_AVX512
(match_operand:VF_AVX512 1 "nonimmediate_operand" "0,v")
(match_operand:VF_AVX512 2 "nonimmediate_operand" "v,0")
(vec_duplicate:VF_AVX512
(match_operand:<ssescalarmode> 3 "memory_operand" "m,m"))))]
"TARGET_AVX512F && <sd_mask_mode512bit_condition>"
"vfmadd213<ssemodesuffix>\t{%3<avx512bcst>, %2, %0<sd_mask_op4>|%0<sd_mask_op4>, %2, %3<avx512bcst>}"
[(set_attr "type" "ssemuladd")
(set_attr "mode" "<MODE>")])
(define_insn "*<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name>_bcst_2"
[(set (match_operand:VF_AVX512 0 "register_operand" "=v,v")
(fma:VF_AVX512
(vec_duplicate:VF_AVX512
(match_operand:<ssescalarmode> 1 "memory_operand" "m,m"))
(match_operand:VF_AVX512 2 "nonimmediate_operand" "0,v")
(match_operand:VF_AVX512 3 "nonimmediate_operand" "v,0")))]
"TARGET_AVX512F && <sd_mask_mode512bit_condition>"
"@
vfmadd132<ssemodesuffix>\t{%1<avx512bcst>, %3, %0<sd_mask_op4>|%0<sd_mask_op4>, %3, %1<avx512bcst>}
vfmadd231<ssemodesuffix>\t{%1<avx512bcst>, %2, %0<sd_mask_op4>|%0<sd_mask_op4>, %2, %1<avx512bcst>}"
[(set_attr "type" "ssemuladd")
(set_attr "mode" "<MODE>")])
(define_insn "*<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name>_bcst_3"
[(set (match_operand:VF_AVX512 0 "register_operand" "=v,v")
(fma:VF_AVX512
(match_operand:VF_AVX512 1 "nonimmediate_operand" "0,v")
(vec_duplicate:VF_AVX512
(match_operand:<ssescalarmode> 2 "memory_operand" "m,m"))
(match_operand:VF_AVX512 3 "nonimmediate_operand" "v,0")))]
"TARGET_AVX512F && <sd_mask_mode512bit_condition>"
"@
vfmadd132<ssemodesuffix>\t{%2<avx512bcst>, %3, %0<sd_mask_op4>|%0<sd_mask_op4>, %3, %2<avx512bcst>}
vfmadd231<ssemodesuffix>\t{%2<avx512bcst>, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %2<avx512bcst>}"
[(set_attr "type" "ssemuladd")
(set_attr "mode" "<MODE>")])
(define_insn "<avx512>_fmadd_<mode>_mask<round_name>"
[(set (match_operand:VF_AVX512VL 0 "register_operand" "=v,v")
(vec_merge:VF_AVX512VL

View File

@ -1,3 +1,26 @@
2018-10-18 H.J. Lu <hongjiu.lu@intel.com>
PR target/72782
* gcc.target/i386/avx512-fma-1.h: New file.
* gcc.target/i386/avx512-fma-2.h: Likewise.
* gcc.target/i386/avx512-fma-3.h: Likewise.
* gcc.target/i386/avx512-fma-4.h: Likewise.
* gcc.target/i386/avx512-fma-5.h: Likewise.
* gcc.target/i386/avx512-fma-6.h: Likewise.
* gcc.target/i386/avx512-fma-7.h: Likewise.
* gcc.target/i386/avx512-fma-8.h: Likewise.
* gcc.target/i386/avx512f-fmadd-df-zmm-1.c: Likewise.
* gcc.target/i386/avx512f-fmadd-sf-zmm-1.c: Likewise.
* gcc.target/i386/avx512f-fmadd-sf-zmm-2.c: Likewise.
* gcc.target/i386/avx512f-fmadd-sf-zmm-3.c: Likewise.
* gcc.target/i386/avx512f-fmadd-sf-zmm-4.c: Likewise.
* gcc.target/i386/avx512f-fmadd-sf-zmm-5.c: Likewise.
* gcc.target/i386/avx512f-fmadd-sf-zmm-6.c: Likewise.
* gcc.target/i386/avx512f-fmadd-sf-zmm-7.c: Likewise.
* gcc.target/i386/avx512f-fmadd-sf-zmm-8.c: Likewise.
* gcc.target/i386/avx512vl-fmadd-sf-xmm-1.c: Likewise.
* gcc.target/i386/avx512vl-fmadd-sf-ymm-1.c: Likewise.
2018-10-18 Tobias Burnus <burnus@net-b.de>
PR fortran/87625

View File

@ -0,0 +1,12 @@
#include <immintrin.h>
#define PASTER2(x,y) x##y
#define PASTER3(x,y,z) _mm##x##_##y##_##z
#define OP(vec, op, suffix) PASTER3 (vec, op, suffix)
#define DUP(vec, suffix, val) PASTER3 (vec, set1, suffix) (val)
type
foo (type x, type y, SCALAR *f)
{
return OP (vec, op, suffix) (x, y, DUP (vec, suffix, *f));
}

View File

@ -0,0 +1,13 @@
#include <immintrin.h>
#define PASTER2(x,y) x##y
#define PASTER3(x,y,z) _mm##x##_##y##_##z
#define TYPE(vec) PASTER2 (__m, vec)
#define OP(vec, op, suffix) PASTER3 (vec, op, suffix)
#define DUP(vec, suffix, val) PASTER3 (vec, set1, suffix) (val)
type
foo (type x, type y, SCALAR *f)
{
return OP (vec, op, suffix) (y, x, DUP (vec, suffix, *f));
}

View File

@ -0,0 +1,13 @@
#include <immintrin.h>
#define PASTER2(x,y) x##y
#define PASTER3(x,y,z) _mm##x##_##y##_##z
#define TYPE(vec) PASTER2 (__m, vec)
#define OP(vec, op, suffix) PASTER3 (vec, op, suffix)
#define DUP(vec, suffix, val) PASTER3 (vec, set1, suffix) (val)
type
foo (type x, type y, SCALAR *f)
{
return OP (vec, op, suffix) (x, DUP (vec, suffix, *f), y);
}

View File

@ -0,0 +1,13 @@
#include <immintrin.h>
#define PASTER2(x,y) x##y
#define PASTER3(x,y,z) _mm##x##_##y##_##z
#define TYPE(vec) PASTER2 (__m, vec)
#define OP(vec, op, suffix) PASTER3 (vec, op, suffix)
#define DUP(vec, suffix, val) PASTER3 (vec, set1, suffix) (val)
type
foo (type x, type y, SCALAR *f)
{
return OP (vec, op, suffix) (y, DUP (vec, suffix, *f), x);
}

View File

@ -0,0 +1,13 @@
#include <immintrin.h>
#define PASTER2(x,y) x##y
#define PASTER3(x,y,z) _mm##x##_##y##_##z
#define TYPE(vec) PASTER2 (__m, vec)
#define OP(vec, op, suffix) PASTER3 (vec, op, suffix)
#define DUP(vec, suffix, val) PASTER3 (vec, set1, suffix) (val)
type
foo (type x, type y, SCALAR *f)
{
return OP (vec, op, suffix) (DUP (vec, suffix, *f), x, y);
}

View File

@ -0,0 +1,13 @@
#include <immintrin.h>
#define PASTER2(x,y) x##y
#define PASTER3(x,y,z) _mm##x##_##y##_##z
#define TYPE(vec) PASTER2 (__m, vec)
#define OP(vec, op, suffix) PASTER3 (vec, op, suffix)
#define DUP(vec, suffix, val) PASTER3 (vec, set1, suffix) (val)
type
foo (type x, type y, SCALAR *f)
{
return OP (vec, op, suffix) (DUP (vec, suffix, *f), y, x);
}

View File

@ -0,0 +1,16 @@
#include <immintrin.h>
#define PASTER2(x,y) x##y
#define PASTER3(x,y,z) _mm##x##_##y##_##z
#define TYPE(vec) PASTER2 (__m, vec)
#define OP(vec, op, suffix) PASTER3 (vec, op, suffix)
#define DUP(vec, suffix, val) PASTER3 (vec, set1, suffix) (val)
extern SCALAR bar (void);
type
foo (type x, type y)
{
SCALAR f = bar ();
return OP (vec, op, suffix) (x, y, DUP (vec, suffix, f));
}

View File

@ -0,0 +1,13 @@
#include <immintrin.h>
#define PASTER2(x,y) x##y
#define PASTER3(x,y,z) _mm##x##_##y##_##z
#define TYPE(vec) PASTER2 (__m, vec)
#define OP(vec, op, suffix) PASTER3 (vec, op, suffix)
#define DUP(vec, suffix, val) PASTER3 (vec, set1, suffix) (val)
type
foo (type x, type y, SCALAR f)
{
return OP (vec, op, suffix) (y, x, DUP (vec, suffix, f));
}

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mavx512f -O2" } */
/* { dg-final { scan-assembler-times "vfmadd...pd\[ \\t\]+\\(%(?:eax|rdi|edi)\\)\\\{1to\[1-8\]+\\\}, %zmm\[0-9\]+, %zmm0" 1 } } */
/* { dg-final { scan-assembler-not "vbroadcastsd\[^\n\]*%zmm\[0-9\]+" } } */
#define type __m512d
#define vec 512
#define op fmadd
#define suffix pd
#define SCALAR double
#include "avx512-fma-1.h"

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mavx512f -O2" } */
/* { dg-final { scan-assembler-times "vfmadd...ps\[ \\t\]+\\(%(?:eax|rdi|edi)\\)\\\{1to\[1-8\]+\\\}, %zmm\[0-9\]+, %zmm0" 1 } } */
/* { dg-final { scan-assembler-not "vbroadcastss\[^\n\]*%zmm\[0-9\]+" } } */
#define type __m512
#define vec 512
#define op fmadd
#define suffix ps
#define SCALAR float
#include "avx512-fma-1.h"

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mavx512f -O2" } */
/* { dg-final { scan-assembler-times "vfmadd...ps\[ \\t\]+\\(%(?:eax|rdi|edi)\\)\\\{1to\[1-8\]+\\\}, %zmm\[0-9\]+, %zmm0" 1 } } */
/* { dg-final { scan-assembler-not "vbroadcastss\[^\n\]*%zmm\[0-9\]+" } } */
#define type __m512
#define vec 512
#define op fmadd
#define suffix ps
#define SCALAR float
#include "avx512-fma-2.h"

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mavx512f -O2" } */
/* { dg-final { scan-assembler-times "vfmadd...ps\[ \\t\]+\\(%(?:eax|rdi|edi)\\)\\\{1to\[1-8\]+\\\}, %zmm\[0-9\]+, %zmm0" 1 } } */
/* { dg-final { scan-assembler-not "vbroadcastss\[^\n\]*%zmm\[0-9\]+" } } */
#define type __m512
#define vec 512
#define op fmadd
#define suffix ps
#define SCALAR float
#include "avx512-fma-3.h"

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mavx512f -O2" } */
/* { dg-final { scan-assembler-times "vfmadd...ps\[ \\t\]+\\(%(?:eax|rdi|edi)\\)\\\{1to\[1-8\]+\\\}, %zmm\[0-9\]+, %zmm0" 1 } } */
/* { dg-final { scan-assembler-not "vbroadcastss\[^\n\]*%zmm\[0-9\]+" } } */
#define type __m512
#define vec 512
#define op fmadd
#define suffix ps
#define SCALAR float
#include "avx512-fma-4.h"

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mavx512f -O2" } */
/* { dg-final { scan-assembler-times "vfmadd...ps\[ \\t\]+\\(%(?:eax|rdi|edi)\\)\\\{1to\[1-8\]+\\\}, %zmm\[0-9\]+, %zmm0" 1 } } */
/* { dg-final { scan-assembler-not "vbroadcastss\[^\n\]*%zmm\[0-9\]+" } } */
#define type __m512
#define vec 512
#define op fmadd
#define suffix ps
#define SCALAR float
#include "avx512-fma-5.h"

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mavx512f -O2" } */
/* { dg-final { scan-assembler-times "vfmadd...ps\[ \\t\]+\\(%(?:eax|rdi|edi)\\)\\\{1to\[1-8\]+\\\}, %zmm\[0-9\]+, %zmm0" 1 } } */
/* { dg-final { scan-assembler-not "vbroadcastss\[^\n\]*%zmm\[0-9\]+" } } */
#define type __m512
#define vec 512
#define op fmadd
#define suffix ps
#define SCALAR float
#include "avx512-fma-6.h"

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mavx512f -O2" } */
/* { dg-final { scan-assembler-times "vbroadcastss\[^\n\]*%zmm\[0-9\]+" 1 } } */
/* { dg-final { scan-assembler-times "vfmadd...ps\[^\n\]*%zmm\[0-9\]+" 1 } } */
#define type __m512
#define vec 512
#define op fmadd
#define suffix ps
#define SCALAR float
#include "avx512-fma-7.h"

View File

@ -0,0 +1,12 @@
/* { dg-do compile { target { ! ia32 } } } */
/* { dg-options "-mavx512f -O2" } */
/* { dg-final { scan-assembler-times "vbroadcastss\[^\n\]*%zmm\[0-9\]+" 1 } } */
/* { dg-final { scan-assembler-times "vfmadd...ps\[ \\t\]+%zmm\[0-9\]+, %zmm\[0-9\]+, %zmm0" 1 } } */
#define type __m512
#define vec 512
#define op fmadd
#define suffix ps
#define SCALAR float
#include "avx512-fma-8.h"

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mfma -mavx512vl -O2" } */
/* { dg-final { scan-assembler-times "vfmadd...ps\[ \\t\]+\\(%(?:eax|rdi|edi)\\)\\\{1to\[1-8\]+\\\}, %xmm\[0-9\]+, %xmm0" 1 } } */
/* { dg-final { scan-assembler-not "vbroadcastss\[^\n\]*%xmm\[0-9\]+" } } */
#define type __m128
#define vec
#define op fmadd
#define suffix ps
#define SCALAR float
#include "avx512-fma-1.h"

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mfma -mavx512vl -O2" } */
/* { dg-final { scan-assembler-times "vfmadd...ps\[ \\t\]+\\(%(?:eax|rdi|edi)\\)\\\{1to\[1-8\]+\\\}, %ymm\[0-9\]+, %ymm0" 1 } } */
/* { dg-final { scan-assembler-not "vbroadcastss\[^\n\]*%ymm\[0-9\]+" } } */
#define type __m256
#define vec 256
#define op fmadd
#define suffix ps
#define SCALAR float
#include "avx512-fma-1.h"