From 3267de7215e340562677434fd085e3e4c20af746 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 16 Dec 2021 16:22:39 +0000 Subject: [PATCH] [X86] combineAnd - pull out repeated getOperand() and SDLoc() calls. NFCI. --- llvm/lib/Target/X86/X86ISelLowering.cpp | 43 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index cdad73f..8e72ce7 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -46250,25 +46250,27 @@ static SDValue combineScalarAndWithMaskSetcc(SDNode *N, SelectionDAG &DAG, static SDValue combineAnd(SDNode *N, SelectionDAG &DAG, TargetLowering::DAGCombinerInfo &DCI, const X86Subtarget &Subtarget) { + SDValue N0 = N->getOperand(0); + SDValue N1 = N->getOperand(1); EVT VT = N->getValueType(0); + SDLoc dl(N); + const TargetLowering &TLI = DAG.getTargetLoweringInfo(); // If this is SSE1 only convert to FAND to avoid scalarization. if (Subtarget.hasSSE1() && !Subtarget.hasSSE2() && VT == MVT::v4i32) { - return DAG.getBitcast( - MVT::v4i32, DAG.getNode(X86ISD::FAND, SDLoc(N), MVT::v4f32, - DAG.getBitcast(MVT::v4f32, N->getOperand(0)), - DAG.getBitcast(MVT::v4f32, N->getOperand(1)))); + return DAG.getBitcast(MVT::v4i32, + DAG.getNode(X86ISD::FAND, dl, MVT::v4f32, + DAG.getBitcast(MVT::v4f32, N0), + DAG.getBitcast(MVT::v4f32, N1))); } // Use a 32-bit and+zext if upper bits known zero. - if (VT == MVT::i64 && Subtarget.is64Bit() && - !isa(N->getOperand(1))) { + if (VT == MVT::i64 && Subtarget.is64Bit() && !isa(N1)) { APInt HiMask = APInt::getHighBitsSet(64, 32); - if (DAG.MaskedValueIsZero(N->getOperand(1), HiMask) || - DAG.MaskedValueIsZero(N->getOperand(0), HiMask)) { - SDLoc dl(N); - SDValue LHS = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, N->getOperand(0)); - SDValue RHS = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, N->getOperand(1)); + if (DAG.MaskedValueIsZero(N1, HiMask) || + DAG.MaskedValueIsZero(N0, HiMask)) { + SDValue LHS = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, N0); + SDValue RHS = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, N1); return DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i64, DAG.getNode(ISD::AND, dl, MVT::i32, LHS, RHS)); } @@ -46281,8 +46283,6 @@ static SDValue combineAnd(SDNode *N, SelectionDAG &DAG, SmallVector SrcPartials; if (matchScalarReduction(SDValue(N, 0), ISD::AND, SrcOps, &SrcPartials) && SrcOps.size() == 1) { - SDLoc dl(N); - const TargetLowering &TLI = DAG.getTargetLoweringInfo(); unsigned NumElts = SrcOps[0].getValueType().getVectorNumElements(); EVT MaskVT = EVT::getIntegerVT(*DAG.getContext(), NumElts); SDValue Mask = combineBitcastvxi1(DAG, MaskVT, SrcOps[0], dl, Subtarget); @@ -46331,24 +46331,23 @@ static SDValue combineAnd(SDNode *N, SelectionDAG &DAG, // Attempt to combine a scalar bitmask AND with an extracted shuffle. if ((VT.getScalarSizeInBits() % 8) == 0 && - N->getOperand(0).getOpcode() == ISD::EXTRACT_VECTOR_ELT && - isa(N->getOperand(0).getOperand(1))) { - SDValue BitMask = N->getOperand(1); - SDValue SrcVec = N->getOperand(0).getOperand(0); + N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT && + isa(N0.getOperand(1))) { + SDValue BitMask = N1; + SDValue SrcVec = N0.getOperand(0); EVT SrcVecVT = SrcVec.getValueType(); // Check that the constant bitmask masks whole bytes. APInt UndefElts; SmallVector EltBits; - if (VT == SrcVecVT.getScalarType() && - N->getOperand(0)->isOnlyUserOf(SrcVec.getNode()) && + if (VT == SrcVecVT.getScalarType() && N0->isOnlyUserOf(SrcVec.getNode()) && getTargetConstantBitsFromNode(BitMask, 8, UndefElts, EltBits) && llvm::all_of(EltBits, [](const APInt &M) { return M.isZero() || M.isAllOnes(); })) { unsigned NumElts = SrcVecVT.getVectorNumElements(); unsigned Scale = SrcVecVT.getScalarSizeInBits() / 8; - unsigned Idx = N->getOperand(0).getConstantOperandVal(1); + unsigned Idx = N0.getConstantOperandVal(1); // Create a root shuffle mask from the byte mask and the extracted index. SmallVector ShuffleMask(NumElts * Scale, SM_SentinelUndef); @@ -46364,8 +46363,8 @@ static SDValue combineAnd(SDNode *N, SelectionDAG &DAG, X86::MaxShuffleCombineDepth, /*HasVarMask*/ false, /*AllowVarCrossLaneMask*/ true, /*AllowVarPerLaneMask*/ true, DAG, Subtarget)) - return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(N), VT, Shuffle, - N->getOperand(0).getOperand(1)); + return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, VT, Shuffle, + N0.getOperand(1)); } } -- 2.7.4