Skip to content

[LoongArch64] Sign/zero-extend small primitive arguments for pinvokes on loongarch64 - #133145

Open
LuckyXu-HF wants to merge 4 commits into
dotnet:mainfrom
LuckyXu-HF:main-LA64
Open

LuckyXu-HF wants to merge 4 commits into
dotnet:mainfrom
LuckyXu-HF:main-LA64

Conversation

@LuckyXu-HF

@LuckyXu-HF LuckyXu-HF commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor
  • LoongArch ABI also requires the caller handling for small primitive arguments sign/zero-extend.

@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 Sep 3, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Sep 3, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@shushanhf shushanhf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks

@LuckyXu-HF

Copy link
Copy Markdown
Contributor Author

Hi @jakobbotsch Could you please help to review this PR? Thanks.

* LoongArch ABI request the caller handling for small primitive arguments sign/zero-extend, so mark the Runtime_101046.il test unsupport on LoongArch64.
@LuckyXu-HF

Copy link
Copy Markdown
Contributor Author

Hi @jakobbotsch, the Runtime_101046.il appears to have been deliberately modified to trigger the test scenario, the reason for skipping this test on LA64 is that ldind.u2 should not be sign-extended semantically, from this perspective the test does not comply with LoongArch ABI, and we cannot guarantee its correctness in this scenario.

However, if this is intentionally a specific test and no need to consider semantics, we should take a fix like

if ((compAppleArm64Abi() || TargetArchitecture::IsArm32 || TargetArchitecture::IsWasm) &&
call->IsUnmanaged() && varTypeIsSmall(jitSigType))
{
// Wasm, Apple arm64 and arm32 ABIs require arguments to be zero/sign
// extended up to 32 bit. The managed ABI does not require
// this.
if (fgCastNeeded(argNode, jitSigType))
{
argNode = gtNewCastNode(TYP_INT, argNode, false, jitSigType);
}
}

because LoongArch ABI requires the caller to handle sign/zero-extend.

Could you help to give us some suggestions? thank you very much!

@jakobbotsch

Copy link
Copy Markdown
Member

Hi @jakobbotsch, the Runtime_101046.il appears to have been deliberately modified to trigger the test scenario, the reason for skipping this test on LA64 is that ldind.u2 should not be sign-extended semantically, from this perspective the test does not comply with LoongArch ABI, and we cannot guarantee its correctness in this scenario.

However, if this is intentionally a specific test and no need to consider semantics, we should take a fix like

if ((compAppleArm64Abi() || TargetArchitecture::IsArm32 || TargetArchitecture::IsWasm) &&
call->IsUnmanaged() && varTypeIsSmall(jitSigType))
{
// Wasm, Apple arm64 and arm32 ABIs require arguments to be zero/sign
// extended up to 32 bit. The managed ABI does not require
// this.
if (fgCastNeeded(argNode, jitSigType))
{
argNode = gtNewCastNode(TYP_INT, argNode, false, jitSigType);
}
}

because LoongArch ABI requires the caller to handle sign/zero-extend.

Could you help to give us some suggestions? thank you very much!

If loongarch's native platform ABI requires callers to zero/sign extend small types, then indeed this should be changed to also kick in for loongarch.

@LuckyXu-HF LuckyXu-HF changed the title [LoongArch64] Mark Runtime_101046.il test unsupport on LoongArch64. [LoongArch64] Sign/zero-extend small primitive arguments for pinvokes on loongarch64 Nov 2, 2026
@LuckyXu-HF

Copy link
Copy Markdown
Contributor Author

Hi @jakobbotsch, the Runtime_101046.il appears to have been deliberately modified to trigger the test scenario, the reason for skipping this test on LA64 is that ldind.u2 should not be sign-extended semantically, from this perspective the test does not comply with LoongArch ABI, and we cannot guarantee its correctness in this scenario.
However, if this is intentionally a specific test and no need to consider semantics, we should take a fix like

if ((compAppleArm64Abi() || TargetArchitecture::IsArm32 || TargetArchitecture::IsWasm) &&
call->IsUnmanaged() && varTypeIsSmall(jitSigType))
{
// Wasm, Apple arm64 and arm32 ABIs require arguments to be zero/sign
// extended up to 32 bit. The managed ABI does not require
// this.
if (fgCastNeeded(argNode, jitSigType))
{
argNode = gtNewCastNode(TYP_INT, argNode, false, jitSigType);
}
}

because LoongArch ABI requires the caller to handle sign/zero-extend.
Could you help to give us some suggestions? thank you very much!

If loongarch's native platform ABI requires callers to zero/sign extend small types, then indeed this should be changed to also kick in for loongarch.

Thank you very much, updated. Could you please help review this again?

This branch has not been deployed

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

Labels

arch-loongarch64 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants