diff --git a/llvm/lib/CodeGen/RegisterClassInfo.cpp b/llvm/lib/CodeGen/RegisterClassInfo.cpp --- a/llvm/lib/CodeGen/RegisterClassInfo.cpp +++ b/llvm/lib/CodeGen/RegisterClassInfo.cpp @@ -188,7 +188,14 @@ } assert(RC && "Failed to find register class"); compute(RC); - unsigned NReserved = RC->getNumRegs() - getNumAllocatableRegs(RC); - return TRI->getRegPressureSetLimit(*MF, Idx) - - TRI->getRegClassWeight(RC).RegWeight * NReserved; + unsigned NAllocatableRegs = getNumAllocatableRegs(RC); + unsigned RegPressureSetLimit = TRI->getRegPressureSetLimit(*MF, Idx); + // If all the regs are reserved, return raw RegPressureSetLimit. + // One example is VRSAVERC in PowerPC. + // Avoid returning zero, getRegPressureSetLimit(Idx) assumes computePSetLimit + // return non-zero value. + if (NAllocatableRegs == 0) + return RegPressureSetLimit; + unsigned NReserved = RC->getNumRegs() - NAllocatableRegs; + return RegPressureSetLimit - TRI->getRegClassWeight(RC).RegWeight * NReserved; } diff --git a/llvm/test/CodeGen/PowerPC/compute-regpressure.ll b/llvm/test/CodeGen/PowerPC/compute-regpressure.ll --- a/llvm/test/CodeGen/PowerPC/compute-regpressure.ll +++ b/llvm/test/CodeGen/PowerPC/compute-regpressure.ll @@ -1,7 +1,7 @@ ; REQUIRES: asserts ; RUN: llc -debug-only=regalloc < %s 2>&1 |FileCheck %s --check-prefix=DEBUG -; DEBUG-COUNT-3: AllocationOrder(VRSAVERC) = [ ] +; DEBUG-COUNT-1: AllocationOrder(VRSAVERC) = [ ] target triple = "powerpc64le-unknown-linux-gnu"