Skip to content

Commit 39be138

Browse files
committed
[X86] combineTargetShuffle - fold SHUF128(CONCAT(),CONCAT()) to peek through upper subvectors
If SHUF128 is accessing only the upper half of a vector source that is a concatenation/insert_subvector then try to access the subvector directly and adjust the element mask accordingly.
1 parent 58a335a commit 39be138

File tree

5 files changed

+713
-719
lines changed

5 files changed

+713
-719
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40221,6 +40221,34 @@ static SDValue combineTargetShuffle(SDValue N, SelectionDAG &DAG,
4022140221
}
4022240222
return SDValue();
4022340223
}
40224+
case X86ISD::SHUF128: {
40225+
// If we're permuting the upper 256-bits subvectors of a concatenation, then
40226+
// see if we can peek through and access the subvector directly.
40227+
if (VT.is512BitVector()) {
40228+
// 512-bit mask uses 4 x i2 indices - if the msb is always set then only the
40229+
// upper subvector is used.
40230+
SDValue LHS = N->getOperand(0);
40231+
SDValue RHS = N->getOperand(1);
40232+
uint64_t Mask = N->getConstantOperandVal(2);
40233+
SmallVector<SDValue> LHSOps, RHSOps;
40234+
SDValue NewLHS, NewRHS;
40235+
if ((Mask & 0x0A) == 0x0A &&
40236+
collectConcatOps(LHS.getNode(), LHSOps, DAG) && LHSOps.size() == 2) {
40237+
NewLHS = widenSubVector(LHSOps[1], false, Subtarget, DAG, DL, 512);
40238+
Mask &= ~0x0A;
40239+
}
40240+
if ((Mask & 0xA0) == 0xA0 &&
40241+
collectConcatOps(RHS.getNode(), RHSOps, DAG) && RHSOps.size() == 2) {
40242+
NewRHS = widenSubVector(RHSOps[1], false, Subtarget, DAG, DL, 512);
40243+
Mask &= ~0xA0;
40244+
}
40245+
if (NewLHS || NewRHS)
40246+
return DAG.getNode(X86ISD::SHUF128, DL, VT, NewLHS ? NewLHS : LHS,
40247+
NewRHS ? NewRHS : RHS,
40248+
DAG.getTargetConstant(Mask, DL, MVT::i8));
40249+
}
40250+
return SDValue();
40251+
}
4022440252
case X86ISD::VPERM2X128: {
4022540253
// Fold vperm2x128(bitcast(x),bitcast(y),c) -> bitcast(vperm2x128(x,y,c)).
4022640254
SDValue LHS = N->getOperand(0);

0 commit comments

Comments
 (0)