Skip to content

Vector128 intrinsic causing crashes on ARM platform. #93912

Closed

Description

@maciejaszyk

Description

We've noticed that our tests crash on the ARM platform (both Linux & MacOS) in release mode. After investigation, I identified one of our optimizations that use intrinsics is causing it. For testing purposes, I forced our code to use a scalar version and tests are running without any crashes.

I also tried to reproduce it on Windows (x64) by disabling AVX/AVX2/removing Vector256 from the code below but it works just fine. I suspect this can be the codegen issue.

Please notice the fact that doesn't appear in Debug mode.

Code that causing the issue:
https://github.com/ravendb/ravendb/blob/bb639435eb6b6148e6d2de03add1240a119f5828/src/Voron/Data/Lookups/Lookup.cs#L791-L800

Reproduction Steps

Run Tryouts project in Release mode from a branch on ARM machine: https://github.com/maciejaszyk/ravendb/tree/ArmRepro

Should happen almost immediately.

Expected behavior

No crashing

Actual behavior

I've seen exit code 139.

Regression?

No response

Known Workarounds

No response

Configuration

.NET SDK:
Version: 7.0.203
Commit: 5b005c19f5

Runtime Environment:
OS Name: Mac OS X
OS Version: 13.3
OS Platform: Darwin
RID: osx.13-arm64
Base Path: /usr/local/share/dotnet/sdk/7.0.203/

Host:
Version: 7.0.12
Architecture: arm64
Commit: 4a824ef

.NET SDKs installed:
6.0.402 [/usr/local/share/dotnet/sdk]
7.0.203 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Also reproducible on Linux ARM:
.NET SDK:
Version: 7.0.402
Commit: 791db8e2d8

Runtime Environment:
OS Name: debian
OS Version: 11
OS Platform: Linux
RID: debian.11-arm64

Host:
Version: 7.0.12
Architecture: arm64
Commit: 4a824ef

Other information

No response

Activity

  1. ghost added
    needs-area-label
    on Oct 24, 2023
  2. ghost added
    untriaged
    on Oct 24, 2023
  3. added and removed
    needs-area-label
    on Oct 24, 2023
  4. added
    area-CodeGen-coreclr
    and removed on Oct 24, 2023
  5. JulieLeeMSFT commented on Oct 24, 2023

    @JulieLeeMSFT
    Member
  6. added this to the 9.0.0 milestone on Oct 24, 2023
  7. ghost removed
    untriaged
    on Oct 24, 2023
  8. kunalspathak commented on Oct 25, 2023

    @kunalspathak
    Contributor

    I was able to reproduce this problem and in checked build, we are hitting this assert.

    assert(lea->Offset() == 0);

    In release, we dereference lea->Index() although it does not have index and we get AV. This was introduced in #67490 where we started having addressing mode for SIMD vector loads/store with unscaled indices. In that, we do not contain LEA if (scale | offset) > 0, however, we mark it as contained even if offset < 0. We should be still able to handle this situation in codegen, however, in the PR, the only case we added was just with an assumption that we have valid index and offset == 0 (the assert that is hitting in checked builds). We should also handle cases where lea->HasNoIndex() and offset == 0 and offset != 0 cases if lea->HasIndex(), along with if offset fits in instruction or not. See

    void emitter::emitInsLoadStoreOp(instruction ins, emitAttr attr, regNumber dataReg, GenTreeIndir* indir)
    where we handle various cases I mentioned.

    I think the right fix is to not contain lea if offset < 0 and thus tweaking the following condition.

    diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp
    index 478ce8ee859..aa8461b06d0 100644
    --- a/src/coreclr/jit/lower.cpp
    +++ b/src/coreclr/jit/lower.cpp
    @@ -5247,7 +5247,7 @@ bool Lowering::TryCreateAddrMode(GenTree* addr, bool isContainable, GenTree* par
             return false;
         }
    
    -    if (((scale | offset) > 0) && parent->OperIsHWIntrinsic())
    +    if (((scale | offset) != 0) && parent->OperIsHWIntrinsic())
         {
             // For now we only support unscaled indices for SIMD loads
             return false;

    With that, we no longer mark the lea as contained and generate 2 instructions for ld1 instead of ldr, which IMO is ok to have, given that this is a fix in net7.

    - ldr     q16, [x0, #-0x02]
    + sub     x1, x0, #2
    + ld1     {v16.8h}, [x1]

    Eventually, we handle it in better way in #80411 and hence don't see this issue in .NET 8 anymore.

    @JulieLeeMSFT - do I need to send a PR to release/7.0 branch?

  9. arekpalinski commented on Oct 25, 2023

    @arekpalinski

    Please note that this is affecting a new, big feature of our product (https://github.com/ravendb/ravendb) in the latest version. This issue makes it unusable on ARM. So we really need to have it fixed in dotnet 7.0

  10. ghost added
    in-pr
    on Oct 25, 2023
  11. kunalspathak commented on Oct 25, 2023

    @kunalspathak
    Contributor

    So we really need to have it fixed in dotnet 7.0

    I have submitted #93983, but wondering if upgrading to .NET8 an option for you?

  12. ghost removed
    in-pr
    on Oct 25, 2023
  13. arekpalinski commented on Oct 27, 2023

    @arekpalinski

    I have submitted #93983, but wondering if upgrading to .NET8 an option for you?

    This is affecting our users right now so we'd love to have it fixed in .NET7. Eventually we'll do the upgrade to .NET8 for sure but the testing process will take some time on our side before we release on .NET8.

  14. ghost locked as resolved and limited conversation to collaborators on Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions