Skip to content

Conversation

@AndyAyersMS
Copy link
Member

In such cases we won't have set up a stack pointer.

In such cases we won't have set up a stack pointer.
Copilot AI review requested due to automatic review settings January 24, 2026 00:26
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 24, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the WASM JIT codegen to avoid homing parameters when no locals or arguments require stack-based storage, i.e., when no stack pointer register has been set up.

Changes:

  • Add a guard in CodeGen::genHomeRegisterParams that checks GetStackPointerReg() and skips parameter homing when it is REG_NA.
  • Assert that the frame pointer is not used in this frameless case and emit a JITDUMP message for debugging.

@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib PTAL
@SingleAccretion let me know if you think we should handle this some other way.

Fixes codegen for methods with no (user) arguments, like

    public static int Zero() => 0;

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

{
JITDUMP("*************** In genHomeRegisterParams()\n");

if (GetStackPointerReg() == REG_NA)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a situation where the RA is wrong; with implicitly referenced variables we have to assume there may be some references to them outside of IR. So something like below:

diff --git a/src/coreclr/jit/regallocwasm.cpp b/src/coreclr/jit/regallocwasm.cpp
index 48bcd978abd..8c001fa77e7 100644
--- a/src/coreclr/jit/regallocwasm.cpp
+++ b/src/coreclr/jit/regallocwasm.cpp
@@ -100,6 +100,10 @@ void WasmRegAlloc::IdentifyCandidates()
         {
             JITDUMP("RA candidate: V%02u", lclNum);
         }
+        else if ((m_fpReg == REG_NA) && (varDsc->lvRefCnt() != 0))
+        {
+            m_fpReg = AllocateFreeRegister(TYP_I_IMPL);
+        }
     }
 }
 
@@ -147,11 +151,6 @@ void WasmRegAlloc::AllocateAndResolveNode(GenTree* node)
             {
                 RewriteLocalStackStore(node->AsLclVarCommon());
             }
-
-            if (m_fpReg == REG_NA)
-            {
-                m_fpReg = AllocateFreeRegister(TYP_I_IMPL);
-            }
         }
     }
     else if (node->OperIs(GT_LCLHEAP))
diff --git a/src/coreclr/jit/registeropswasm.cpp b/src/coreclr/jit/registeropswasm.cpp
index 0386d477d1b..b8f96cc35a7 100644
--- a/src/coreclr/jit/registeropswasm.cpp
+++ b/src/coreclr/jit/registeropswasm.cpp
@@ -109,7 +109,10 @@ unsigned UnpackWasmReg(regNumber reg, WasmValueType* pType)
 //
 unsigned WasmRegToIndex(regNumber reg)
 {
-    return UnpackWasmReg(reg);
+    WasmValueType wasmType;
+    unsigned index = UnpackWasmReg(reg, &wasmType);
+    assert((WasmValueType::Invalid < wasmType) && (wasmType < WasmValueType::Count));
+    return index;
 }
 
 bool genIsValidReg(regNumber reg)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants