Many AVX512 vector operations can broadcast from a scalar memory source.
This patch enables memory broadcast for FP add operations.
gcc/
PR target/72782
* config/i386/sse.md
(*<plusminus_insn><mode>3<mask_name>_bcst_1): New.
(*add<mode>3<mask_name>_bcst_2): Likewise.
gcc/testsuite/
PR target/72782
* gcc.target/i386/avx512-binop-1.h: New file.
* gcc.target/i386/avx512-binop-2.h: Likewise.
* gcc.target/i386/avx512-binop-3.h: Likewise.
* gcc.target/i386/avx512-binop-4.h: Likewise.
* gcc.target/i386/avx512-binop-5.h: Likewise.
* gcc.target/i386/avx512-binop-6.h: Likewise.
* gcc.target/i386/avx512f-add-df-zmm-1.c: Likewise.
* gcc.target/i386/avx512f-add-sf-zmm-1.c: Likewise.
* gcc.target/i386/avx512f-add-sf-zmm-2.c: Likewise.
* gcc.target/i386/avx512f-add-sf-zmm-3.c: Likewise.
* gcc.target/i386/avx512f-add-sf-zmm-4.c: Likewise.
* gcc.target/i386/avx512f-add-sf-zmm-5.c: Likewise.
* gcc.target/i386/avx512f-add-sf-zmm-6.c: Likewise.
* gcc.target/i386/avx512f-sub-df-zmm-1.c: Likewise.
* gcc.target/i386/avx512f-sub-sf-zmm-1.c: Likewise.
* gcc.target/i386/avx512f-sub-sf-zmm-2.c: Likewise.
* gcc.target/i386/avx512f-sub-sf-zmm-3.c: Likewise.
* gcc.target/i386/avx512f-sub-sf-zmm-4.c: Likewise.
* gcc.target/i386/avx512f-sub-sf-zmm-5.c: Likewise.
* gcc.target/i386/avx512vl-add-sf-xmm-1.c: Likewise.
* gcc.target/i386/avx512vl-add-sf-ymm-1.c: Likewise.
* gcc.target/i386/avx512vl-sub-sf-xmm-1.c: Likewise.
* gcc.target/i386/avx512vl-sub-sf-ymm-1.c: Likewise.
From-SVN: r265311
2018-10-19 H.J. Lu <hongjiu.lu@intel.com>
+ PR target/72782
+ * config/i386/sse.md
+ (*<plusminus_insn><mode>3<mask_name>_bcst_1): New.
+ (*add<mode>3<mask_name>_bcst_2): Likewise.
+
+2018-10-19 H.J. Lu <hongjiu.lu@intel.com>
+
* config/i386/sse.md
(*<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name>_bcst_1):
Replace nonimmediate_operand with register_operand.
(set_attr "prefix" "<mask_prefix3>")
(set_attr "mode" "<MODE>")])
+(define_insn "*<plusminus_insn><mode>3<mask_name>_bcst_1"
+ [(set (match_operand:VF_AVX512 0 "register_operand" "=v")
+ (plusminus:VF_AVX512
+ (match_operand:VF_AVX512 1 "register_operand" "v")
+ (vec_duplicate:VF_AVX512
+ (match_operand:<ssescalarmode> 2 "memory_operand" "m"))))]
+ "TARGET_AVX512F
+ && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)
+ && <mask_mode512bit_condition>"
+ "v<plusminus_mnemonic><ssemodesuffix>\t{%2<avx512bcst>, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2<avx512bcst>}"
+ [(set_attr "prefix" "evex")
+ (set_attr "type" "sseadd")
+ (set_attr "mode" "<MODE>")])
+
+(define_insn "*add<mode>3<mask_name>_bcst_2"
+ [(set (match_operand:VF_AVX512 0 "register_operand" "=v")
+ (plus:VF_AVX512
+ (vec_duplicate:VF_AVX512
+ (match_operand:<ssescalarmode> 1 "memory_operand" "m"))
+ (match_operand:VF_AVX512 2 "register_operand" "v")))]
+ "TARGET_AVX512F
+ && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)
+ && <mask_mode512bit_condition>"
+ "vadd<ssemodesuffix>\t{%1<avx512bcst>, %2, %0<mask_operand3>|%0<mask_operand3>, %2, %1<avx512bcst>}"
+ [(set_attr "prefix" "evex")
+ (set_attr "type" "sseadd")
+ (set_attr "mode" "<MODE>")])
+
(define_insn "<sse>_vm<plusminus_insn><mode>3<mask_scalar_name><round_scalar_name>"
[(set (match_operand:VF_128 0 "register_operand" "=x,v")
(vec_merge:VF_128
+2018-10-19 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR target/72782
+ * gcc.target/i386/avx512-binop-1.h: New file.
+ * gcc.target/i386/avx512-binop-2.h: Likewise.
+ * gcc.target/i386/avx512-binop-3.h: Likewise.
+ * gcc.target/i386/avx512-binop-4.h: Likewise.
+ * gcc.target/i386/avx512-binop-5.h: Likewise.
+ * gcc.target/i386/avx512-binop-6.h: Likewise.
+ * gcc.target/i386/avx512f-add-df-zmm-1.c: Likewise.
+ * gcc.target/i386/avx512f-add-sf-zmm-1.c: Likewise.
+ * gcc.target/i386/avx512f-add-sf-zmm-2.c: Likewise.
+ * gcc.target/i386/avx512f-add-sf-zmm-3.c: Likewise.
+ * gcc.target/i386/avx512f-add-sf-zmm-4.c: Likewise.
+ * gcc.target/i386/avx512f-add-sf-zmm-5.c: Likewise.
+ * gcc.target/i386/avx512f-add-sf-zmm-6.c: Likewise.
+ * gcc.target/i386/avx512f-sub-df-zmm-1.c: Likewise.
+ * gcc.target/i386/avx512f-sub-sf-zmm-1.c: Likewise.
+ * gcc.target/i386/avx512f-sub-sf-zmm-2.c: Likewise.
+ * gcc.target/i386/avx512f-sub-sf-zmm-3.c: Likewise.
+ * gcc.target/i386/avx512f-sub-sf-zmm-4.c: Likewise.
+ * gcc.target/i386/avx512f-sub-sf-zmm-5.c: Likewise.
+ * gcc.target/i386/avx512vl-add-sf-xmm-1.c: Likewise.
+ * gcc.target/i386/avx512vl-add-sf-ymm-1.c: Likewise.
+ * gcc.target/i386/avx512vl-sub-sf-xmm-1.c: Likewise.
+ * gcc.target/i386/avx512vl-sub-sf-ymm-1.c: Likewise.
+
2018-10-19 Ilya Leoshkevich <iii@linux.ibm.com>
PR rtl-optimization/87596
--- /dev/null
+#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, SCALAR *f)
+{
+ return OP (vec, op, suffix) (x , DUP (vec, suffix, *f));
+}
--- /dev/null
+#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, SCALAR *f)
+{
+ return OP (vec, op, suffix) (DUP (vec, suffix, *f), x);
+}
--- /dev/null
+#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)
+
+extern SCALAR bar (void);
+
+type
+foo (type x)
+{
+ SCALAR f = bar ();
+ return OP (vec, op, suffix) (DUP (vec, suffix, f), x);
+}
--- /dev/null
+#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, SCALAR f)
+{
+ return OP (vec, op, suffix) (DUP (vec, suffix, f), x);
+}
--- /dev/null
+#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)
+
+extern SCALAR f;
+
+type
+foo (type x)
+{
+ return OP (vec, op, suffix) (x , DUP (vec, suffix, f));
+}
--- /dev/null
+#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)
+
+extern SCALAR f;
+
+type
+foo (type x)
+{
+ return OP (vec, op, suffix) (DUP (vec, suffix, f), x);
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vaddpd\[ \\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 add
+#define suffix pd
+#define SCALAR double
+
+#include "avx512-binop-1.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vaddps\[ \\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 add
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-1.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vaddps\[ \\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 add
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-2.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vbroadcastss\[^\n\]*%zmm\[0-9\]+" 1 } } */
+/* { dg-final { scan-assembler-times "vaddps\[^\n\]*%zmm\[0-9\]+" 1 } } */
+
+#define type __m512
+#define vec 512
+#define op add
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-3.h"
--- /dev/null
+/* { 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 "vaddps\[ \\t\]+%zmm\[0-9\]+, %zmm\[0-9\]+, %zmm0" 1 } } */
+
+#define type __m512
+#define vec 512
+#define op add
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-4.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vaddps\[ \\t\]+\[^\n\]*\\\{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 add
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-5.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vaddps\[ \\t\]+\[^\n\]*\\\{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 add
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-6.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vsubpd\[ \\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 sub
+#define suffix pd
+#define SCALAR double
+
+#include "avx512-binop-1.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vsubps\[ \\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 sub
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-1.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vbroadcastss\[^\n\]*%zmm\[0-9\]+" 1 } } */
+/* { dg-final { scan-assembler-times "vsubps\[^\n\]*%zmm\[0-9\]+" 1 } } */
+
+#define type __m512
+#define vec 512
+#define op sub
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-2.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vbroadcastss\[^\n\]*%zmm\[0-9\]+" 1 } } */
+/* { dg-final { scan-assembler-times "vsubps\[^\n\]*%zmm\[0-9\]+" 1 } } */
+
+#define type __m512
+#define vec 512
+#define op sub
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-3.h"
--- /dev/null
+/* { 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 "vsubps\[ \\t\]+%zmm\[0-9\]+, %zmm\[0-9\]+, %zmm0" 1 } } */
+
+#define type __m512
+#define vec 512
+#define op sub
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-4.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mavx512f -O2" } */
+/* { dg-final { scan-assembler-times "vbroadcastss\[^\n\]*%zmm\[0-9\]+" 1 } } */
+/* { dg-final { scan-assembler-times "vsubps\[^\n\]*%zmm\[0-9\]+" 1 } } */
+
+#define type __m512
+#define vec 512
+#define op sub
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-6.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mfma -mavx512vl -O2" } */
+/* { dg-final { scan-assembler-times "vaddps\[ \\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 add
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-1.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mfma -mavx512vl -O2" } */
+/* { dg-final { scan-assembler-times "vaddps\[ \\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 add
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-1.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mfma -mavx512vl -O2" } */
+/* { dg-final { scan-assembler-times "vsubps\[ \\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 sub
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-1.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mfma -mavx512vl -O2" } */
+/* { dg-final { scan-assembler-times "vsubps\[ \\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 sub
+#define suffix ps
+#define SCALAR float
+
+#include "avx512-binop-1.h"