Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f335448
Fold const RVA access
EgorBo Nov 23, 2022
0282bfe
fix build
EgorBo Nov 23, 2022
9780a9a
Address feedback
EgorBo Nov 23, 2022
ae56d28
Clean up
EgorBo Nov 23, 2022
e35ac7c
fix compilation
EgorBo Nov 24, 2022
b8e2dd5
NativeAOT support (jit side)
EgorBo Nov 24, 2022
aaf129e
Update src/coreclr/vm/jitinterface.cpp
EgorBo Nov 24, 2022
f7b0d4e
Implement NativeAOT side
EgorBo Nov 24, 2022
1a6400a
Merge branch 'fold-const-rva' of github.com:EgorBo/runtime-1 into fol…
EgorBo Nov 24, 2022
29f4e9d
Update assertionprop.cpp
EgorBo Nov 24, 2022
8d471c1
Add tests, clean up
EgorBo Nov 24, 2022
7f402fc
Update ConstIndexRVA.cs
EgorBo Nov 24, 2022
14743b6
fix test
EgorBo Nov 24, 2022
784d02b
Merge branch 'fold-const-rva' of github.com:EgorBo/runtime-1 into fol…
EgorBo Nov 24, 2022
0dbc4c2
Merge branch 'main' of github.com:dotnet/runtime into fold-const-rva
EgorBo Nov 24, 2022
677c55d
Merge branch 'main' of github.com:dotnet/runtime into fold-const-rva
EgorBo Nov 25, 2022
142ad61
Address feedback
EgorBo Nov 26, 2022
66e481c
fix assert
EgorBo Nov 26, 2022
c4aa231
Update src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorIn…
EgorBo Nov 26, 2022
8164730
Fix AOT
EgorBo Nov 26, 2022
7c55cea
Merge branch 'main' of github.com:dotnet/runtime into fold-const-rva
EgorBo Nov 28, 2022
d718816
Address feedback
EgorBo Nov 28, 2022
f8051a8
make tryReadRvaFieldData static
EgorBo Nov 28, 2022
f45a76e
address feedback
EgorBo Nov 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix test
  • Loading branch information
EgorBo committed Nov 24, 2022
commit 14743b6e342057f8223d2b281fc1990a4694309d
43 changes: 22 additions & 21 deletions src/tests/JIT/opt/ValueNumbering/ConstIndexRVA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand All @@ -24,45 +25,45 @@ static int Main()
mth.Invoke(null, null);
testMethods++;
}
return testMethods == 26 ? 100 : -100;
return testMethods == 25 ? 100 : -100;
}

static ReadOnlySpan<byte> RVA1 => new byte[]
{
0x9c, 0x00, 0x01, 0x10,
0x9c, 0x00, 0x01, 0x10,
0x80, 0xAA, 0xAB, 0xFF,
0x9b, 0x02, 0x03, 0x14,
0x85, 0xA6, 0xA7, 0xF9,
};
static ReadOnlySpan<sbyte> RVA2 => new sbyte[] { -100, 100, 0, -128, 127 };
static ReadOnlySpan<bool> RVA3 => new [] { true, false };
static ReadOnlySpan<bool> RVA3 => new[] { true, false };

[MethodImpl(MethodImplOptions.NoInlining)] static void Test_1() => AssertEquals<int>((int)RVA1[0], (int)0x9c);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_2() => AssertEquals(RVA1[1], 0x00);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_3() => AssertEquals(RVA1[4], 0x80);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_4() => AssertEquals(RVA1[RVA1.Length -1], 0xF9);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_4() => AssertEquals(RVA1[RVA1.Length - 1], 0xF9);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_5() => ThrowsOOB(() => Consume(RVA1[-1]));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_6() => ThrowsOOB(() => Consume(RVA1[0xFF]));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_7() => ThrowsOOB(() => Consume(RVA1[RVA1.Length]));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_8() => AssertEquals<long>((long)RVA2[0], -100);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_9() => AssertEquals(RVA2[1], 100);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_11() => AssertEquals(RVA2[^1], 127);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_12() => ThrowsOOB(() => Consume(RVA2[-int.MaxValue]));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_13() => ThrowsOOB(() => Consume(RVA2[0xFF]));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_14() => ThrowsOOB(() => Consume(RVA2[RVA2.Length]));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_15() => AssertEquals(RVA3[0], true);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_16() => AssertEquals(RVA3[1], false);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_17() => AssertEquals<int>(Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 0)), 268501148);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_18() => AssertEquals<uint>(Unsafe.ReadUnaligned<uint>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 1)), 2148532480);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_19() => AssertEquals<int>(Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 11)), -1482259180);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_20() => AssertEquals<short>(Unsafe.ReadUnaligned<short>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 0)), 156);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_21() => AssertEquals<ulong>(Unsafe.ReadUnaligned<ulong>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 1)), 11240891943721369856);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_22() => AssertEquals<long>(Unsafe.ReadUnaligned<long>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 4)), 1441999174721317504);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_23() => AssertEquals<MyStruct>(Unsafe.ReadUnaligned<MyStruct>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 4)), new MyStruct(1441999174721317504));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_24() => AssertEquals<Guid>(Unsafe.ReadUnaligned<Guid>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 4)), new Guid("ffabaa80-029b-1403-85a6-a7f900000000"));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_10() => AssertEquals(RVA2[^1], 127);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_11() => ThrowsOOB(() => Consume(RVA2[-int.MaxValue]));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_12() => ThrowsOOB(() => Consume(RVA2[0xFF]));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_13() => ThrowsOOB(() => Consume(RVA2[RVA2.Length]));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_14() => AssertEquals(RVA3[0], true);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_15() => AssertEquals(RVA3[1], false);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_16() => AssertEquals<int>(Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 0)), 268501148);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_17() => AssertEquals<uint>(Unsafe.ReadUnaligned<uint>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 1)), 2148532480);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_18() => AssertEquals<int>(Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 10)), -1501228029);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_19() => AssertEquals<short>(Unsafe.ReadUnaligned<short>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 0)), 156);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_20() => AssertEquals<ulong>(Unsafe.ReadUnaligned<ulong>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 1)), 11240891943721369856);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_21() => AssertEquals<long>(Unsafe.ReadUnaligned<long>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 4)), 1441999174721317504);
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_22() => AssertEquals<MyStruct>(Unsafe.ReadUnaligned<MyStruct>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 0)), new MyStruct(-23737906019368804));
[MethodImpl(MethodImplOptions.NoInlining)] static void Test_23() => AssertEquals<Guid>(Unsafe.ReadUnaligned<Guid>(ref Unsafe.Add(ref MemoryMarshal.GetReference(RVA1), 0)), new Guid("1001009c-aa80-ffab-9b02-031485a6a7f9"));

[MethodImpl(MethodImplOptions.NoInlining)]
static int Test_25() // AssertProp test
static int Test_24() // AssertProp test
{
byte x = RVA1[1];
if (x > 100)
Expand All @@ -72,7 +73,7 @@ static int Test_25() // AssertProp test
return x;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static int Test_26() // AssertProp test
static int Test_25() // AssertProp test
{
sbyte x = RVA2[0];
if (x > 100)
Expand Down Expand Up @@ -106,7 +107,7 @@ static void AssertEquals<T>(T actual, T expected, [CallerLineNumber] int line =
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void Consume<T>(T _) {}
static void Consume<T>(T _) { }

public record struct MyStruct(long a);
}