Skip to content

Commit 126e4ee

Browse files
committed
fixup! [RISCV] GPR Pairs for Inline Asm using Pr
This commit is an alternate approach that follows SystemZ in using MVT::Untyped for GPR Pairs rather than new MVTs. This approach does not need to use getAsmOperandValueType, so I have also undone the fixes for this in TargetLowering.cpp. I will open a separate PR against AArch64 to land this fix.
1 parent 7fa4c46 commit 126e4ee

File tree

8 files changed

+37
-84
lines changed

8 files changed

+37
-84
lines changed

llvm/include/llvm/CodeGen/ValueTypes.td

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,23 +317,20 @@ def riscv_nxv16i8x3 : VTVecTup<384, 3, i8, 220>; // RISCV vector tuple(min_num_
317317
def riscv_nxv16i8x4 : VTVecTup<512, 4, i8, 221>; // RISCV vector tuple(min_num_elts=16, nf=4)
318318
def riscv_nxv32i8x2 : VTVecTup<512, 2, i8, 222>; // RISCV vector tuple(min_num_elts=32, nf=2)
319319

320-
def riscv_i32_pair : ValueType<64, 223>; // RISCV pair of RV32 GPRs
321-
def riscv_i64_pair : ValueType<128, 224>; // RISCV pair of RV64 GPRs
322-
323-
def x86mmx : ValueType<64, 225>; // X86 MMX value
324-
def Glue : ValueType<0, 226>; // Pre-RA sched glue
325-
def isVoid : ValueType<0, 227>; // Produces no value
326-
def untyped : ValueType<8, 228> { // Produces an untyped value
320+
def x86mmx : ValueType<64, 223>; // X86 MMX value
321+
def Glue : ValueType<0, 224>; // Pre-RA sched glue
322+
def isVoid : ValueType<0, 225>; // Produces no value
323+
def untyped : ValueType<8, 226> { // Produces an untyped value
327324
let LLVMName = "Untyped";
328325
}
329-
def funcref : ValueType<0, 229>; // WebAssembly's funcref type
330-
def externref : ValueType<0, 230>; // WebAssembly's externref type
331-
def exnref : ValueType<0, 231>; // WebAssembly's exnref type
332-
def x86amx : ValueType<8192, 232>; // X86 AMX value
333-
def i64x8 : ValueType<512, 233>; // 8 Consecutive GPRs (AArch64)
326+
def funcref : ValueType<0, 227>; // WebAssembly's funcref type
327+
def externref : ValueType<0, 228>; // WebAssembly's externref type
328+
def exnref : ValueType<0, 229>; // WebAssembly's exnref type
329+
def x86amx : ValueType<8192, 230>; // X86 AMX value
330+
def i64x8 : ValueType<512, 231>; // 8 Consecutive GPRs (AArch64)
334331
def aarch64svcount
335-
: ValueType<16, 234>; // AArch64 predicate-as-counter
336-
def spirvbuiltin : ValueType<0, 235>; // SPIR-V's builtin type
332+
: ValueType<16, 232>; // AArch64 predicate-as-counter
333+
def spirvbuiltin : ValueType<0, 233>; // SPIR-V's builtin type
337334

338335
let isNormalValueType = false in {
339336
def token : ValueType<0, 504>; // TokenTy

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5753,8 +5753,7 @@ TargetLowering::ParseConstraints(const DataLayout &DL,
57535753
assert(!Call.getType()->isVoidTy() && "Bad inline asm!");
57545754
if (auto *STy = dyn_cast<StructType>(Call.getType())) {
57555755
OpInfo.ConstraintVT =
5756-
getAsmOperandValueType(DL, STy->getElementType(ResNo))
5757-
.getSimpleVT();
5756+
getSimpleValueType(DL, STy->getElementType(ResNo));
57585757
} else {
57595758
assert(ResNo == 0 && "Asm only has one result!");
57605759
OpInfo.ConstraintVT =

llvm/lib/CodeGen/ValueTypes.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ std::string EVT::getEVTString() const {
177177
if (isFloatingPoint())
178178
return "f" + utostr(getSizeInBits());
179179
llvm_unreachable("Invalid EVT!");
180-
case MVT::riscv_i32_pair:
181-
return "riscv_i32_pair";
182-
case MVT::riscv_i64_pair:
183-
return "riscv_i64_pair";
184180
case MVT::bf16: return "bf16";
185181
case MVT::ppcf128: return "ppcf128";
186182
case MVT::isVoid: return "isVoid";
@@ -218,8 +214,6 @@ Type *EVT::getTypeForEVT(LLVMContext &Context) const {
218214
assert(isExtended() && "Type is not extended!");
219215
return LLVMTy;
220216
case MVT::isVoid: return Type::getVoidTy(Context);
221-
case MVT::riscv_i32_pair: return IntegerType::get(Context, 64);
222-
case MVT::riscv_i64_pair: return IntegerType::get(Context, 128);
223217
case MVT::x86mmx: return llvm::FixedVectorType::get(llvm::IntegerType::get(Context, 64), 1);
224218
case MVT::aarch64svcount:
225219
return TargetExtType::get(Context, "aarch64.svcount");

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
961961
CurDAG->getTargetConstant(RISCV::sub_gpr_odd, DL, MVT::i32)};
962962

963963
SDNode *N = CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, DL,
964-
Subtarget->getXLenPairVT(), Ops);
964+
MVT::Untyped, Ops);
965965
ReplaceNode(Node, N);
966966
return;
967967
}

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
113113
}
114114

115115
MVT XLenVT = Subtarget.getXLenVT();
116-
MVT XLenPairVT = Subtarget.getXLenPairVT();
117116

118117
// Set up the register classes.
119118
addRegisterClass(XLenVT, &RISCV::GPRRegClass);
120-
addRegisterClass(XLenPairVT, &RISCV::GPRPairRegClass);
121119

122120
if (Subtarget.hasStdExtZfhmin())
123121
addRegisterClass(MVT::f16, &RISCV::FPR16RegClass);
@@ -297,11 +295,6 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
297295
setCondCodeAction(ISD::SETLE, XLenVT, Expand);
298296
}
299297

