Skip to content

Fix ARM32 JIT errors with native int-div#128970

Open
clamp03 wants to merge 6 commits into
dotnet:mainfrom
clamp03:intdiv
Open

Fix ARM32 JIT errors with native int-div#128970
clamp03 wants to merge 6 commits into
dotnet:mainfrom
clamp03:intdiv

Conversation

@clamp03

@clamp03 clamp03 commented Jun 4, 2026

Copy link
Copy Markdown
Member

Fix errors when USE_HELPERS_FOR_INT_DIV is disabled to use native ARM division instructions, and add the missing GT_UDIV case.

Fix errors when USE_HELPERS_FOR_INT_DIV is disabled to use native ARM division instructions, and add the missing GT_UDIV case.
@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 Jun 4, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 4, 2026
@clamp03 clamp03 self-assigned this Jun 4, 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.

@JulieLeeMSFT

Copy link
Copy Markdown
Member

@dhartglassMSFT, PTAL.

Comment thread src/coreclr/jit/morph.cpp
@am11

am11 commented Jun 6, 2026

Copy link
Copy Markdown
Member

when USE_HELPERS_FOR_INT_DIV is disabled

It's enabled with hardcoded value:

#define USE_HELPERS_FOR_INT_DIV 1 // BeagleBoard (ARMv7A) doesn't support SDIV/UDIV

Do we need to add a runtime detection?

// in src/native/minipal/cpufeatures.h

#if defined(HOST_ARM)
#define ArmIntrinsicConstants_IDIV (1 << 0)
#endif

// in src/native/minipal/cpufeatures.c

#elif defined(HOST_ARM)

#if defined(HOST_UNIX)

    unsigned long hwcaps = getauxval(AT_HWCAP);

    if (hwcaps & HWCAP_IDIV)
    {
        // Our baseline support is ARMv7 with SDIV/UDIV
        result |= ArmIntrinsicConstants_IDIV;
    }

and wire it like Zbs was done in 65e9497.

@clamp03

clamp03 commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@am11 Thanks for the suggestion! Regarding TODO-ARM-CQ: Check for sdiv/udiv at runtime and generate it if available, I agree that implementing a runtime checker would be better. @jkotas @jakobbotsch What do you think?

@jkotas

jkotas commented Jun 8, 2026

Copy link
Copy Markdown
Member

Our bar for linux arm32 is to keep it functional. We are not spending any cycles to make it better. I do not think we are interested in investing into new arm32-specific optimizations.

@clamp03

clamp03 commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@jkotas Thank you for your comment. I think PR like error fix can still be reviewed and merged if there is no problem. Could you review this PR?

@jkotas

jkotas commented Jun 8, 2026

Copy link
Copy Markdown
Member

@dhartglassMSFT is going to review this PR

@clamp03

clamp03 commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

@dhartglassMSFT Could you please review this PR when you get a chance?

Comment thread src/coreclr/jit/lower.cpp Outdated

#if defined(USE_HELPERS_FOR_INT_DIV)
#if USE_HELPERS_FOR_INT_DIV
if (!varTypeIsIntegral(divMod->TypeGet()))

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.

Should the if be checking the inverse? This seems like a typo and we want if(varTypeIsIntegral... without the !

or get rid of the if, and add the assert message to the TypeIsFloating assert, seems like we don't need both of these

@dhartglassMSFT

dhartglassMSFT commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

I think the following code in gentree.cpp must also be updated - as-is something strange could happen if we try to generate a MOD/UMOD helper call when "USE_HELPERS_FOR_INT_DIV == 0"

in void GenTree::InitNodeSize()

#if USE_HELPERS_FOR_INT_DIV
    GenTree::s_gtNodeSizes[GT_DIV]           = TREE_NODE_SZ_LARGE;
    GenTree::s_gtNodeSizes[GT_UDIV]          = TREE_NODE_SZ_LARGE;
    GenTree::s_gtNodeSizes[GT_MOD]           = TREE_NODE_SZ_LARGE;
    GenTree::s_gtNodeSizes[GT_UMOD]          = TREE_NODE_SZ_LARGE;
#endif

the GT_MOD/GT_UMOD cases should be under the ARM32 target ifdef

@am11

am11 commented Jun 15, 2026

Copy link
Copy Markdown
Member

Our bar for linux arm32 is to keep it functional. We are not spending any cycles to make it better. I do not think we are interested in investing into new arm32-specific optimizations.

BTW, that hwcap suggestion is about changing buildtime check to runtime check with a single if HWCAP_IDIV, rest of the code is already in JIT (under #if !USE_HELPERS_FOR_INT_DIV).

clamp03 added 4 commits June 16, 2026 13:59
- genCodeForDivMod now throws DivideByZeroException (x / 0) and
  ArithmeticException (MinInt / -1), gated on OperExceptions.
- Address review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants