Skip to content

Commit e4d5423

Browse files
committed
[X86][AVX] SimplifyDemandedVectorElts - handle extraction from X86ISD::SUBV_BROADCAST source (PR42819)
PR42819 showed an issue that we couldn't handle the case where we demanded a 'sub-sub-vector' of the SUBV_BROADCAST 'sub-vector' source. This patch recognizes these cases and extracts the sub-sub-vector instead of trying to broadcast to a type smaller than the 'sub-vector' source. llvm-svn: 367306
1 parent b9f8ab2 commit e4d5423

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34214,14 +34214,16 @@ bool X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode(
3421434214
// Subvector broadcast.
3421534215
case X86ISD::SUBV_BROADCAST: {
3421634216
SDLoc DL(Op);
34217-
SDValue Ext = Op.getOperand(0);
34218-
if (Ext.getValueSizeInBits() != ExtSizeInBits) {
34219-
MVT ExtSVT = Ext.getSimpleValueType().getScalarType();
34220-
MVT ExtVT =
34221-
MVT::getVectorVT(ExtSVT, ExtSizeInBits / ExtSVT.getSizeInBits());
34222-
Ext = TLO.DAG.getNode(X86ISD::SUBV_BROADCAST, DL, ExtVT, Ext);
34223-
}
34224-
return TLO.CombineTo(Op, insertSubVector(TLO.DAG.getUNDEF(VT), Ext, 0,
34217+
SDValue Src = Op.getOperand(0);
34218+
if (Src.getValueSizeInBits() > ExtSizeInBits)
34219+
Src = extractSubVector(Src, 0, TLO.DAG, DL, ExtSizeInBits);
34220+
else if (Src.getValueSizeInBits() < ExtSizeInBits) {
34221+
MVT SrcSVT = Src.getSimpleValueType().getScalarType();
34222+
MVT SrcVT =
34223+
MVT::getVectorVT(SrcSVT, ExtSizeInBits / SrcSVT.getSizeInBits());
34224+
Src = TLO.DAG.getNode(X86ISD::SUBV_BROADCAST, DL, SrcVT, Src);
34225+
}
34226+
return TLO.CombineTo(Op, insertSubVector(TLO.DAG.getUNDEF(VT), Src, 0,
3422534227
TLO.DAG, DL, ExtSizeInBits));
3422634228
}
3422734229
// Byte shifts by immediate.

llvm/test/CodeGen/X86/oddsubvector.ll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,35 @@ define void @PR40815(%struct.Mat4* nocapture readonly dereferenceable(64), %stru
158158
store <4 x float> %5, <4 x float>* %13, align 16
159159
ret void
160160
}
161+
162+
define <16 x i32> @PR42819(<8 x i32>* %a0) {
163+
; SSE-LABEL: PR42819:
164+
; SSE: # %bb.0:
165+
; SSE-NEXT: movdqu (%rdi), %xmm3
166+
; SSE-NEXT: pslldq {{.*#+}} xmm3 = zero,zero,zero,zero,xmm3[0,1,2,3,4,5,6,7,8,9,10,11]
167+
; SSE-NEXT: xorps %xmm0, %xmm0
168+
; SSE-NEXT: xorps %xmm1, %xmm1
169+
; SSE-NEXT: xorps %xmm2, %xmm2
170+
; SSE-NEXT: retq
171+
;
172+
; AVX-LABEL: PR42819:
173+
; AVX: # %bb.0:
174+
; AVX-NEXT: vpermilps {{.*#+}} xmm0 = mem[0,0,1,2]
175+
; AVX-NEXT: vinsertf128 $1, %xmm0, %ymm0, %ymm0
176+
; AVX-NEXT: vxorps %xmm1, %xmm1, %xmm1
177+
; AVX-NEXT: vblendps {{.*#+}} ymm1 = ymm1[0,1,2,3,4],ymm0[5,6,7]
178+
; AVX-NEXT: vxorps %xmm0, %xmm0, %xmm0
179+
; AVX-NEXT: retq
180+
;
181+
; AVX512-LABEL: PR42819:
182+
; AVX512: # %bb.0:
183+
; AVX512-NEXT: vmovdqu (%rdi), %xmm0
184+
; AVX512-NEXT: movw $-8192, %ax # imm = 0xE000
185+
; AVX512-NEXT: kmovw %eax, %k1
186+
; AVX512-NEXT: vpexpandd %zmm0, %zmm0 {%k1} {z}
187+
; AVX512-NEXT: retq
188+
%1 = load <8 x i32>, <8 x i32>* %a0, align 4
189+
%2 = shufflevector <8 x i32> %1, <8 x i32> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
190+
%3 = shufflevector <16 x i32> zeroinitializer, <16 x i32> %2, <16 x i32> <i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18>
191+
ret <16 x i32> %3
192+
}

0 commit comments

Comments
 (0)