Skip to content

Commit 3382c24

Browse files
committed
[RISCV] Fix RISCVInstrInfo::getInstSizeInBytes for atomics pseudos
Summary: Without these, the generic branch relaxation pass will underestimate the range required for branches spanning these and we can end up with "fixup value out of range" errors rather than relaxing the branches. Some of the instructions in the expansion may end up being compressed but exactly determining that is awkward, and these conservative values should be safe, if slightly suboptimal in rare cases. Reviewers: asb, lenary, luismarques, lewis-revill Reviewed By: asb, luismarques Subscribers: hiraditya, rbar, johnrusso, simoncook, sabuasal, niosHD, kito-cheng, shiva0217, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, jfb, PkmX, jocewei, psnobl, benna, Jim, s.egerton, pzheng, sameer.abuasal, apazos, evandro, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77443
1 parent 7a587ca commit 3382c24

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ bool RISCVExpandAtomicPseudo::expandMBB(MachineBasicBlock &MBB) {
8686
bool RISCVExpandAtomicPseudo::expandMI(MachineBasicBlock &MBB,
8787
MachineBasicBlock::iterator MBBI,
8888
MachineBasicBlock::iterator &NextMBBI) {
89+
// RISCVInstrInfo::getInstSizeInBytes hard-codes the number of expanded
90+
// instructions for each pseudo, and must be updated when adding new pseudos
91+
// or changing existing ones.
8992
switch (MBBI->getOpcode()) {
9093
case RISCV::PseudoAtomicLoadNand32:
9194
return expandAtomicBinOp(MBB, MBBI, AtomicRMWInst::Nand, false, 32,

llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ bool RISCVExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
8787
bool RISCVExpandPseudo::expandMI(MachineBasicBlock &MBB,
8888
MachineBasicBlock::iterator MBBI,
8989
MachineBasicBlock::iterator &NextMBBI) {
90+
// RISCVInstrInfo::getInstSizeInBytes hard-codes the number of expanded
91+
// instructions for each pseudo, and must be updated when adding new pseudos
92+
// or changing existing ones.
9093
switch (MBBI->getOpcode()) {
9194
case RISCV::PseudoLLA:
9295
return expandLoadLocalAddress(MBB, MBBI, NextMBBI);

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ unsigned RISCVInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
471471
case TargetOpcode::KILL:
472472
case TargetOpcode::DBG_VALUE:
473473
return 0;
474+
// These values are determined based on RISCVExpandAtomicPseudoInsts,
475+
// RISCVExpandPseudoInsts and RISCVMCCodeEmitter, depending on where the
476+
// pseudos are expanded.
474477
case RISCV::PseudoCALLReg:
475478
case RISCV::PseudoCALL:
476479
case RISCV::PseudoJump:
@@ -480,6 +483,26 @@ unsigned RISCVInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
480483
case RISCV::PseudoLA_TLS_IE:
481484
case RISCV::PseudoLA_TLS_GD:
482485
return 8;
486+
case RISCV::PseudoAtomicLoadNand32:
487+
case RISCV::PseudoAtomicLoadNand64:
488+
return 20;
489+
case RISCV::PseudoMaskedAtomicSwap32:
490+
case RISCV::PseudoMaskedAtomicLoadAdd32:
491+
case RISCV::PseudoMaskedAtomicLoadSub32:
492+
return 28;
493+
case RISCV::PseudoMaskedAtomicLoadNand32:
494+
return 32;
495+
case RISCV::PseudoMaskedAtomicLoadMax32:
496+
case RISCV::PseudoMaskedAtomicLoadMin32:
497+
return 44;
498+
case RISCV::PseudoMaskedAtomicLoadUMax32:
499+
case RISCV::PseudoMaskedAtomicLoadUMin32:
500+
return 36;
501+
case RISCV::PseudoCmpXchg32:
502+
case RISCV::PseudoCmpXchg64:
503+
return 16;
504+
case RISCV::PseudoMaskedCmpXchg32:
505+
return 32;
483506
case TargetOpcode::INLINEASM:
484507
case TargetOpcode::INLINEASM_BR: {
485508
const MachineFunction &MF = *MI.getParent()->getParent();

0 commit comments

Comments
 (0)