Skip to content

Commit 461126c

Browse files
[AArch64] Fix incorrectly getting the destination reg of an insn (#101205)
This popped up while investigating #96950 In a few places where we need the destination reg of an instruction we were using a call that worked only by accident.
1 parent b537df9 commit 461126c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,6 +4112,7 @@ bool AArch64InstrInfo::isPairedLdSt(const MachineInstr &MI) {
41124112
}
41134113

41144114
const MachineOperand &AArch64InstrInfo::getLdStBaseOp(const MachineInstr &MI) {
4115+
assert(MI.mayLoadOrStore() && "Load or store instruction expected");
41154116
unsigned Idx =
41164117
AArch64InstrInfo::isPairedLdSt(MI) || AArch64InstrInfo::isPreLdSt(MI) ? 2
41174118
: 1;
@@ -4120,6 +4121,7 @@ const MachineOperand &AArch64InstrInfo::getLdStBaseOp(const MachineInstr &MI) {
41204121

41214122
const MachineOperand &
41224123
AArch64InstrInfo::getLdStOffsetOp(const MachineInstr &MI) {
4124+
assert(MI.mayLoadOrStore() && "Load or store instruction expected");
41234125
unsigned Idx =
41244126
AArch64InstrInfo::isPairedLdSt(MI) || AArch64InstrInfo::isPreLdSt(MI) ? 3
41254127
: 2;

llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,12 +1951,15 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
19511951

19521952
static MachineBasicBlock::iterator
19531953
maybeMoveCFI(MachineInstr &MI, MachineBasicBlock::iterator MaybeCFI) {
1954+
assert((MI.getOpcode() == AArch64::SUBXri ||
1955+
MI.getOpcode() == AArch64::ADDXri) &&
1956+
"Expected a register update instruction");
19541957
auto End = MI.getParent()->end();
19551958
if (MaybeCFI == End ||
19561959
MaybeCFI->getOpcode() != TargetOpcode::CFI_INSTRUCTION ||
19571960
!(MI.getFlag(MachineInstr::FrameSetup) ||
19581961
MI.getFlag(MachineInstr::FrameDestroy)) ||
1959-
AArch64InstrInfo::getLdStBaseOp(MI).getReg() != AArch64::SP)
1962+
MI.getOperand(0).getReg() != AArch64::SP)
19601963
return End;
19611964

19621965
const MachineFunction &MF = *MI.getParent()->getParent();
@@ -2006,7 +2009,7 @@ AArch64LoadStoreOpt::mergeUpdateInsn(MachineBasicBlock::iterator I,
20062009
if (!AArch64InstrInfo::isPairedLdSt(*I)) {
20072010
// Non-paired instruction.
20082011
MIB = BuildMI(*I->getParent(), I, I->getDebugLoc(), TII->get(NewOpc))
2009-
.add(getLdStRegOp(*Update))
2012+
.add(Update->getOperand(0))
20102013
.add(getLdStRegOp(*I))
20112014
.add(AArch64InstrInfo::getLdStBaseOp(*I))
20122015
.addImm(Value / Scale)
@@ -2015,7 +2018,7 @@ AArch64LoadStoreOpt::mergeUpdateInsn(MachineBasicBlock::iterator I,
20152018
} else {
20162019
// Paired instruction.
20172020
MIB = BuildMI(*I->getParent(), I, I->getDebugLoc(), TII->get(NewOpc))
2018-
.add(getLdStRegOp(*Update))
2021+
.add(Update->getOperand(0))
20192022
.add(getLdStRegOp(*I, 0))
20202023
.add(getLdStRegOp(*I, 1))
20212024
.add(AArch64InstrInfo::getLdStBaseOp(*I))

0 commit comments

Comments
 (0)