From 1eb75362c9903fcaa8b5ceb28ab36234ddda0cca Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Thu, 26 Aug 2021 18:57:59 +0100 Subject: [PATCH] [MCA][RegisterFile] Consistently update the PRF in the presence of multiple writes to the same register. My last change to the RegisterFile (PR51495) has introduced a bug in the logic that allocates physical registers in the PRF. In some cases, this bug could have triggered a nasty unsigned wrap in the number of allocated registers, thus resulting in mca being stuck forever in a loop of PRF availability checks. --- llvm/lib/MCA/HardwareUnits/RegisterFile.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp b/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp index 1c0f40dd73082..474bf84cf8913 100644 --- a/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp +++ b/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp @@ -294,7 +294,9 @@ void RegisterFile::addRegisterWrite(WriteRef Write, const WriteState *OtherWS = OtherWrite.getWriteState(); if (OtherWS && OtherWrite.getSourceIndex() == Write.getSourceIndex()) { if (OtherWS->getLatency() > WS.getLatency()) { - // Conservatively keep the slowest write to RegID. + // Conservatively keep the slowest write on RegID. + if (ShouldAllocatePhysRegs) + allocatePhysRegs(RegisterMappings[RegID].second, UsedPhysRegs); return; } }