From f26bc0ddd508edad7e3838850dfcb6b960d6e681 Mon Sep 17 00:00:00 2001 From: Jinsong Ji Date: Tue, 5 Jan 2021 15:37:16 +0000 Subject: [PATCH] [RegisterClassInfo] Return non-zero for RC without allocatable reg In some case, the RC may have 0 allocatable reg. eg: VRSAVERC in PowerPC, which has only 1 reg, but it is also reserved. The curreent implementation will keep calling the computePSetLimit because getRegPressureSetLimit assume computePSetLimit will return a non-zero value. The fix simply early return the value from TableGen for such special case. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D92907 --- llvm/lib/CodeGen/RegisterClassInfo.cpp | 13 ++++++++++--- llvm/test/CodeGen/PowerPC/compute-regpressure.ll | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/llvm/lib/CodeGen/RegisterClassInfo.cpp b/llvm/lib/CodeGen/RegisterClassInfo.cpp index 1523bd4..0488db3 100644 --- a/llvm/lib/CodeGen/RegisterClassInfo.cpp +++ b/llvm/lib/CodeGen/RegisterClassInfo.cpp @@ -188,7 +188,14 @@ unsigned RegisterClassInfo::computePSetLimit(unsigned Idx) const { } 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 index 7a15e46..4ef7fa2 100644 --- 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" -- 2.7.4