@@ -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