Skip to content

Commit

Permalink
Add tests for add/sub (extended-register) combinations on ARM64 (#112408
Browse files Browse the repository at this point in the history
)

Contributes to #68028
  • Loading branch information
snickolls-arm authored Feb 13, 2025
1 parent a5f99c6 commit d4f570d
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/tests/JIT/opt/InstructionCombining/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@ public static int CheckAdd()
fail = true;
}

if (AddExtendedB(0, 0x101) != 1)
{
fail = true;
}

if (AddExtendedH(0, 0x10001) != 1)
{
fail = true;
}

if (AddExtendedW(0, 0x100000001) != 1)
{
fail = true;
}

if (AddExtendedUB(0, 0x101) != 1)
{
fail = true;
}

if (AddExtendedUH(0, 0x10001) != 1)
{
fail = true;
}

if (AddExtendedUW(0, 0x100000001) != 1)
{
fail = true;
}

if (fail)
{
return 101;
Expand Down Expand Up @@ -141,6 +171,48 @@ static long AddLargeShift64Bit(long a, long b)
return a + (b>>169);
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long AddExtendedB(int a, int b)
{
//ARM64-FULL-LINE: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, SXTB
return a + (sbyte)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long AddExtendedH(int a, int b)
{
//ARM64-FULL-LINE: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, SXTH
return a + (short)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long AddExtendedW(long a, long b)
{
//ARM64-FULL-LINE: add {{x[0-9]+}}, {{x[0-9]+}}, {{w[0-9]+}}, SXTW
return a + (int)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long AddExtendedUB(int a, int b)
{
//ARM64-FULL-LINE: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, UXTB
return a + (byte)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long AddExtendedUH(int a, int b)
{
//ARM64-FULL-LINE: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, UXTH
return a + (ushort)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long AddExtendedUW(long a, long b)
{
//ARM64-FULL-LINE: add {{x[0-9]+}}, {{x[0-9]+}}, {{w[0-9]+}}, UXTW
return a + (uint)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static int Adds(int a, int b)
{
Expand Down
68 changes: 68 additions & 0 deletions src/tests/JIT/opt/InstructionCombining/Sub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ public static int CheckSub()
fail = true;
}

if (SubExtendedB(1, 0x1001) != 0)
{
fail = true;
}
if (SubExtendedH(1, 0x10001) != 0)
{
fail = true;
}
if (SubExtendedW(1, 0x100000001) != 0)
{
fail = true;
}

if (SubExtendedUB(1, 0x1001) != 0)
{
fail = true;
}
if (SubExtendedUH(1, 0x10001) != 0)
{
fail = true;
}
if (SubExtendedUW(1, 0x100000001) != 0)
{
fail = true;
}

if (fail)
{
return 101;
Expand Down Expand Up @@ -124,6 +150,48 @@ static long SubLargeShift64Bit(long a, long b)
return a - (b<<118);
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long SubExtendedB(int a, int b)
{
//ARM64-FULL-LINE: sub {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, SXTB
return a - (sbyte)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long SubExtendedH(int a, int b)
{
//ARM64-FULL-LINE: sub {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, SXTH
return a - (short)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long SubExtendedW(long a, long b)
{
//ARM64-FULL-LINE: sub {{x[0-9]+}}, {{x[0-9]+}}, {{w[0-9]+}}, SXTW
return a - (int)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long SubExtendedUB(int a, int b)
{
//ARM64-FULL-LINE: sub {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, UXTB
return a - (byte)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long SubExtendedUH(int a, int b)
{
//ARM64-FULL-LINE: sub {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, UXTH
return a - (ushort)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static long SubExtendedUW(long a, long b)
{
//ARM64-FULL-LINE: sub {{x[0-9]+}}, {{x[0-9]+}}, {{w[0-9]+}}, UXTW
return a - (uint)b;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static int Subs(int a, int b)
{
Expand Down

0 comments on commit d4f570d

Please sign in to comment.