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 @@ -317,6 +317,15 @@ return Changed; } +static bool doVRegTypesMatch(const MachineRegisterInfo &MRI, unsigned VReg0, + unsigned VReg1) { + if (MRI.getRegClassOrNull(VReg0) == MRI.getRegClassOrNull(VReg1)) + return MRI.getRegClassOrNull(VReg0) != nullptr + ? true + : MRI.getType(VReg0) == MRI.getType(VReg1); + return false; +} + static bool propagateLocalCopies(MachineBasicBlock *MBB) { bool Changed = false; MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo(); @@ -341,7 +350,7 @@ continue; if (!TargetRegisterInfo::isVirtualRegister(Src)) continue; - if (MRI.getRegClass(Dst) != MRI.getRegClass(Src)) + if (!doVRegTypesMatch(MRI, Dst, Src)) continue; for (auto UI = MRI.use_begin(Dst); UI != MRI.use_end(); ++UI) { @@ -500,14 +509,16 @@ return virtualVRegNumber; } - unsigned createVirtualRegister(const TargetRegisterClass *RC) { + unsigned createVirtualRegister(MachineRegisterInfo &MRI, unsigned VReg) { + auto RC = MRI.getRegClassOrNull(VReg); std::string S; raw_string_ostream OS(S); OS << "namedVReg" << (virtualVRegNumber & ~0x80000000); OS.flush(); virtualVRegNumber++; - - return MRI.createVirtualRegister(RC, OS.str()); + if (RC) + return MRI.createVirtualRegister(RC, OS.str()); + return MRI.createGenericVirtualRegister(MRI.getType(VReg), OS.str()); } }; } // namespace @@ -557,7 +568,7 @@ continue; } - auto Rename = NVC.createVirtualRegister(MRI.getRegClass(Reg)); + auto Rename = NVC.createVirtualRegister(MRI, Reg); if (VRegRenameMap.find(Reg) == VRegRenameMap.end()) { LLVM_DEBUG(dbgs() << "Mapping vreg ";); @@ -741,7 +752,7 @@ MachineInstr &MI = *MII++; Changed = true; unsigned vRegToRename = MI.getOperand(0).getReg(); - auto Rename = NVC.createVirtualRegister(MRI.getRegClass(vRegToRename)); + auto Rename = NVC.createVirtualRegister(MRI, vRegToRename); std::vector RenameMOs; for (auto &MO : MRI.reg_operands(vRegToRename)) { diff --git a/llvm/test/CodeGen/MIR/AArch64/addrspace-memoperands.mir b/llvm/test/CodeGen/MIR/AArch64/addrspace-memoperands.mir --- a/llvm/test/CodeGen/MIR/AArch64/addrspace-memoperands.mir +++ b/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 --- |