Index: lib/CodeGen/RegUsageInfoCollector.cpp =================================================================== --- lib/CodeGen/RegUsageInfoCollector.cpp +++ lib/CodeGen/RegUsageInfoCollector.cpp @@ -103,9 +103,20 @@ DEBUG(dbgs() << "Clobbered Registers: "); - for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg) - if (MRI->isPhysRegModified(PReg, true)) + auto &UsedPhysRegsMask = MRI->getUsedPhysRegsMask(); + // Scan all the physical register. When a register is defined in the current + // function set it and all the aliasing registers as defined in the regmask. + for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg) { + if (!MRI->def_empty(PReg)) { + for (MCRegAliasIterator AI(PReg, TRI, true); AI.isValid(); ++AI) + RegMask[*AI / 32] &= ~(1u << *AI % 32); + continue; + } + // If a register is not defned but is in the UsedPhysRegsMask set then + // set it to defined in the mask anyway. + if (UsedPhysRegsMask.test(PReg)) RegMask[PReg / 32] &= ~(1u << PReg % 32); + } if (!TargetFrameLowering::isSafeForNoCSROpt(F)) { const uint32_t *CallPreservedMask =