Skip to content

Commit

Permalink
[MIR-Canon] Add support for rewriting VRegs that are typed but don't …
Browse files Browse the repository at this point in the history
…have an RC.

There were crashes (addrspace-memoperands.mir was only one of them) in MIR that
had operands that came from before register classes were set. With these
operands, creating a replacement vreg (for MIR-Canon's renaming) needs to use
the vreg type rather than the RegisterClass which is not present.

Differential Revision: https://reviews.llvm.org/D62543

llvm-svn: 362122
  • Loading branch information
plotfi committed May 30, 2019
1 parent 50daaa5 commit 0f4446b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
Expand Up @@ -500,14 +500,15 @@ class NamedVRegCursor {
return virtualVRegNumber;
}

unsigned createVirtualRegister(const TargetRegisterClass *RC) {
unsigned createVirtualRegister(unsigned VReg) {
std::string S;
raw_string_ostream OS(S);
OS << "namedVReg" << (virtualVRegNumber & ~0x80000000);
OS.flush();
virtualVRegNumber++;

return MRI.createVirtualRegister(RC, OS.str());
if (auto RC = MRI.getRegClassOrNull(VReg))
return MRI.createVirtualRegister(RC, OS.str());
return MRI.createGenericVirtualRegister(MRI.getType(VReg), OS.str());
}
};
} // namespace
Expand Down Expand Up @@ -557,7 +558,7 @@ GetVRegRenameMap(const std::vector<TypedVReg> &VRegs,
continue;
}

auto Rename = NVC.createVirtualRegister(MRI.getRegClass(Reg));
auto Rename = NVC.createVirtualRegister(Reg);

if (VRegRenameMap.find(Reg) == VRegRenameMap.end()) {
LLVM_DEBUG(dbgs() << "Mapping vreg ";);
Expand Down Expand Up @@ -741,7 +742,7 @@ static bool runOnBasicBlock(MachineBasicBlock *MBB,
MachineInstr &MI = *MII++;
Changed = true;
unsigned vRegToRename = MI.getOperand(0).getReg();
auto Rename = NVC.createVirtualRegister(MRI.getRegClass(vRegToRename));
auto Rename = NVC.createVirtualRegister(vRegToRename);

std::vector<MachineOperand *> RenameMOs;
for (auto &MO : MRI.reg_operands(vRegToRename)) {
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/MIR/AArch64/addrspace-memoperands.mir
@@ -1,4 +1,5 @@
# RUN: llc -mtriple=aarch64-none-linux-gnu -run-pass none -o - %s | FileCheck %s
# RUN: llc -mtriple=aarch64-none-linux-gnu -run-pass mir-canonicalizer -o - %s

--- |

Expand Down

0 comments on commit 0f4446b

Please sign in to comment.