Skip to content

Commit e08f177

Browse files
committed
[X86][AVX] concat_vectors(scalar_to_vector(x),scalar_to_vector(x)) --> broadcast(x)
For AVX1, limit this to i32/f32/i64/f64 loading cases only. llvm-svn: 354730
1 parent 3179373 commit e08f177

File tree

3 files changed

+20
-42
lines changed

3 files changed

+20
-42
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41961,6 +41961,13 @@ static SDValue combineInsertSubvector(SDNode *N, SelectionDAG &DAG,
4196141961
SubVec.getOpcode() == X86ISD::SUBV_BROADCAST))
4196241962
return DAG.getNode(SubVec.getOpcode(), dl, OpVT, SubVec.getOperand(0));
4196341963

41964+
// concat_vectors(scalar_to_vector(x),scalar_to_vector(x)) -> broadcast(x)
41965+
if (SubVec == SubVec2 && SubVec.getOpcode() == ISD::SCALAR_TO_VECTOR &&
41966+
(Subtarget.hasAVX2() || (OpVT.getScalarSizeInBits() >= 32 &&
41967+
MayFoldLoad(SubVec.getOperand(0)))) &&
41968+
SubVec.getOperand(0).getValueType() == OpVT.getScalarType())
41969+
return DAG.getNode(X86ISD::VBROADCAST, dl, OpVT, SubVec.getOperand(0));
41970+
4196441971
// If we're inserting all zeros into the upper half, change this to
4196541972
// an insert into an all zeros vector. We will match this to a move
4196641973
// with implicit upper bit zeroing during isel.

