Skip to content

Commit c711c65

Browse files
authored
[X86] combineINSERT_SUBVECTOR - attempt to constant fold from constant pool loads (if we're not widening). (#129682)
1 parent 1e1781b commit c711c65

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58684,6 +58684,21 @@ static SDValue combineINSERT_SUBVECTOR(SDNode *N, SelectionDAG &DAG,
5868458684
}
5868558685
}
5868658686

58687+
// Attempt to constant fold (if we're not widening).
58688+
if (!Vec.isUndef() && !ISD::isBuildVectorAllZeros(Vec.getNode())) {
58689+
unsigned EltSizeInBits = OpVT.getScalarSizeInBits();
58690+
APInt VecUndefElts, SubUndefElts;
58691+
SmallVector<APInt, 16> VecEltBits, SubEltBits;
58692+
if (getTargetConstantBitsFromNode(Vec, EltSizeInBits, VecUndefElts,
58693+
VecEltBits) &&
58694+
getTargetConstantBitsFromNode(SubVec, EltSizeInBits, SubUndefElts,
58695+
SubEltBits)) {
58696+
VecUndefElts.insertBits(SubUndefElts, IdxVal);
58697+
llvm::copy(SubEltBits, VecEltBits.begin() + IdxVal);
58698+
return getConstVector(VecEltBits, VecUndefElts, OpVT, DAG, dl);
58699+
}
58700+
}
58701+
5868758702
return SDValue();
5868858703
}
5868958704

llvm/test/CodeGen/X86/vector-shuffle-combining-xop.ll

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,11 @@ define <4 x double> @demandedelts_vpermil2pd256_as_shufpd(<4 x double> %a0, <4 x
140140
; X86-NEXT: vshufpd {{.*#+}} ymm0 = ymm0[1,1,2,3]
141141
; X86-NEXT: retl
142142
;
143-
; X64-AVX-LABEL: demandedelts_vpermil2pd256_as_shufpd:
144-
; X64-AVX: # %bb.0:
145-
; X64-AVX-NEXT: vpermil2pd {{.*#+}} ymm0 = ymm1[0,0],ymm0[3],ymm1[3]
146-
; X64-AVX-NEXT: retq
147-
;
148-
; X64-AVX2-LABEL: demandedelts_vpermil2pd256_as_shufpd:
149-
; X64-AVX2: # %bb.0:
150-
; X64-AVX2-NEXT: vshufpd {{.*#+}} ymm0 = ymm0[0],ymm1[0],ymm0[3],ymm1[3]
151-
; X64-AVX2-NEXT: vshufpd {{.*#+}} ymm0 = ymm0[1,1,2,3]
152-
; X64-AVX2-NEXT: retq
143+
; X64-LABEL: demandedelts_vpermil2pd256_as_shufpd:
144+
; X64: # %bb.0:
145+
; X64-NEXT: vshufpd {{.*#+}} ymm0 = ymm0[0],ymm1[0],ymm0[3],ymm1[3]
146+
; X64-NEXT: vshufpd {{.*#+}} ymm0 = ymm0[1,1,2,3]
147+
; X64-NEXT: retq
153148
%res0 = insertelement <4 x i64> <i64 0, i64 4, i64 2, i64 7>, i64 %a2, i32 0
154149
%res1 = call <4 x double> @llvm.x86.xop.vpermil2pd.256(<4 x double> %a0, <4 x double> %a1, <4 x i64> %res0, i8 0)
155150
%res2 = shufflevector <4 x double> %res1, <4 x double> undef, <4 x i32> <i32 1, i32 1, i32 2, i32 3>

0 commit comments

Comments
 (0)