diff --git a/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp b/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp --- a/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp +++ b/llvm/lib/CodeGen/MIRCanonicalizerPass.cpp @@ -480,21 +480,18 @@ namespace { class NamedVRegCursor { MachineRegisterInfo &MRI; - unsigned virtualVRegNumber; + unsigned virtualVRegNumber = 0; public: NamedVRegCursor(MachineRegisterInfo &MRI) : MRI(MRI) { - unsigned VRegGapIndex = 0; - const unsigned VR_GAP = (++VRegGapIndex * 1000); - - unsigned I = MRI.createIncompleteVirtualRegister(); - const unsigned E = (((I + VR_GAP) / VR_GAP) + 1) * VR_GAP; - - virtualVRegNumber = E; } void SkipVRegs() { unsigned VRegGapIndex = 1; + if (!virtualVRegNumber) { + VRegGapIndex = 0; + virtualVRegNumber = MRI.createIncompleteVirtualRegister(); + } const unsigned VR_GAP = (++VRegGapIndex * 1000); unsigned I = virtualVRegNumber; @@ -511,6 +508,8 @@ } unsigned createVirtualRegister(unsigned VReg) { + if (!virtualVRegNumber) + SkipVRegs(); std::string S; raw_string_ostream OS(S); OS << "namedVReg" << (virtualVRegNumber & ~0x80000000); diff --git a/llvm/test/CodeGen/MIR/AArch64/multiple-lhs-operands.mir b/llvm/test/CodeGen/MIR/AArch64/multiple-lhs-operands.mir --- a/llvm/test/CodeGen/MIR/AArch64/multiple-lhs-operands.mir +++ b/llvm/test/CodeGen/MIR/AArch64/multiple-lhs-operands.mir @@ -2,6 +2,9 @@ # This test ensures that the MIR parser can parse multiple register machine # operands before '='. +# This tests that a MIR file with no vregs does not get altered by mir-canon. +# RUN: llc -mtriple=aarch64 -o - -run-pass mir-canonicalizer -verify-machineinstrs %s + --- | declare void @foo()