300-
if (Subtarget.is64Bit())
301-
setOperationAction(ISD::BITCAST, MVT::i128, Custom);
302-
else
303-
setOperationAction(ISD::BITCAST, MVT::i64, Custom);
304-
305298
setOperationAction({ISD::STACKSAVE, ISD::STACKRESTORE}, MVT::Other, Expand);
306299

307300
setOperationAction(ISD::VASTART, MVT::Other, Custom);
@@ -2218,17 +2211,6 @@ bool RISCVTargetLowering::isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
22182211
return (ResElts * 2) == SrcElts && (Index == 0 || Index == ResElts);
22192212
}
22202213

2221-
EVT RISCVTargetLowering::getAsmOperandValueType(const DataLayout &DL, Type *Ty,
2222-
bool AllowUnknown) const {
2223-
if (!Subtarget.is64Bit() && Ty->isIntegerTy(64))
2224-
return MVT::riscv_i32_pair;
2225-
2226-
if (Subtarget.is64Bit() && Ty->isIntegerTy(128))
2227-
return MVT::riscv_i64_pair;
2228-
2229-
return TargetLowering::getAsmOperandValueType(DL, Ty, AllowUnknown);
2230-
}
2231-
22322214
MVT RISCVTargetLowering::getRegisterTypeForCallingConv(LLVMContext &Context,
22332215
CallingConv::ID CC,
22342216
EVT VT) const {
@@ -2248,7 +2230,7 @@ RISCVTargetLowering::getNumRegisters(LLVMContext &Context, EVT VT,
22482230
std::optional<MVT> RegisterVT) const {
22492231
// Pair inline assembly operand
22502232
if (VT == (Subtarget.is64Bit() ? MVT::i128 : MVT::i64) && RegisterVT &&
2251-
*RegisterVT == Subtarget.getXLenPairVT())
2233+
*RegisterVT == MVT::Untyped)
22522234
return 1;
22532235

22542236
return TargetLowering::getNumRegisters(Context, VT, RegisterVT);
@@ -2794,19 +2776,6 @@ RISCVTargetLowering::computeVLMAXBounds(MVT VecVT,
27942776
return std::make_pair(MinVLMAX, MaxVLMAX);
27952777
}
27962778

2797-
bool RISCVTargetLowering::isLoadBitCastBeneficial(
2798-
EVT LoadVT, EVT BitcastVT, const SelectionDAG &DAG,
2799-
const MachineMemOperand &MMO) const {
2800-
// We want to leave `bitcasts` to/from MVT::riscv_i<xlen>_pair separate from
2801-
// loads/stores so they can be turned into BuildGPRPair/::SplitGPRPair nodes.
2802-
if (LoadVT == (Subtarget.is64Bit() ? MVT::i128 : MVT::i64) &&
2803-
BitcastVT == Subtarget.getXLenPairVT())
2804-
return false;
2805-
2806-
return TargetLoweringBase::isLoadBitCastBeneficial(LoadVT, BitcastVT, DAG,
2807-
MMO);
2808-
}
2809-
28102779
// The state of RVV BUILD_VECTOR and VECTOR_SHUFFLE lowering is that very few
28112780
// of either is (currently) supported. This can get us into an infinite loop
28122781
// where we try to lower a BUILD_VECTOR as a VECTOR_SHUFFLE as a BUILD_VECTOR
@@ -6470,13 +6439,6 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
64706439
std::tie(Lo, Hi) = DAG.SplitScalar(Op0, DL, MVT::i32, MVT::i32);
64716440
return DAG.getNode(RISCVISD::BuildPairF64, DL, MVT::f64, Lo, Hi);
64726441
}
6473-
if (VT == Subtarget.getXLenPairVT() && Op0VT.isScalarInteger() &&
6474-
Op0VT.getSizeInBits() == 2 * Subtarget.getXLen()) {
6475-
SDValue Lo, Hi;
6476-
std::tie(Lo, Hi) = DAG.SplitScalar(Op0, DL, XLenVT, XLenVT);
6477-
return DAG.getNode(RISCVISD::BuildGPRPair, DL, Subtarget.getXLenPairVT(),
6478-
Lo, Hi);
6479-
}
64806442

64816443
// Consider other scalar<->scalar casts as legal if the types are legal.
64826444
// Otherwise expand them.
@@ -12999,14 +12961,6 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
1299912961
SDValue RetReg = DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64,
1300012962
NewReg.getValue(0), NewReg.getValue(1));
1300112963
Results.push_back(RetReg);
13002-
} else if (VT.isInteger() &&
13003-
VT.getSizeInBits() == 2 * Subtarget.getXLen() &&
13004-
Op0VT == Subtarget.getXLenPairVT()) {
13005-
SDValue NewReg = DAG.getNode(RISCVISD::SplitGPRPair, DL,
13006-
DAG.getVTList(XLenVT, XLenVT), Op0);
13007-
SDValue RetReg = DAG.getNode(ISD::BUILD_PAIR, DL, VT, NewReg.getValue(0),
13008-
NewReg.getValue(1));
13009-
Results.push_back(RetReg);
1301012964
} else if (!VT.isVector() && Op0VT.isFixedLengthVector() &&
1301112965
isTypeLegal(Op0VT)) {
1301212966
// Custom-legalize bitcasts from fixed-length vector types to illegal
@@ -21418,6 +21372,17 @@ bool RISCVTargetLowering::splitValueIntoRegisterParts(
2141821372
unsigned NumParts, MVT PartVT, std::optional<CallingConv::ID> CC) const {
2141921373
bool IsABIRegCopy = CC.has_value();
2142021374
EVT ValueVT = Val.getValueType();
21375+
21376+
if (ValueVT == (Subtarget.is64Bit() ? MVT::i128 : MVT::i64) &&
21377+
NumParts == 1 && PartVT == MVT::Untyped) {
21378+
// Pairs in Inline Assembly
21379+
MVT XLenVT = Subtarget.getXLenVT();
21380+
SDValue Lo, Hi;
21381+
std::tie(Lo, Hi) = DAG.SplitScalar(Val, DL, XLenVT, XLenVT);
21382+
Parts[0] = DAG.getNode(RISCVISD::BuildGPRPair, DL, MVT::Untyped, Lo, Hi);
21383+
return true;
21384+
}
21385+
2142121386
if (IsABIRegCopy && (ValueVT == MVT::f16 || ValueVT == MVT::bf16) &&
2142221387
PartVT == MVT::f32) {
2142321388
// Cast the [b]f16 to i16, extend to i32, pad with ones to make a float
@@ -21489,6 +21454,17 @@ SDValue RISCVTargetLowering::joinRegisterPartsIntoValue(
2148921454
SelectionDAG &DAG, const SDLoc &DL, const SDValue *Parts, unsigned NumParts,
2149021455
MVT PartVT, EVT ValueVT, std::optional<CallingConv::ID> CC) const {
2149121456
bool IsABIRegCopy = CC.has_value();
21457+
21458+
if (ValueVT == (Subtarget.is64Bit() ? MVT::i128 : MVT::i64) &&
21459+
NumParts == 1 && PartVT == MVT::Untyped) {
21460+
// Pairs in Inline Assembly
21461+
MVT XLenVT = Subtarget.getXLenVT();
21462+
SDValue Res = DAG.getNode(RISCVISD::SplitGPRPair, DL,
21463+
DAG.getVTList(XLenVT, XLenVT), Parts[0]);
21464+
return DAG.getNode(ISD::BUILD_PAIR, DL, ValueVT, Res.getValue(0),
21465+
Res.getValue(1));
21466+
}
21467+
2149221468
if (IsABIRegCopy && (ValueVT == MVT::f16 || ValueVT == MVT::bf16) &&
2149321469
PartVT == MVT::f32) {
2149421470
SDValue Val = Parts[0];

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,6 @@ class RISCVTargetLowering : public TargetLowering {
554554

555555
bool softPromoteHalfType() const override { return true; }
556556

557-
EVT getAsmOperandValueType(const DataLayout &DL, Type *Ty,
558-
bool AllowUnknown = false) const override;
559-
560557
/// Return the register type for a given MVT, ensuring vectors are treated
561558
/// as a series of gpr sized integers.
562559
MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC,
@@ -602,10 +599,6 @@ class RISCVTargetLowering : public TargetLowering {
602599
return false;
603600
}
604601

605-
bool isLoadBitCastBeneficial(EVT LoadVT, EVT BitcastVT,
606-
const SelectionDAG &DAG,
607-
const MachineMemOperand &MMO) const override;
608-
609602
bool
610603
shouldExpandBuildVectorWithShuffles(EVT VT,
611604
unsigned DefinedValues) const override;

llvm/lib/Target/RISCV/RISCVRegisterInfo.td

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,7 @@ def GPRX1X5 : GPRRegisterClass<(add X1, X5)>;
287287
// Even-Odd GPR Pairs
288288
//===----------------------------------------------------------------------===//
289289

290-
def XLenPairVT : ValueTypeByHwMode<
291-
[RV32, RV64],
292-
[riscv_i32_pair, riscv_i64_pair]>;
290+
defvar XLenPairVT = untyped;
293291

294292
def XLenPairRI : RegInfoByHwMode<
295293
[RV32, RV64],

llvm/lib/Target/RISCV/RISCVSubtarget.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
201201
return Min;
202202
}
203203

204-
MVT getXLenPairVT() const {
205-
return is64Bit() ? MVT::riscv_i64_pair : MVT::riscv_i32_pair;
206-
}
207-
208204
/// If the ElementCount or TypeSize \p X is scalable and VScale (VLEN) is
209205
/// exactly known, returns \p X converted to a fixed quantity. Otherwise
210206
/// returns \p X unmodified.

0 commit comments

Comments
 (0)