Repository: dotnet/runtime
File: src/coreclr/jit/regallocwasm.cpp (C++)

Code before:
//
// Arguments:
//    divModNode - The [U]DIV/[U]MOD node
//
void WasmRegAlloc::CollectReferencesForDivMod(GenTreeOp* divModNode)
{
    ConsumeTemporaryRegForOperand(divModNode->gtGetOp2() DEBUGARG("div-by-zero / overflow check"));
    ConsumeTemporaryRegForOperand(divModNode->gtGetOp1() DEBUGARG("div-by-zero / overflow check"));
}

//------------------------------------------------------------------------
// CollectReferencesForCall: Collect virtual register references for a call.
//
// Consumes temporary registers for a call.
//
// Arguments:
//    callNode - The GT_CALL node
//
void WasmRegAlloc::CollectReferencesForCall(GenTreeCall* callNode)
{
    if (callNode->NeedsNullCheck())
    {
        CallArg* thisArg  = callNode->gtArgs.GetThisArg();
        GenTree* thisNode = thisArg->GetNode();
        ConsumeTemporaryRegForOperand(thisNode DEBUGARG("null check for call"));
    }
}

//------------------------------------------------------------------------
// CollectReferencesForCast: Collect virtual register references for a cast.
//
// Consumes temporary registers for a cast.
//
// Arguments:
//    castNode - The GT_CAST node
//
void WasmRegAlloc::CollectReferencesForCast(GenTreeOp* castNode)
{
    if (castNode->gtOverflow())
    {
        ConsumeTemporaryRegForOperand(castNode->gtGetOp1() DEBUGARG("cast overflow check"));
    }
}

//------------------------------------------------------------------------
// RewriteLocalStackStore: rewrite a store to the stack to STOREIND(LCL_ADDR, ...).
//
// This is needed to obey WASM stack ordering constraints: as in IR, the
// address operands comes first and we can't insert that into the middle
// of an already generated instruction stream at codegen time.
//

Review comment (bug):
```suggestion
    CallArg* thisArg = callNode->gtArgs.GetThisArg();
    if (thisArg != nullptr)
    {
        ConsumeTemporaryRegForOperand(thisArg->GetNode() DEBUGARG("null check for call"));
    }
```
The idea with these `ConsumeTemporaryRegForOperand` is to not re-check the conditions that lead to them being needed to be made multi-use.

Code after:
//
// Arguments:
//    divModNode - The [U]DIV/[U]MOD node
//
void WasmRegAlloc::CollectReferencesForDivMod(GenTreeOp* divModNode)
{
    ConsumeTemporaryRegForOperand(divModNode->gtGetOp2() DEBUGARG("div-by-zero / overflow check"));
    ConsumeTemporaryRegForOperand(divModNode->gtGetOp1() DEBUGARG("div-by-zero / overflow check"));
}

//------------------------------------------------------------------------
// CollectReferencesForCall: Collect virtual register references for a call.
//
// Consumes temporary registers for a call.
//
// Arguments:
//    callNode - The GT_CALL node
//
void WasmRegAlloc::CollectReferencesForCall(GenTreeCall* callNode)
{
    CallArg* thisArg = callNode->gtArgs.GetThisArg();

    if (thisArg != nullptr)
    {
        ConsumeTemporaryRegForOperand(thisArg->GetNode() DEBUGARG("call this argument"));
    }
}

//------------------------------------------------------------------------
// CollectReferencesForCast: Collect virtual register references for a cast.
//
// Consumes temporary registers for a cast.
//
// Arguments:
//    castNode - The GT_CAST node
//
void WasmRegAlloc::CollectReferencesForCast(GenTreeOp* castNode)
{
    ConsumeTemporaryRegForOperand(castNode->gtGetOp1() DEBUGARG("cast overflow check"));
}

//------------------------------------------------------------------------
// RewriteLocalStackStore: rewrite a store to the stack to STOREIND(LCL_ADDR, ...).
//
// This is needed to obey WASM stack ordering constraints: as in IR, the
// address operands comes first and we can't insert that into the middle
// of an already generated instruction stream at codegen time.
//
// Arguments:
//    lclNode - The local store node
//