From 110f6a740b4f63f8eabefc24ad90e98357782949 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 20 May 2024 15:29:35 -0700 Subject: [PATCH] [SelectionDAG] Add getVPZeroExtendInReg. NFC (#92792) Use it for 2 places in LegalizeIntegerTypes that created a VP_AND. --- llvm/include/llvm/CodeGen/SelectionDAG.h | 5 +++++ .../SelectionDAG/LegalizeIntegerTypes.cpp | 11 +++-------- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h index ed6962685f7b04..96a62706904686 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAG.h +++ b/llvm/include/llvm/CodeGen/SelectionDAG.h @@ -991,6 +991,11 @@ class SelectionDAG { /// value assuming it was the smaller SrcTy value. SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT); + /// Return the expression required to zero extend the Op + /// value assuming it was the smaller SrcTy value. + SDValue getVPZeroExtendInReg(SDValue Op, SDValue Mask, SDValue EVL, + const SDLoc &DL, EVT VT); + /// Convert Op, which must be of integer type, to the integer type VT, by /// either truncating it or performing either zero or sign extension as /// appropriate extension for the pointer's semantics. diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp index 7d3be72995239d..c64e27fe45634e 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -1511,10 +1511,7 @@ SDValue DAGTypeLegalizer::PromoteIntRes_VPFunnelShift(SDNode *N) { !TLI.isOperationLegalOrCustom(Opcode, VT)) { SDValue HiShift = DAG.getConstant(OldBits, DL, VT); Hi = DAG.getNode(ISD::VP_SHL, DL, VT, Hi, HiShift, Mask, EVL); - APInt Imm = APInt::getLowBitsSet(VT.getScalarSizeInBits(), - OldVT.getScalarSizeInBits()); - Lo = DAG.getNode(ISD::VP_AND, DL, VT, Lo, DAG.getConstant(Imm, DL, VT), - Mask, EVL); + Lo = DAG.getVPZeroExtendInReg(Lo, Mask, EVL, DL, OldVT); SDValue Res = DAG.getNode(ISD::VP_OR, DL, VT, Hi, Lo, Mask, EVL); Res = DAG.getNode(IsFSHR ? ISD::VP_LSHR : ISD::VP_SHL, DL, VT, Res, Amt, Mask, EVL); @@ -2377,10 +2374,8 @@ SDValue DAGTypeLegalizer::PromoteIntOp_VP_ZERO_EXTEND(SDNode *N) { // FIXME: There is no VP_ANY_EXTEND yet. Op = DAG.getNode(ISD::VP_ZERO_EXTEND, dl, VT, Op, N->getOperand(1), N->getOperand(2)); - APInt Imm = APInt::getLowBitsSet(VT.getScalarSizeInBits(), - N->getOperand(0).getScalarValueSizeInBits()); - return DAG.getNode(ISD::VP_AND, dl, VT, Op, DAG.getConstant(Imm, dl, VT), - N->getOperand(1), N->getOperand(2)); + return DAG.getVPZeroExtendInReg(Op, N->getOperand(1), N->getOperand(2), dl, + N->getOperand(0).getValueType()); } SDValue DAGTypeLegalizer::PromoteIntOp_FIX(SDNode *N) { diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 72685a2d772164..777bbf071732e2 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -1540,6 +1540,25 @@ SDValue SelectionDAG::getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT) { return getNode(ISD::AND, DL, OpVT, Op, getConstant(Imm, DL, OpVT)); } +SDValue SelectionDAG::getVPZeroExtendInReg(SDValue Op, SDValue Mask, + SDValue EVL, const SDLoc &DL, + EVT VT) { + EVT OpVT = Op.getValueType(); + assert(VT.isInteger() && OpVT.isInteger() && + "Cannot getVPZeroExtendInReg FP types"); + assert(VT.isVector() && OpVT.isVector() && + "getVPZeroExtendInReg type and operand type should be vector!"); + assert(VT.getVectorElementCount() == OpVT.getVectorElementCount() && + "Vector element counts must match in getZeroExtendInReg"); + assert(VT.bitsLE(OpVT) && "Not extending!"); + if (OpVT == VT) + return Op; + APInt Imm = APInt::getLowBitsSet(OpVT.getScalarSizeInBits(), + VT.getScalarSizeInBits()); + return getNode(ISD::VP_AND, DL, OpVT, Op, getConstant(Imm, DL, OpVT), Mask, + EVL); +} + SDValue SelectionDAG::getPtrExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT) { // Only unsigned pointer semantics are supported right now. In the future this // might delegate to TLI to check pointer signedness.