Skip to content

Commit 81cf80c

Browse files
committed
Replace getShiftForeReduction with an additional combine in
performExtractVectorEltCombine().
1 parent 90fa0e7 commit 81cf80c

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,9 +4146,6 @@ SDValue AMDGPUTargetLowering::performShlCombine(SDNode *N,
41464146
SDLoc SL(N);
41474147
SelectionDAG &DAG = DCI.DAG;
41484148

4149-
if (SDValue R = getShiftForReduction(N, DAG))
4150-
return R;
4151-
41524149
unsigned RHSVal;
41534150
if (CRHS) {
41544151
RHSVal = CRHS->getZExtValue();
@@ -4249,9 +4246,6 @@ SDValue AMDGPUTargetLowering::performSraCombine(SDNode *N,
42494246
SelectionDAG &DAG = DCI.DAG;
42504247
SDLoc SL(N);
42514248

4252-
if (SDValue R = getShiftForReduction(N, DAG))
4253-
return R;
4254-
42554249
if (VT.getScalarType() != MVT::i64)
42564250
return SDValue();
42574251

@@ -4354,9 +4348,6 @@ SDValue AMDGPUTargetLowering::performSrlCombine(SDNode *N,
43544348
SDLoc SL(N);
43554349
unsigned RHSVal;
43564350

4357-
if (SDValue R = getShiftForReduction(N, DAG))
4358-
return R;
4359-
43604351
if (CRHS) {
43614352
RHSVal = CRHS->getZExtValue();
43624353

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14674,6 +14674,35 @@ SITargetLowering::performExtractVectorEltCombine(SDNode *N,
1467414674
return DAG.getNode(Vec.getOpcode(), SL, ResVT, Elt);
1467514675
}
1467614676

14677+
// (extract_vector_element (and {y0, y1}, (build_vector 0x1f, 0x1f)), index)
14678+
// -> (and (extract_vector_element {yo, y1}, index), 0x1f)
14679+
// There are optimisations to transform 64-bit shifts into 32-bit shifts
14680+
// depending on the shift operand. See e.g. performSraCombine().
14681+
// This combine ensures that the optimisation is compatible with v2i32
14682+
// legalised AND.
14683+
if (VecVT == MVT::v2i32 && Vec->getOpcode() == ISD::AND &&
14684+
Vec->getOperand(1)->getOpcode() == ISD::BUILD_VECTOR) {
14685+
SDValue BV = Vec->getOperand(1);
14686+
14687+
ConstantSDNode *BV0 = dyn_cast<ConstantSDNode>(BV->getOperand(0));
14688+
ConstantSDNode *BV1 = dyn_cast<ConstantSDNode>(BV->getOperand(1));
14689+
14690+
if (!BV0 || !BV1 || BV->getConstantOperandVal(0) != 0x1f ||
14691+
BV->getConstantOperandVal(1) != 0x1f)
14692+
return SDValue();
14693+
14694+
SDLoc SL(N);
14695+
SDValue AndMask = DAG.getConstant(0x1f, SL, MVT::i32);
14696+
ConstantSDNode *Index = dyn_cast<ConstantSDNode>(N->getOperand(1));
14697+
uint64_t I = Index->getZExtValue();
14698+
const SDValue Zero = DAG.getConstant(0, SL, MVT::i32);
14699+
const SDValue One = DAG.getConstant(1, SL, MVT::i32);
14700+
SDValue EVE = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32,
14701+
Vec->getOperand(0), I == 0 ? Zero : One);
14702+
SDValue A = DAG.getNode(ISD::AND, SL, MVT::i32, EVE, AndMask);
14703+
DAG.ReplaceAllUsesWith(N, A.getNode());
14704+
}
14705+
1467714706
// ScalarRes = EXTRACT_VECTOR_ELT ((vector-BINOP Vec1, Vec2), Idx)
1467814707
// =>
1467914708
// Vec1Elt = EXTRACT_VECTOR_ELT(Vec1, Idx)

0 commit comments

Comments
 (0)