-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV][GISel] Add manual isel for s16 load/store for the GPR bank. #116111
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -580,6 +580,23 @@ static void getOperandsForBranch(Register CondReg, RISCVCC::CondCode &CC, | |
CC = getRISCVCCFromICmp(Pred); | ||
} | ||
|
||
/// Select the RISC-V opcode for the G_LOAD or G_STORE operation \p GenericOpc, | ||
/// appropriate for the (value) register bank \p RegBankID and of memory access | ||
/// size \p OpSize. | ||
/// \returns \p GenericOpc if the combination is unsupported. | ||
static unsigned selectLoadStoreOp(unsigned GenericOpc, unsigned RegBankID, | ||
unsigned OpSize) { | ||
const bool IsStore = GenericOpc == TargetOpcode::G_STORE; | ||
if (RegBankID == RISCV::GPRBRegBankID) { | ||
switch (OpSize) { | ||
case 16: | ||
return IsStore ? RISCV::SH : RISCV::LH; | ||
} | ||
} | ||
|
||
return GenericOpc; | ||
} | ||
|
||
bool RISCVInstructionSelector::select(MachineInstr &MI) { | ||
MachineBasicBlock &MBB = *MI.getParent(); | ||
MachineFunction &MF = *MBB.getParent(); | ||
|
@@ -786,6 +803,54 @@ bool RISCVInstructionSelector::select(MachineInstr &MI) { | |
return selectMergeValues(MI, MIB); | ||
case TargetOpcode::G_UNMERGE_VALUES: | ||
return selectUnmergeValues(MI, MIB); | ||
case TargetOpcode::G_LOAD: | ||
case TargetOpcode::G_STORE: { | ||
GLoadStore &LdSt = cast<GLoadStore>(MI); | ||
LLT PtrTy = MRI->getType(LdSt.getPointerReg()); | ||
|
||
if (PtrTy != LLT::pointer(0, STI.getXLen())) { | ||
LLVM_DEBUG(dbgs() << "Load/Store pointer has type: " << PtrTy | ||
<< ", expected: " << LLT::pointer(0, STI.getXLen()) | ||
<< '\n'); | ||
return false; | ||
} | ||
|
||
#ifndef NDEBUG | ||
const RegisterBank &PtrRB = | ||
*RBI.getRegBank(LdSt.getPointerReg(), *MRI, TRI); | ||
// Check that the pointer register is valid. | ||
assert(PtrRB.getID() == RISCV::GPRBRegBankID && | ||
"Load/Store pointer operand isn't a GPR"); | ||
#endif | ||
|
||
unsigned MemSizeInBits = LdSt.getMemSizeInBits().getValue(); | ||
|
||
const Register ValReg = LdSt.getReg(0); | ||
const RegisterBank &RB = *RBI.getRegBank(ValReg, *MRI, TRI); | ||
|
||
const unsigned NewOpc = | ||
selectLoadStoreOp(MI.getOpcode(), RB.getID(), MemSizeInBits); | ||
if (NewOpc == MI.getOpcode()) | ||
return false; | ||
|
||
// Check if we can fold anything into the addressing mode. | ||
auto AddrModeFns = selectAddrRegImm(MI.getOperand(1)); | ||
if (!AddrModeFns) | ||
return false; | ||
|
||
// Folded something. Create a new instruction and return it. | ||
auto NewInst = MIB.buildInstr(NewOpc, {}, {}, MI.getFlags()); | ||
if (isa<GStore>(MI)) | ||
NewInst.addUse(ValReg); | ||
else | ||
NewInst.addDef(ValReg); | ||
NewInst.cloneMemRefs(MI); | ||
for (auto &Fn : *AddrModeFns) | ||
Fn(NewInst); | ||
MI.eraseFromParent(); | ||
|
||
return constrainSelectedInstRegOperands(*NewInst, TII, TRI, RBI); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be selectable from patterns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How? i16 isn't in the GPR register class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just add it to the class definition. If you're trying to do this it should be there. The set of dag legal types is not influenced by the tablegen class definition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weirdly the types in the register class influences something in how tablegen generates the SelectiondDAG output patterns for patterns with multiple instructions. Ever since I added i32 to GPR on RV64 we've been fighting with this #81192 Maybe it's a weird interaction with HwMode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order of the types in the class is significant in tablegen, for some reason. If you order it last, it might be less trouble There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I've traced it back to
|
||
} | ||
default: | ||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really need a regbank legality verifier