Skip to content

crossgen2: getHFAType fails on arm64 and passes on x64 targetting arm64 #46126

Closed

Description

@sandreenko

private CorInfoHFAElemType getHFAType(CORINFO_CLASS_STRUCT_* hClass)
fails on arm64 and passes on x64 targetting arm64.

To repro get this change:
sandreenko@880a563

readytorun\crossgen2\crossgen2smoke

and run crossgen2 test on x64 -> passes, on x64 targeting arm64 -> passes, on arm64 -> fails with:

Z:\PayloadGroup0>dotnet "Z:\CoreRoot\crossgen2\crossgen2.dll" @"Z:\PayloadGroup0\readytorun\crossgen2\crossgen2smoke\\composite-r2r.dll.rsp"   --composite"
To repro, add following arguments to the command line:
--singlemethodtypename "HelperGenericILCode`1[[System.__Canon]],helperildll" --singlemethodname LdTokenArrayMethods --singlemethodindex 1
Unhandled exception. ILCompiler.CodeGenerationFailedException: Code generation failed for method '[helperildll]HelperGenericILCode`1<System.__Canon>.LdTokenArrayMethods(RuntimeMethodHandle&,RuntimeMethodHandle&,RuntimeMethodHandle&,RuntimeMethodHandle&,RuntimeMethodHandle&)'
   at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL) in /_/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs:line 216
   at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodWithGCInfo methodCodeNodeNeedingCode) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs:line 391
   at ILCompiler.ReadyToRunCodegenCompilation.<ComputeDependencyNodeDependencies>b__26_0(DependencyNodeCore`1 dependency) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs:line 499
   at ILCompiler.ReadyToRunCodegenCompilation.ComputeDependencyNodeDependencies(List`1 obj) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs:line 525
   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 302
   at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs:line 302
   at ILCompiler.Program.Run(String[] args) in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 590
   at ILCompiler.Program.Main(String[] args) in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 739

for the minimal repro use the following rsp file(with your passes):

Y:\PayloadGroup0\readytorun\crossgen2\crossgen2smoke\IL-CG2\*.dll
-o:Y:\PayloadGroup0\readytorun\crossgen2\crossgen2smoke\\composite-r2r.dll
--targetarch:arm64
--verify-type-and-field-layout
-O
-r:Y:\CoreRoot\System.*.dll
-r:Y:\CoreRoot\Microsoft.*.dll
-r:Y:\CoreRoot\mscorlib.dll
-r:Y:\CoreRoot\netstandard.dll
--parallelism 
1
--singlemethodtypename 
HelperGenericILCode`1[[System.__Canon]],helperildll
--singlemethodname
LdTokenArrayMethods
--singlemethodindex
1

Remove a workaround for #46034 when it is fixed.

Activity

  1. sandreenko commented on Dec 16, 2020

    @sandreenko
    ContributorAuthor
  2. removed
    untriagedNew issue has not been triaged by the area owner
    on Dec 16, 2020
  3. added this to the 6.0.0 milestone on Dec 16, 2020
  4. mangod9 commented on Dec 16, 2020

    @mangod9
    Member

    cc @dotnet/crossgen-contrib. @sandreenko, is this blocking your PR from merging?

  5. sandreenko commented on Dec 16, 2020

    @sandreenko
    ContributorAuthor

    @mangod9 no, it does not

  6. mangod9 commented on Dec 16, 2020

    @mangod9
    Member

    Thanks, assigning to @AntonLapounov who will look at it in Jan.

  7. mangod9 commented on Jul 9, 2021

    @mangod9
    Member

    assume this is still something that needs investigation?

  8. AntonLapounov commented on Jul 9, 2021

    @AntonLapounov
    Contributor

    We discussed that offline. The current behavior may be considered "by design". There was another question why compiling for ARM64 on x64 and ARM64 machines demonstrated different behavior (no assert vs. assert). I can check whether it is still the case. I think we can safely move it to future release.

  9. modified the milestones: 6.0.0, 7.0.0 on Jul 9, 2021
  10. modified the milestones: 7.0.0, Future on Jul 19, 2022
  11. 6 remaining items

  12. sandreenko commented on Jun 7, 2023

    @sandreenko
    ContributorAuthor

    The assert and change in Jit to call it only on value types sound reasonable.
    Probably many methods in jit call it right now without a value type check, like

    return varTypeIsValidHfaType(GetHfaType(hClass));
    and expect that GetHfaType(NO_CLASS_HANDLE) returns TYP_UNDEF but the fix should not be complex.

  13. trylek commented on Jun 7, 2023

    @trylek
    Member

    I guess it should suffice to fix the JIT wrapper GetHfaType to avoid actually calling the JIT interface unless the type is a valuetype, there are various sorts of upfront checks there already.

  14. jkotas commented on Jun 7, 2023

    @jkotas
    Member

    I guess it should suffice to fix the JIT wrapper GetHfaType to avoid actually calling the JIT interface unless the type is a valuetype

    If you need to do another call on JIT/EE inteface to check whether it is a value type, it is more efficient to allow passing any types into the JIT/EE interface getHFAType API.

  15. trylek commented on Jun 7, 2023

    @trylek
    Member

    Hmm, I thought this information was readily available to JIT without making another interface call, if not, you're certainly right, we don't want to add another interface call for this purpose.

  16. sandreenko commented on Jun 8, 2023

    @sandreenko
    ContributorAuthor

    Hmm, I thought this information was readily available to JIT without making another interface call, if not, you're certainly right, we don't want to add another interface call for this purpose.

    'isValueType' is saved in LclVars and GenTrees that call 'getHFAType' method so it is cheap to fix. Maybe it would ever be a speed-up not to call it when JIT-EE already knows the result.

    cc @jakobbotsch

  17. jakobbotsch commented on Jun 8, 2023

    @jakobbotsch
    Member

    Some callers of GetHfaType already guard on varTypeIsStruct(type) for the corresponding JIT type, so it would make sense to me to do this more thoroughly. Alternatively we can change GetHfaType to take ClassLayout* that indeed already has cached isValueType available. That might also save a getClassSize JIT-EE call in a few places.

  18. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    and removed on Jun 8, 2023
  19. added
    needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration
    on Jun 8, 2023
  20. jakobbotsch commented on Jun 8, 2023

    @jakobbotsch
    Member

    From a quick pass over the callers I think it will suffice to add a varTypeIsStruct(argSigType) guard here:

    if (GlobalJitOptions::compFeatureHfa)

    All other callers I saw seem to be from paths that already know we are dealing with a value type.

  21. AndyAyersMS commented on Aug 11, 2026

    @AndyAyersMS
    Member

    This no longer reproduces with the current Crossgen2 and JIT. The crossgen2smoke inputs now compile successfully as a composite ARM64 ReadyToRun image from an x64 host.

    The unguarded GetHfaType(argSigClass) call identified in the final discussion was removed by #112665. Current ARM and ARM64 ABI classifiers only query HFA information for struct types.

    Closing as fixed by the subsequent ABI classification cleanup.

  22. locked and limited conversation to collaborators on Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-arm64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions