Skip to content

[SelectionDAG] NFC: Add target hooks to enable vector coercion in CopyToReg / CopyFromReg #66134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -1076,10 +1076,10 @@ class TargetLoweringBase {
/// This method returns the number of registers needed, and the VT for each
/// register. It also returns the VT and quantity of the intermediate values
/// before they are promoted/expanded.
unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
EVT &IntermediateVT,
unsigned &NumIntermediates,
MVT &RegisterVT) const;
virtual unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
EVT &IntermediateVT,
unsigned &NumIntermediates,
MVT &RegisterVT) const;

/// Certain targets such as MIPS require that some types such as vectors are
/// always broken down into scalars in some contexts. This occurs even if the
Expand All @@ -1091,6 +1091,16 @@ class TargetLoweringBase {
RegisterVT);
}

/// Certain targets, such as AMDGPU, may coerce vectors of one type to another
/// to produce optimal code for CopyToReg / CopyFromReg pairs when dealing
/// with non-legal types -- e.g. v7i8 -> v2i32. This gives targets an
/// opportunity to do custom lowering in such cases.
virtual SDValue lowerVectorCopyReg(bool ISABIRegCopy, SelectionDAG &DAG,
const SDLoc &DL, SDValue &Val, EVT Source,
EVT Dest, bool IsCopyTo = true) const {
return SDValue();
};

struct IntrinsicInfo {
unsigned opc = 0; // target opcode
EVT memVT; // memory VT
Expand Down Expand Up @@ -1598,7 +1608,7 @@ class TargetLoweringBase {
}

/// Return the type of registers that this ValueType will eventually require.
MVT getRegisterType(LLVMContext &Context, EVT VT) const {
virtual MVT getRegisterType(LLVMContext &Context, EVT VT) const {
if (VT.isSimple())
return getRegisterType(VT.getSimpleVT());
if (VT.isVector()) {
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL,
if (ValueVT.getSizeInBits() == PartEVT.getSizeInBits())
return DAG.getNode(ISD::BITCAST, DL, ValueVT, Val);

if (auto TargetLowered = TLI.lowerVectorCopyReg(IsABIRegCopy, DAG, DL, Val,
PartEVT, ValueVT, false)) {
// Give targets a chance to custom lower mismatched sizes
return TargetLowered;
}
// If the parts vector has more elements than the value vector, then we
// have a vector widening case (e.g. <2 x float> -> <4 x float>).
// Extract the elements we want.
Expand Down Expand Up @@ -765,6 +770,10 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL,
} else if (ValueVT.getSizeInBits() == BuiltVectorTy.getSizeInBits()) {
// Bitconvert vector->vector case.
Val = DAG.getNode(ISD::BITCAST, DL, BuiltVectorTy, Val);
} else if (SDValue TargetLowered = TLI.lowerVectorCopyReg(
IsABIRegCopy, DAG, DL, Val, ValueVT, BuiltVectorTy)) {
// Give targets a chance to custom lower mismatched sizes
Val = TargetLowered;
} else {
if (BuiltVectorTy.getVectorElementType().bitsGT(
ValueVT.getVectorElementType())) {
Expand Down