llvm/test/CodeGen/X86/avx512dqvl-intrinsics-upgrade.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,10 +2718,9 @@ define <8 x i32>@test_int_x86_avx512_mask_broadcasti32x2_256(<4 x i32> %x0, <8 x
27182718
; X64-LABEL: test_int_x86_avx512_mask_broadcasti32x2_256:
27192719
; X64: # %bb.0:
27202720
; X64-NEXT: # kill: def $xmm0 killed $xmm0 def $ymm0
2721-
; X64-NEXT: vmovq (%rsi), %xmm2 # EVEX TO VEX Compression encoding: [0xc5,0xfa,0x7e,0x16]
2722-
; X64-NEXT: # xmm2 = mem[0],zero
27232721
; X64-NEXT: kmovw %edi, %k1 # encoding: [0xc5,0xf8,0x92,0xcf]
2724-
; X64-NEXT: vinserti32x4 $1, %xmm2, %ymm2, %ymm1 {%k1} # encoding: [0x62,0xf3,0x6d,0x29,0x38,0xca,0x01]
2722+
; X64-NEXT: vbroadcasti32x2 (%rsi), %ymm1 {%k1} # encoding: [0x62,0xf2,0x7d,0x29,0x59,0x0e]
2723+
; X64-NEXT: # ymm1 {%k1} = mem[0,1,0,1,0,1,0,1]
27252724
; X64-NEXT: vinserti128 $1, %xmm0, %ymm0, %ymm2 # EVEX TO VEX Compression encoding: [0xc4,0xe3,0x7d,0x38,0xd0,0x01]
27262725
; X64-NEXT: vinserti32x4 $1, %xmm0, %ymm0, %ymm0 {%k1} {z} # encoding: [0x62,0xf3,0x7d,0xa9,0x38,0xc0,0x01]
27272726
; X64-NEXT: vpaddd %ymm2, %ymm0, %ymm0 # EVEX TO VEX Compression encoding: [0xc5,0xfd,0xfe,0xc2]

llvm/test/CodeGen/X86/subvector-broadcast.ll

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,46 +1657,18 @@ define <4 x double> @broadcast_v4f64_v2f64_4u61(<2 x double>* %vp, <4 x double>
16571657
}
16581658

16591659
define <8 x float> @broadcast_v8f32_v2f32_u1uu0uEu(<2 x float>* %vp, <8 x float> %default) {
1660-
; X32-AVX1-LABEL: broadcast_v8f32_v2f32_u1uu0uEu:
1661-
; X32-AVX1: # %bb.0:
1662-
; X32-AVX1-NEXT: movl {{[0-9]+}}(%esp), %eax
1663-
; X32-AVX1-NEXT: vmovsd {{.*#+}} xmm1 = mem[0],zero
1664-
; X32-AVX1-NEXT: vinsertf128 $1, %xmm1, %ymm1, %ymm1
1665-
; X32-AVX1-NEXT: vblendps {{.*#+}} ymm0 = ymm1[0,1,2,3,4,5],ymm0[6,7]
1666-
; X32-AVX1-NEXT: retl
1667-
;
1668-
; X32-AVX2-LABEL: broadcast_v8f32_v2f32_u1uu0uEu:
1669-
; X32-AVX2: # %bb.0:
1670-
; X32-AVX2-NEXT: movl {{[0-9]+}}(%esp), %eax
1671-
; X32-AVX2-NEXT: vbroadcastsd (%eax), %ymm1
1672-
; X32-AVX2-NEXT: vblendps {{.*#+}} ymm0 = ymm1[0,1,2,3,4,5],ymm0[6,7]
1673-
; X32-AVX2-NEXT: retl
1674-
;
1675-
; X32-AVX512-LABEL: broadcast_v8f32_v2f32_u1uu0uEu:
1676-
; X32-AVX512: # %bb.0:
1677-
; X32-AVX512-NEXT: movl {{[0-9]+}}(%esp), %eax
1678-
; X32-AVX512-NEXT: vbroadcastsd (%eax), %ymm1
1679-
; X32-AVX512-NEXT: vblendps {{.*#+}} ymm0 = ymm1[0,1,2,3,4,5],ymm0[6,7]
1680-
; X32-AVX512-NEXT: retl
1681-
;
1682-
; X64-AVX1-LABEL: broadcast_v8f32_v2f32_u1uu0uEu:
1683-
; X64-AVX1: # %bb.0:
1684-
; X64-AVX1-NEXT: vmovsd {{.*#+}} xmm1 = mem[0],zero
1685-
; X64-AVX1-NEXT: vinsertf128 $1, %xmm1, %ymm1, %ymm1
1686-
; X64-AVX1-NEXT: vblendps {{.*#+}} ymm0 = ymm1[0,1,2,3,4,5],ymm0[6,7]
1687-
; X64-AVX1-NEXT: retq
1688-
;
1689-
; X64-AVX2-LABEL: broadcast_v8f32_v2f32_u1uu0uEu:
1690-
; X64-AVX2: # %bb.0:
1691-
; X64-AVX2-NEXT: vbroadcastsd (%rdi), %ymm1
1692-
; X64-AVX2-NEXT: vblendps {{.*#+}} ymm0 = ymm1[0,1,2,3,4,5],ymm0[6,7]
1693-
; X64-AVX2-NEXT: retq
1660+
; X32-LABEL: broadcast_v8f32_v2f32_u1uu0uEu:
1661+
; X32: # %bb.0:
1662+
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
1663+
; X32-NEXT: vbroadcastsd (%eax), %ymm1
1664+
; X32-NEXT: vblendps {{.*#+}} ymm0 = ymm1[0,1,2,3,4,5],ymm0[6,7]
1665+
; X32-NEXT: retl
16941666
;
1695-
; X64-AVX512-LABEL: broadcast_v8f32_v2f32_u1uu0uEu:
1696-
; X64-AVX512: # %bb.0:
1697-
; X64-AVX512-NEXT: vbroadcastsd (%rdi), %ymm1
1698-
; X64-AVX512-NEXT: vblendps {{.*#+}} ymm0 = ymm1[0,1,2,3,4,5],ymm0[6,7]
1699-
; X64-AVX512-NEXT: retq
1667+
; X64-LABEL: broadcast_v8f32_v2f32_u1uu0uEu:
1668+
; X64: # %bb.0:
1669+
; X64-NEXT: vbroadcastsd (%rdi), %ymm1
1670+
; X64-NEXT: vblendps {{.*#+}} ymm0 = ymm1[0,1,2,3,4,5],ymm0[6,7]
1671+
; X64-NEXT: retq
17001672
%vec = load <2 x float>, <2 x float>* %vp
17011673
%shuf = shufflevector <2 x float> %vec, <2 x float> undef, <8 x i32> <i32 undef, i32 1, i32 undef, i32 undef, i32 0, i32 2, i32 3, i32 undef>
17021674
%res = select <8 x i1> <i1 1, i1 1, i1 1, i1 1, i1 1, i1 1, i1 0, i1 1>, <8 x float> %shuf, <8 x float> %default

0 commit comments

Comments
 (0)