Skip to content

Commit 5dcf147

Browse files
committed
[SelectionDAG] NFC: Add target hooks to enable vector coercion in CopyToReg / CopyFromReg
Change-Id: I7c888ad2c3cd7f1104aed47725852e2fe09b7665
1 parent 9b77638 commit 5dcf147

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,10 +1076,10 @@ class TargetLoweringBase {
10761076
/// This method returns the number of registers needed, and the VT for each
10771077
/// register. It also returns the VT and quantity of the intermediate values
10781078
/// before they are promoted/expanded.
1079-
unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
1080-
EVT &IntermediateVT,
1081-
unsigned &NumIntermediates,
1082-
MVT &RegisterVT) const;
1079+
virtual unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
1080+
EVT &IntermediateVT,
1081+
unsigned &NumIntermediates,
1082+
MVT &RegisterVT) const;
10831083

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

1094+
/// Certain targets, such as AMDGPU, may coerce vectors of one type to another
1095+
/// to produce optimal code for CopyToReg / CopyFromReg pairs when dealing
1096+
/// with non-legal types -- e.g. v7i8 -> v2i32. This gives targets an
1097+
/// opportunity to do custom lowering in such cases.
1098+
virtual SDValue lowerVectorCopyReg(bool ISABIRegCopy, SelectionDAG &DAG,
1099+
const SDLoc &DL, SDValue &Val, EVT Source,
1100+
EVT Dest, bool IsCopyTo = true) const {
1101+
return SDValue();
1102+
};
1103+
10941104
struct IntrinsicInfo {
10951105
unsigned opc = 0; // target opcode
10961106
EVT memVT; // memory VT
@@ -1598,7 +1608,7 @@ class TargetLoweringBase {
15981608
}
15991609

16001610
/// Return the type of registers that this ValueType will eventually require.
1601-
MVT getRegisterType(LLVMContext &Context, EVT VT) const {
1611+
virtual MVT getRegisterType(LLVMContext &Context, EVT VT) const {
16021612
if (VT.isSimple())
16031613
return getRegisterType(VT.getSimpleVT());
16041614
if (VT.isVector()) {

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL,
400400
if (ValueVT.getSizeInBits() == PartEVT.getSizeInBits())
401401
return DAG.getNode(ISD::BITCAST, DL, ValueVT, Val);
402402

403+
if (auto TargetLowered = TLI.lowerVectorCopyReg(IsABIRegCopy, DAG, DL, Val,
404+
PartEVT, ValueVT, false)) {
405+
// Give targets a chance to custom lower mismatched sizes
406+
return TargetLowered;
407+
}
403408
// If the parts vector has more elements than the value vector, then we
404409
// have a vector widening case (e.g. <2 x float> -> <4 x float>).
405410
// Extract the elements we want.
@@ -765,6 +770,10 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL,
765770
} else if (ValueVT.getSizeInBits() == BuiltVectorTy.getSizeInBits()) {
766771
// Bitconvert vector->vector case.
767772
Val = DAG.getNode(ISD::BITCAST, DL, BuiltVectorTy, Val);
773+
} else if (SDValue TargetLowered = TLI.lowerVectorCopyReg(
774+
IsABIRegCopy, DAG, DL, Val, ValueVT, BuiltVectorTy)) {
775+
// Give targets a chance to custom lower mismatched sizes
776+
Val = TargetLowered;
768777
} else {
769778
if (BuiltVectorTy.getVectorElementType().bitsGT(
770779
ValueVT.getVectorElementType())) {

0 commit comments

Comments
 (0)