@@ -9580,6 +9580,37 @@ static bool isValidSplatLoad(const PPCSubtarget &Subtarget, const SDValue &Op,
95809580 return false;
95819581}
95829582
9583+ bool isValidMtVsrbmi(APInt &BMI, BuildVectorSDNode &BVN) {
9584+ unsigned int NumOps = BVN.getNumOperands();
9585+ assert(NumOps > 0 && "isConstantSplat has 0-size build vector");
9586+
9587+ BMI.clearAllBits();
9588+ EVT VT = BVN.getValueType(0);
9589+ APInt ConstValue(VT.getSizeInBits(), 0);
9590+
9591+ unsigned EltWidth = VT.getScalarSizeInBits();
9592+
9593+ for (unsigned j = 0; j < NumOps; ++j) {
9594+ SDValue OpVal = BVN.getOperand(j);
9595+ unsigned BitPos = j * EltWidth;
9596+ auto *CN = dyn_cast<ConstantSDNode>(OpVal);
9597+
9598+ if (!CN)
9599+ return false;
9600+
9601+ ConstValue.insertBits(CN->getAPIntValue().zextOrTrunc(EltWidth), BitPos);
9602+ }
9603+
9604+ for (unsigned J = 0; J < 16; J++) {
9605+ APInt ExtractValue = ConstValue.extractBits(8, J * 8);
9606+ if (ExtractValue != 0x00 && ExtractValue != 0xFF)
9607+ return false;
9608+ if (ExtractValue == 0xFF)
9609+ BMI.setBit(J);
9610+ }
9611+ return true;
9612+ }
9613+
95839614// If this is a case we can't handle, return null and let the default
95849615// expansion code take care of it. If we CAN select this case, and if it
95859616// selects to a single instruction, return Op. Otherwise, if we can codegen
@@ -9591,6 +9622,24 @@ SDValue PPCTargetLowering::LowerBUILD_VECTOR(SDValue Op,
95919622 BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode());
95929623 assert(BVN && "Expected a BuildVectorSDNode in LowerBUILD_VECTOR");
95939624
9625+ if(Subtarget.hasP10Vector()) {
9626+ APInt BMI(32, 0);
9627+ // If the value of the vector is all zeros or all ones,
9628+ // we do not convert it to MTVSRBMI.
9629+ // The xxleqv instruction sets a vector with all ones.
9630+ // The xxlxor instruction sets a vector with all zeros.
9631+ if (isValidMtVsrbmi(BMI, *BVN) && BMI != 0 && BMI!=0xffff ) {
9632+ SDValue SDConstant= DAG.getTargetConstant(BMI, dl, MVT::i32);
9633+ MachineSDNode* MSDNode = DAG.getMachineNode(PPC::MTVSRBMI, dl,MVT::v16i8, SDConstant);
9634+ SDValue SDV = SDValue(MSDNode,0);
9635+ EVT DVT = BVN->getValueType(0);
9636+ EVT SVT = SDV.getValueType();
9637+ if (SVT != DVT ) {
9638+ SDV = DAG.getNode(ISD::BITCAST, dl, DVT, SDV);
9639+ }
9640+ return SDV;
9641+ }
9642+ }
95949643 // Check if this is a splat of a constant value.
95959644 APInt APSplatBits, APSplatUndef;
95969645 unsigned SplatBitSize;
0 commit comments