Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 11c3bab

Browse files
TNorthoverarielb1
authored andcommitted
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 6772bcc commit 11c3bab

File tree

6 files changed

+401
-4
lines changed

6 files changed

+401
-4
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
@@ -330,6 +330,8 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) {
330330
MF.setAlignment(YamlMF.Alignment);
331331
MF.setExposesReturnsTwice(YamlMF.ExposesReturnsTwice);
332332

333+
if (YamlMF.NoVRegs)
334+
MF.getProperties().set(MachineFunctionProperties::Property::NoVRegs);
333335
if (YamlMF.Legalized)
334336
MF.getProperties().set(MachineFunctionProperties::Property::Legalized);
335337
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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,7 @@ bool ARMConstantIslands::optimizeThumb2JumpTables() {
20332033
unsigned DeadSize = 0;
20342034
bool CanDeleteLEA = false;
20352035
bool BaseRegKill = false;
2036-
2036+
20372037
unsigned IdxReg = ~0U;
20382038
bool IdxRegKill = true;
20392039
if (isThumb2) {
@@ -2061,6 +2061,12 @@ bool ARMConstantIslands::optimizeThumb2JumpTables() {
20612061
IdxReg = Shift->getOperand(2).getReg();
20622062
unsigned ShiftedIdxReg = Shift->getOperand(0).getReg();
20632063

2064+
// It's important that IdxReg is live until the actual TBB/TBH. Most of
2065+
// the range is checked later, but the LEA might still clobber it and not
2066+
// actually get removed.
2067+
if (BaseReg == IdxReg && !jumpTableFollowsTB(MI, User.CPEMI))
2068+
continue;
2069+
20642070
MachineInstr *Load = User.MI->getNextNode();
20652071
if (Load->getOpcode() != ARM::tLDRr)
20662072
continue;
@@ -2086,15 +2092,15 @@ bool ARMConstantIslands::optimizeThumb2JumpTables() {
20862092
if (Load->getOperand(0).getReg() != MI->getOperand(0).getReg())
20872093
continue;
20882094
}
2089-
2090-
2095+
2096+
20912097
// Now safe to delete the load and lsl. The LEA will be removed later.
20922098
CanDeleteLEA = true;
20932099
Shift->eraseFromParent();
20942100
Load->eraseFromParent();
20952101
DeadSize += 4;
20962102
}
2097-
2103+
20982104
DEBUG(dbgs() << "Shrink JT: " << *MI);
20992105
MachineInstr *CPEMI = User.CPEMI;
21002106
unsigned Opc = ByteOk ? ARM::t2TBB_JT : ARM::t2TBH_JT;

0 commit comments

Comments
 (0)