[llvm] [GlobalISel][AMDGPU] Do not cache UsesAGPRs from empty functions. (PR #124799)

David Green via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 10:25:36 PST 2025


================
@@ -788,6 +788,12 @@ bool SIMachineFunctionInfo::usesAGPRs(const MachineFunction &MF) const {
   if (UsesAGPRs)
     return *UsesAGPRs;
 
+  // Assume we cannot get any useful information about an empty function, but do
+  // not cache the result as we may not have useful information yet (for example
+  // after a Global-ISel fallback).
+  if (MF.empty())
----------------
davemgreen wrote:

It comes from: After we fall back from global-isel to SDAG, MachineVerifier::visitMachineFunctionBefore gets called, which calls MRI->getReservedRegs which uses SIMachineFunctionInfo::usesAGPRs which caches the result of UsesAGPRs.
My original patch prevented the call from MachineVerifier to getReservedRegs if the function was empty, but that felt a bit odd. We are not allowed to call getReservedRegs on certain functions at some points? I can get the Machine Verifier not to run at that point in the pipeline by changing how the global isel passes are added. It as far as I understand the verifier after ResetMachineFunctionPass that causes the problems:
```
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index 847a1aef39c5..cf407b507303 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -1039,11 +1039,13 @@ bool TargetPassConfig::addCoreISelPasses() {

     if (addGlobalInstructionSelect())
       return true;
+  }

-    // Pass to reset the MachineFunction if the ISel failed.
+  // Pass to reset the MachineFunction if the ISel failed. Outside of the above
+  // if so that the verifier is not added to it.
+  if (Selector == SelectorType::GlobalISel)
     addPass(createResetMachineFunctionPass(
         reportDiagnosticWhenGlobalISelFallback(), isGlobalISelAbortEnabled()));
-  }

   // Run the SDAG InstSelector, providing a fallback path when we do not want to
   // abort on not-yet-supported input.
```

https://github.com/llvm/llvm-project/pull/124799


More information about the llvm-commits mailing list