Skip to content

[arm64] JIT assertion failures for valid C# code #73804

Closed

Description

@adamsitnik

In #73768 I've wrote quite complex, but valid (it defnitely works fine on x64) C# code that produces JIT assertion failures on arm64:

Sample run: https://github.com/dotnet/runtime/pull/73768/checks?check_run_id=7793120898

Sample log: https://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-73768-merge-b3d703c3580445e6b2/JIT.1.Attempt.3/1/console.32c25b20.log?helixlogtype=result

    JIT\Performance\CodeQuality\BenchmarksGame\regex-redux\regex-redux-5\regex-redux-5.cmd [FAIL]
      
      Assert failure(PID 2736 [0x00000ab0], Thread: 11800 [0x2e18]): Assertion failed 'ins != INS_invalid' in 'System.SpanHelpers:LastIndexOfValueType(byref,short,int):int' during 'Generate code' (IL size 335; hash 0xbe43e860; FullOpts)
      
          File: D:\a\_work\1\s\src\coreclr\jit\hwintrinsiccodegenarm64.cpp Line: 282
          Image: D:\h\w\A7BB0946\p\corerun.exe
      
      
      Return code:      1
      Raw output file:      D:\h\w\A7BB0946\w\A93E0970\uploads\Reports\JIT.Performance\CodeQuality\BenchmarksGame\regex-redux\regex-redux-5\regex-redux-5.output.txt
      Raw output:

It would be great if someone from the @dotnet/jit-contrib Team could take a look and let me know whether I've hit a bug in JIT or my code is invalid. Thanks!

Activity

  1. added
    area-CodeGen-coreclr
    on Aug 11, 2022
  2. added this to the 7.0.0 milestone on Aug 11, 2022
  3. JulieLeeMSFT commented on Aug 11, 2022

    @JulieLeeMSFT
    Member
  4. BruceForstall commented on Aug 11, 2022

    @BruceForstall
    Contributor

    You should never hit a JIT assert under any circumstance.

    cc @tannergooding in case I'm wrong w.r.t. hw intrinsics

  5. SingleAccretion commented on Aug 11, 2022

    @SingleAccretion
    Contributor

    The issue here is that for some scalar intrinsics (here it is ArmBase_LeadinZeroCount) "the base type", which is also "the operation type" is derived from the the first operand. This operand can be small while the operation itself isn't.

    Simple reproduction:

    private static int Problem(short* s)
    {
        return ArmBase.LeadingZeroCount(*s);
    }

    Edit: the presumable fix would be to use genActualType when deriving "base types" from operands.

  6. tannergooding commented on Aug 11, 2022

    @tannergooding
    Member

    cc @tannergooding in case I'm wrong w.r.t. hw intrinsics

    This is correct, assertions shouldn't be hit ever. For recursive intrinsics we should be at worst bailing out in import and causing it to throw a PNSE instead, for regular intrinsics we should at worst be falling back to the managed implementation.

  7. BruceForstall commented on Aug 12, 2022

    @BruceForstall
    Contributor

    What should be the IR behavior for short types in indirections? The incoming IL is:

    ldarg.0
    ldind.i2
    call
    

    So the ldind.i2 loads an int16 into int32 on the evaluation stack; an implicit cast to int.

    If we don't recognize the intrinsic, we have:

      t3 =    LCL_VAR   long   V00 arg0         u:1 x0 (last use) REG x0 $80
           /--*  t3     long
      t4 = *  IND       short  REG x0 <l:$201, c:$200>
           /--*  t4     short
      t8 = *  PUTARG_REG int    REG x0
      t9 =    CNS_INT(h) long   0x7ff7fd7a7d20 ftn REG x1
           /--*  t9     long
     t10 = *  IND       long   REG x1
           /--*  t8     int    arg0 in x0
           +--*  t10    long   control expr
      t5 = *  CALL      int    System.Runtime.Intrinsics.Arm.ArmBase.LeadingZeroCount REG x0 $240
    

    and generate a call like:

    ldrsh   w0, [x0]
    ...
    blr     x1
    

    The PUTARG_REG is TYP_INT, but we don't have to generate any code for it.

    When we recognize the intrinsic, we have:

      t3 =    LCL_VAR   long   V00 arg0         u:1 x0 (last use) REG x0 $80
           /--*  t3     long
      t4 = *  IND       short  REG x0 <l:$201, c:$200>
           /--*  t4     short
      t5 = *  HWINTRINSIC int     LeadingZeroCount REG x0 <l:$281, c:$280>
    

    and generate the same:

    ldrsh   w0, [x0]
    

    before hitting the assert.

    the presumable fix would be to use genActualType when deriving "base types" from operands.

    Or do we need to insert a cast during importation?

  8. jakobbotsch commented on Aug 12, 2022

    @jakobbotsch
    Member

    What should be the IR behavior for short types in indirections?

    They are zero/sign-extended to TYP_INT as part of the indirection.

    Or do we need to insert a cast during importation?

    That cast would just be removed by morph. Using genActualType should be the right fix (using non-actual types for a child node is almost never correct).

    I've said this a few times, but I really wish GenTree::TypeGet() would always return actual types and that we would have specific type getters for the nodes that have support for small typed operations (e.g. GenTreeIndir::IndirType()). We time and time again hit these issues due to our representation.

  9. added a commit that references this issue on Aug 12, 2022
    626ba48
  10. ghost added
    in-pr
    on Aug 12, 2022
  11. added a commit that references this issue on Aug 13, 2022
    3478472
  12. ghost removed
    in-pr
    on Aug 13, 2022
  13. ghost locked as resolved and limited conversation to collaborators on Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-arm64area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions