Skip to content

Commit 4928eff

Browse files
committed
[RISCV] Add an implementation of findRepresentativeClass to assign i32 to GPRRegClass for RV64.
This is an alternative fix for llvm#81192. This allows the SelectionDAG scheduler to be able to find a register class for i32 on RV64. The default implementation of findRepresentativeClass only works for legal types which i32 is not for RV64. I wanted to remove i32 from the GPR register class to fix the issue, but we need to be able to write some i32 patterns for GISel. And now it looks like I need to add i16 to GPR. I had tried to use manual instruction selection for some cases in GISel in llvm#116111, but I got some feedback recommending the use of patterns. I did some investigation of why tablegen uses i32 in output patterns on RV64. It appears it comes down to ForceArbitraryInstResultType that just picks a type for the output pattern when the isel pattern isn't specific enough. I believe it picks the smallest type(lowested numbered) to resolve the conflict.
1 parent 5a2888d commit 4928eff

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21996,6 +21996,24 @@ SDValue RISCVTargetLowering::expandIndirectJTBranch(const SDLoc &dl,
2199621996
return TargetLowering::expandIndirectJTBranch(dl, Value, Addr, JTI, DAG);
2199721997
}
2199821998

21999+
// Some types are listed in the GPR register class to support isel patterns for
22000+
// GISel, but are not legal in SelectionDAG. This prevents the default
22001+
// implementation from finding a register clss for them.
22002+
std::pair<const TargetRegisterClass *, uint8_t>
22003+
RISCVTargetLowering::findRepresentativeClass(const TargetRegisterInfo *TRI,
22004+
MVT VT) const {
22005+
const TargetRegisterClass *RRC = nullptr;
22006+
uint8_t Cost = 1;
22007+
switch (VT.SimpleTy) {
22008+
default:
22009+
return TargetLowering::findRepresentativeClass(TRI, VT);
22010+
case MVT::i8: case MVT::i16: case MVT::i32:
22011+
RRC = &RISCV::GPRRegClass;
22012+
break;
22013+
}
22014+
return std::make_pair(RRC, Cost);
22015+
}
22016+
2199922017
namespace llvm::RISCVVIntrinsicsTable {
2200022018

2200122019
#define GET_RISCVVIntrinsicsTable_IMPL

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,9 @@ class RISCVTargetLowering : public TargetLowering {
10511051

10521052
SDValue emitFlushICache(SelectionDAG &DAG, SDValue InChain, SDValue Start,
10531053
SDValue End, SDValue Flags, SDLoc DL) const;
1054+
1055+
std::pair<const TargetRegisterClass *, uint8_t>
1056+
findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT) const override;
10541057
};
10551058

10561059
namespace RISCVVIntrinsicsTable {

0 commit comments

Comments
 (0)