Skip to content

Commit

Permalink
[SelectionDAG] Add getVPZeroExtendInReg. NFC (#92792)
Browse files Browse the repository at this point in the history
Use it for 2 places in LegalizeIntegerTypes that created a VP_AND.
  • Loading branch information
topperc authored May 20, 2024
1 parent 33b7833 commit 110f6a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
5 changes: 5 additions & 0 deletions llvm/include/llvm/CodeGen/SelectionDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 3 additions & 8 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 110f6a7

Please sign in to comment.