Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit f4523b0

Browse files
committed
ARM: avoid clobbering register in v6 jump-table expansion.
If we got unlucky with register allocation and actual constpool placement, we could end up producing a tTBB_JT with an index that's already been clobbered. Technically, we might be able to fix this situation up with a MOV, but I think the constant islands pass is complex enough without having to deal with more weird edge-cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297871 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1d95032 commit f4523b0

File tree

6 files changed

+399
-2
lines changed

6 files changed

+399
-2
lines changed

include/llvm/CodeGen/MIRYamlMapping.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ struct MachineFunction {
381381
StringRef Name;
382382
unsigned Alignment = 0;
383383
bool ExposesReturnsTwice = false;
384+
bool NoVRegs;
384385
// GISel MachineFunctionProperties.
385386
bool Legalized = false;
386387
bool RegBankSelected = false;
@@ -405,6 +406,7 @@ template <> struct MappingTraits<MachineFunction> {
405406
YamlIO.mapRequired("name", MF.Name);
406407
YamlIO.mapOptional("alignment", MF.Alignment);
407408
YamlIO.mapOptional("exposesReturnsTwice", MF.ExposesReturnsTwice);
409+
YamlIO.mapOptional("noVRegs", MF.NoVRegs);
408410
YamlIO.mapOptional("legalized", MF.Legalized);
409411
YamlIO.mapOptional("regBankSelected", MF.RegBankSelected);
410412
YamlIO.mapOptional("selected", MF.Selected);

lib/CodeGen/MIRParser/MIRParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) {
332332
MF.setAlignment(YamlMF.Alignment);
333333
MF.setExposesReturnsTwice(YamlMF.ExposesReturnsTwice);
334334

335+
if (YamlMF.NoVRegs)
336+
MF.getProperties().set(MachineFunctionProperties::Property::NoVRegs);
335337
if (YamlMF.Legalized)
336338
MF.getProperties().set(MachineFunctionProperties::Property::Legalized);
337339
if (YamlMF.RegBankSelected)

lib/CodeGen/MIRPrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ void MIRPrinter::print(const MachineFunction &MF) {
175175
YamlMF.Alignment = MF.getAlignment();
176176
YamlMF.ExposesReturnsTwice = MF.exposesReturnsTwice();
177177

178+
YamlMF.NoVRegs = MF.getProperties().hasProperty(
179+
MachineFunctionProperties::Property::NoVRegs);
178180
YamlMF.Legalized = MF.getProperties().hasProperty(
179181
MachineFunctionProperties::Property::Legalized);
180182
YamlMF.RegBankSelected = MF.getProperties().hasProperty(

lib/Target/ARM/ARMConstantIslandPass.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,12 @@ bool ARMConstantIslands::optimizeThumb2JumpTables() {
21042104
IdxReg = Shift->getOperand(2).getReg();
21052105
unsigned ShiftedIdxReg = Shift->getOperand(0).getReg();
21062106

2107+
// It's important that IdxReg is live until the actual TBB/TBH. Most of
2108+
// the range is checked later, but the LEA might still clobber it and not
2109+
// actually get removed.
2110+
if (BaseReg == IdxReg && !jumpTableFollowsTB(MI, User.CPEMI))
2111+
continue;
2112+
21072113
MachineInstr *Load = User.MI->getNextNode();
21082114
if (Load->getOpcode() != ARM::tLDRr)
21092115
continue;
@@ -2135,14 +2141,14 @@ bool ARMConstantIslands::optimizeThumb2JumpTables() {
21352141
// IdxReg gets redefined in the middle of the sequence.
21362142
continue;
21372143
}
2138-
2144+
21392145
// Now safe to delete the load and lsl. The LEA will be removed later.
21402146
CanDeleteLEA = true;
21412147
Shift->eraseFromParent();
21422148
Load->eraseFromParent();
21432149
DeadSize += 4;
21442150
}
2145-
2151+
21462152
DEBUG(dbgs() << "Shrink JT: " << *MI);
21472153
MachineInstr *CPEMI = User.CPEMI;
21482154
unsigned Opc = ByteOk ? ARM::t2TBB_JT : ARM::t2TBH_JT;

0 commit comments

Comments
 (0)