Repository: dotnet/runtime
File: src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Interlocked.cs (C#)

Code before:
using System.Runtime.CompilerServices;

namespace System.Threading
{
    public static partial class Interlocked
    {
        #region CompareExchange

        [Intrinsic]
        public static int CompareExchange(ref int location1, int value, int comparand)
        {
#if TARGET_X86 || TARGET_AMD64 || TARGET_ARM64 || TARGET_RISCV64
            return CompareExchange(ref location1, value, comparand); // Must expand intrinsic
#else
            if (Unsafe.IsNullRef(ref location1))
                ThrowHelper.ThrowNullReferenceException();
            return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand);
#endif
        }

        // This is used internally in cases where having a managed
        // ref to the location is unsafe (Ex: it is the object header of a pinned object).
        // The intrinsic expansion for this overload is exactly the same as for the `ref int`
        // variant and will go on the same path since expansion is triggered by the name and
        // return type of the method.
        // The important part is avoiding `ref *location` that is reported as byref to the GC. 
        [Intrinsic]
        internal static unsafe int CompareExchange(int* location1, int value, int comparand)
        {
#if TARGET_X86 || TARGET_AMD64 || TARGET_ARM64 || TARGET_RISCV64
            return CompareExchange(location1, value, comparand); // Must expand intrinsic
#else
            Debug.Assert(location1 != null);
            return RuntimeImports.InterlockedCompareExchange(location1, value, comparand);
#endif
        }

        [Intrinsic]
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static long CompareExchange(ref long location1, long value, long comparand)
        {
#if TARGET_AMD64 || TARGET_ARM64 || TARGET_RISCV64
            return CompareExchange(ref location1, value, comparand); // Must expand intrinsic
#else
            if (Unsafe.IsNullRef(ref location1))
                ThrowHelper.ThrowNullReferenceException();
            return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand);
#endif
        }

        [Intrinsic]

Review comment (suggestion):
```suggestion
        // The important part is avoiding `ref *location` that is reported as byref to the GC.
```

Code after:
using System.Runtime.CompilerServices;

namespace System.Threading
{
    public static partial class Interlocked
    {
        #region CompareExchange

        [Intrinsic]
        public static int CompareExchange(ref int location1, int value, int comparand)
        {
#if TARGET_X86 || TARGET_AMD64 || TARGET_ARM64 || TARGET_RISCV64
            return CompareExchange(ref location1, value, comparand); // Must expand intrinsic
#else
            if (Unsafe.IsNullRef(ref location1))
                ThrowHelper.ThrowNullReferenceException();
            return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand);
#endif
        }

        // This is used internally in cases where having a managed
        // ref to the location is unsafe (Ex: it is the object header of a pinned object).
        // The intrinsic expansion for this overload is exactly the same as for the `ref int`
        // variant and will go on the same path since expansion is triggered by the name and
        // return type of the method.
        // The important part is avoiding `ref *location` that is reported as byref to the GC.
        [Intrinsic]
        internal static unsafe int CompareExchange(int* location1, int value, int comparand)
        {
#if TARGET_X86 || TARGET_AMD64 || TARGET_ARM64 || TARGET_RISCV64
            return CompareExchange(location1, value, comparand); // Must expand intrinsic
#else
            Debug.Assert(location1 != null);
            return RuntimeImports.InterlockedCompareExchange(location1, value, comparand);
#endif
        }

        [Intrinsic]
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static long CompareExchange(ref long location1, long value, long comparand)
        {
#if TARGET_AMD64 || TARGET_ARM64 || TARGET_RISCV64
            return CompareExchange(ref location1, value, comparand); // Must expand intrinsic
#else
            if (Unsafe.IsNullRef(ref location1))
                ThrowHelper.ThrowNullReferenceException();
            return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand);
#endif
        }

        [Intrinsic]