1 ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=avx < %s | FileCheck %s -check-prefix=CHECK --check-prefix=AVX
2 ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=avx2 < %s | FileCheck %s -check-prefix=CHECK --check-prefix=AVX2
4 ; Check constant loads of every 128-bit and 256-bit vector type
5 ; for size optimization using splat ops available with AVX and AVX2.
7 ; There is no AVX broadcast from double to 128-bit vector because movddup has been around since SSE3 (grrr).
8 define <2 x double> @splat_v2f64(<2 x double> %x) #0 {
9 %add = fadd <2 x double> %x, <double 1.0, double 1.0>
11 ; CHECK-LABEL: splat_v2f64
17 define <4 x double> @splat_v4f64(<4 x double> %x) #1 {
18 %add = fadd <4 x double> %x, <double 1.0, double 1.0, double 1.0, double 1.0>
20 ; CHECK-LABEL: splat_v4f64
26 define <4 x float> @splat_v4f32(<4 x float> %x) #0 {
27 %add = fadd <4 x float> %x, <float 1.0, float 1.0, float 1.0, float 1.0>
29 ; CHECK-LABEL: splat_v4f32
35 define <8 x float> @splat_v8f32(<8 x float> %x) #1 {
36 %add = fadd <8 x float> %x, <float 1.0, float 1.0, float 1.0, float 1.0, float 1.0, float 1.0, float 1.0, float 1.0>
38 ; CHECK-LABEL: splat_v8f32
44 ; AVX can't do integer splats, so fake it: use vmovddup to splat 64-bit value.
45 ; We also generate vmovddup for AVX2 because it's one byte smaller than vpbroadcastq.
46 define <2 x i64> @splat_v2i64(<2 x i64> %x) #1 {
47 %add = add <2 x i64> %x, <i64 1, i64 1>
49 ; CHECK-LABEL: splat_v2i64
55 ; AVX can't do 256-bit integer ops, so we split this into two 128-bit vectors,
56 ; and then we fake it: use vmovddup to splat 64-bit value.
57 define <4 x i64> @splat_v4i64(<4 x i64> %x) #0 {
58 %add = add <4 x i64> %x, <i64 1, i64 1, i64 1, i64 1>
60 ; CHECK-LABEL: splat_v4i64
69 ; AVX can't do integer splats, so fake it: use vbroadcastss to splat 32-bit value.
70 define <4 x i32> @splat_v4i32(<4 x i32> %x) #1 {
71 %add = add <4 x i32> %x, <i32 1, i32 1, i32 1, i32 1>
73 ; CHECK-LABEL: splat_v4i32
80 ; AVX can't do integer splats, so fake it: use vbroadcastss to splat 32-bit value.
81 define <8 x i32> @splat_v8i32(<8 x i32> %x) #0 {
82 %add = add <8 x i32> %x, <i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1>
84 ; CHECK-LABEL: splat_v8i32
93 ; AVX can't do integer splats, and there's no broadcast fakery for 16-bit. Could use pshuflw, etc?
94 define <8 x i16> @splat_v8i16(<8 x i16> %x) #1 {
95 %add = add <8 x i16> %x, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
97 ; CHECK-LABEL: splat_v8i16
104 ; AVX can't do integer splats, and there's no broadcast fakery for 16-bit. Could use pshuflw, etc?
105 define <16 x i16> @splat_v16i16(<16 x i16> %x) #0 {
106 %add = add <16 x i16> %x, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
108 ; CHECK-LABEL: splat_v16i16
117 ; AVX can't do integer splats, and there's no broadcast fakery for 8-bit. Could use pshufb, etc?
118 define <16 x i8> @splat_v16i8(<16 x i8> %x) #1 {
119 %add = add <16 x i8> %x, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
121 ; CHECK-LABEL: splat_v16i8
128 ; AVX can't do integer splats, and there's no broadcast fakery for 8-bit. Could use pshufb, etc?
129 define <32 x i8> @splat_v32i8(<32 x i8> %x) #0 {
130 %add = add <32 x i8> %x, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
132 ; CHECK-LABEL: splat_v32i8
141 ; PR23259: Verify that ISel doesn't crash with a 'fatal error in backend'
142 ; due to a missing AVX pattern to select a v2i64 X86ISD::BROADCAST of a
143 ; loadi64 with multiple uses.
145 @A = common global <3 x i64> zeroinitializer, align 32
147 define <8 x i64> @pr23259() #1 {
149 %0 = load <4 x i64>, <4 x i64>* bitcast (<3 x i64>* @A to <4 x i64>*), align 32
150 %1 = shufflevector <4 x i64> %0, <4 x i64> undef, <3 x i32> <i32 undef, i32 undef, i32 2>
151 %shuffle = shufflevector <3 x i64> <i64 1, i64 undef, i64 undef>, <3 x i64> %1, <8 x i32> <i32 5, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>
152 ret <8 x i64> %shuffle
155 attributes #0 = { optsize }
156 attributes #1 = { minsize }