dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.94k stars 4.64k forks source link

Test failure: System.Numerics.Tests.GenericVectorTests.NarrowDouble #36614

Closed BruceForstall closed 4 years ago

BruceForstall commented 4 years ago

Failure in libraries System.Numerics.Vectors.Tests: release libraries, checked coreclr with:

set COMPlus_JitStress=1

fails with set COMPlus_TieredCompilation 0 or 1.

Windows x86

E.g.,

build -s libs+libs.tests -runtimeConfiguration checked -c Release -arch x86 /p:ArchiveTests=true

(the /p:ArchiveTests=true is required to build the RunTests.cmd wrapper scripts)

C:\gh\runtime\artifacts\bin\System.Numerics.Vectors.Tests\net5.0-Release>call .\RunTests.cmd -r C:\gh\runtime\artifacts\bin\testhost\net5.0-Windows_NT-Release-x86
----- start Sun 05/17/2020 11:33:07.75 ===============  To repro directly: =====================================================
pushd C:\gh\runtime\artifacts\bin\System.Numerics.Vectors.Tests\net5.0-Release\
"C:\gh\runtime\artifacts\bin\testhost\net5.0-Windows_NT-Release-x86\dotnet.exe" exec --runtimeconfig System.Numerics.Vectors.Tests.runtimeconfig.json --depsfile System.Numerics.Vectors.Tests.deps.json xunit.console.dll System.Numerics.Vectors.Tests.dll -xml testResults.xml -nologo -nocolor -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing
popd
===========================================================================================================

C:\gh\runtime\artifacts\bin\System.Numerics.Vectors.Tests\net5.0-Release>"C:\gh\runtime\artifacts\bin\testhost\net5.0-Windows_NT-Release-x86\dotnet.exe" exec --runtimeconfig System.Numerics.Vectors.Tests.runtimeconfig.json --depsfile System.Numerics.Vectors.Tests.deps.json xunit.console.dll System.Numerics.Vectors.Tests.dll -xml testResults.xml -nologo -nocolor -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing
  Discovering: System.Numerics.Vectors.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.Numerics.Vectors.Tests (found 1191 of 1194 test cases)
  Starting:    System.Numerics.Vectors.Tests (parallel test collections = on, max threads = 8)
    System.Numerics.Tests.GenericVectorTests.NarrowDouble [FAIL]
      Assert.Equal() Failure
      Expected: 1.2382202E+09
      Actual:   -1.7497244E+09
      Stack Trace:
        C:\gh\runtime\src\libraries\System.Numerics.Vectors\tests\GenericVectorTests.cs(3048,0): at System.Numerics.Tests.GenericVectorTests.NarrowDouble()
  Finished:    System.Numerics.Vectors.Tests
=== TEST EXECUTION SUMMARY ===
   System.Numerics.Vectors.Tests  Total: 1191, Errors: 0, Failed: 1, Skipped: 0, Time: 25.167s
----- end Sun 05/17/2020 11:33:40.23 ----- exit code 1 ----------------------------------------------------------

The failure mode is different every run: the Expected/Actual values both change.

@tannergooding @CarolEidt

tannergooding commented 4 years ago

The C# code under test is:

        public void NarrowDouble()
        {
            double[] source1 = GenerateRandomValuesForVector<double>();
            double[] source2 = GenerateRandomValuesForVector<double>();
            Vector<double> sourceVec1 = new Vector<double>(source1);
            Vector<double> sourceVec2 = new Vector<double>(source2);
            Vector<float> dest = Vector.Narrow(sourceVec1, sourceVec2);

            for (int i = 0; i < Vector<double>.Count; i++)
            {
                Assert.Equal(unchecked((float)source1[i]), dest[i]);
            }
            for (int i = 0; i < Vector<double>.Count; i++)
            {
                Assert.Equal(unchecked((float)source2[i]), dest[i + Vector<double>.Count]);
            }
        }

Generated assembly is:

; Assembly listing for method System.Numerics.Tests.GenericVectorTests:NarrowDouble():this
; Emitting BLENDED_CODE for Pentium 4 - Windows
; optimized code
; double-aligned frame
; partially interruptible
; Final local variable assignments
;
;* V00 this         [V00    ] (  0,  0   )     ref  ->  zero-ref    this class-hnd ptr
;  V01 loc0         [V01,T01] (  5,  3   )     ref  ->  esi         class-hnd
;  V02 loc1         [V02,T02] (  5,  3   )     ref  ->  edi         class-hnd
;  V03 loc2         [V03,T05] (  2,  2   )  simd32  ->  mm0         ld-addr-op
;  V04 loc3         [V04,T06] (  2,  2   )  simd32  ->  mm1         ld-addr-op
;  V05 loc4         [V05,T07] (  3,  1   )  simd32  ->  [esp+0x24]   ld-addr-op ptr
;* V06 loc5         [V06    ] (  0,  0   )  struct ( 8) zero-ref    ld-addr-op
;  V07 loc6         [V07,T04] (  7,  1   )     int  ->  ebx
;  V08 loc7         [V08,T08] (  7,  0   )     int  ->  esi
;  V09 tmp0         [V09    ] (  1,  1   )     int  ->  [esp+0x20]   do-not-enreg[X] must-init addr-exposed "GSCookie dummy"
;  V10 tmp1         [V10,T10] (  2,  0   )   float  ->  mm1         "Inlining Arg"
;  V11 tmp2         [V11,T11] (  2,  0   )   float  ->  mm2         "Inlining Arg"
;  V12 tmp3         [V12,T00] (  4,  4   )    bool  ->  eax         V06.hasValue(offs=0x00) P-INDEP "field V06.hasValue (fldOffset=0x0)"
;* V13 tmp4         [V13,T03] (  0,  0   )     int  ->  zero-ref    V06.value(offs=0x04) P-INDEP "field V06.value (fldOffset=0x4)"
;  V14 tmp5         [V14,T09] (  2,  0   )     ref  ->  ecx         "argument with side effect"
;  V15 GsCookie     [V15    ] (  1,  1   )     int  ->  [esp+0x44]   do-not-enreg[X] must-init addr-exposed "GSSecurityCookie"
;  V16 rat0         [V16    ] (  1,  1   )  simd32  ->  [esp+0x00]   do-not-enreg[XS] must-init addr-exposed "SIMDInitTempVar"
;
; Lcl frame size = 76

G_M33220_IG01:
       55           push     ebp
       8BEC         mov      ebp, esp
       83E4F8       and      esp, -8
       57           push     edi
       56           push     esi
       53           push     ebx
       83EC4C       sub      esp, 76
       C5F877       vzeroupper
       C5D857E4     vxorps   xmm4, xmm4
       C5FA7F2424   vmovdqu  xmmword ptr [esp], xmm4
       C5FA7F642410 vmovdqu  xmmword ptr [esp+10H], xmm4
       C5FA7F642420 vmovdqu  xmmword ptr [esp+20H], xmm4
       C5FA7F642430 vmovdqu  xmmword ptr [esp+30H], xmm4
       33C0         xor      eax, eax
       89442440     mov      dword ptr [esp+40H], eax
       89442444     mov      dword ptr [esp+44H], eax
       C744244478563412 mov      dword ptr [esp+44H], 0x12345678
                                                ;; bbWeight=1    PerfScore 13.33
G_M33220_IG02:
       33C0         xor      eax, eax
       6A00         push     0
       50           push     eax
       E832EDFFFF   call     System.Numerics.Tests.GenericVectorTests:GenerateRandomValuesForVector(System.Nullable`1[Int32]):System.Double[]
       8BF0         mov      esi, eax
       33C0         xor      eax, eax
       6A00         push     0
       50           push     eax
       E826EDFFFF   call     System.Numerics.Tests.GenericVectorTests:GenerateRandomValuesForVector(System.Nullable`1[Int32]):System.Double[]
       8BF8         mov      edi, eax
       837E0403     cmp      dword ptr [esi+4], 3
       0F86DD000000 jbe      G_M33220_IG08
       C5FD104608   vmovupd  ymm0, ymmword ptr[esi+8]
       837F0403     cmp      dword ptr [edi+4], 3
       0F86CE000000 jbe      G_M33220_IG08
       C5FD104F08   vmovupd  ymm1, ymmword ptr[edi+8]
       C5FD5AC0     vcvtpd2ps ymm0, ymm0
       C5FD5AD1     vcvtpd2ps ymm2, ymm1
       C4E37D18C201 vinsertf128 ymm0, ymm2, 1
       33DB         xor      ebx, ebx
                                                ;; bbWeight=1    PerfScore 32.25
G_M33220_IG03:
       3B5E04       cmp      ebx, dword ptr [esi+4]
       0F83AC000000 jae      G_M33220_IG08
       C5F35A4CDE08 vcvtsd2ss xmm1, dword ptr [esi+8*ebx+8]
       C5FD11442424 vmovupd  ymmword ptr[esp+24H], ymm0
       C5FD110424   vmovupd  ymmword ptr[esp], ymm0
       C5FA10149C   vmovss   xmm2, dword ptr [esp+4*ebx]
       83EC04       sub      esp, 4
       C5FA110C24   vmovss   dword ptr [esp], xmm1
       83EC04       sub      esp, 4
       C5FA111424   vmovss   dword ptr [esp], xmm2
       33C9         xor      ecx, ecx
       E8E0ECFFFF   call     Xunit.Assert:GetEqualityComparer(System.Collections.IEqualityComparer):System.Collections.Generic.IEqualityComparer`1[Single]
       8BC8         mov      ecx, eax
       E8D1FDFFFF   call     Xunit.Assert:Equal(float,float,System.Collections.Generic.IEqualityComparer`1[Single])
       43           inc      ebx
       83FB04       cmp      ebx, 4
       C5FD10442424 vmovupd  ymm0, ymmword ptr[esp+24H]
       7CB7         jl       SHORT G_M33220_IG03
                                                ;; bbWeight=0    PerfScore 0.00
G_M33220_IG04:
       33F6         xor      esi, esi
                                                ;; bbWeight=0    PerfScore 0.00
G_M33220_IG05:
       3B7704       cmp      esi, dword ptr [edi+4]
       735E         jae      SHORT G_M33220_IG08
       C5F35A4CF708 vcvtsd2ss xmm1, dword ptr [edi+8*esi+8]
       83EC04       sub      esp, 4
       C5FA110C24   vmovss   dword ptr [esp], xmm1
       8D4604       lea      eax, [esi+4]
       C5FD11442428 vmovupd  ymmword ptr[esp+24H+04H], ymm0
       C5FD11442404 vmovupd  ymmword ptr[esp+04H], ymm0
       C5FA100C84   vmovss   xmm1, dword ptr [esp+4*eax]
       83EC04       sub      esp, 4
       C5FA110C24   vmovss   dword ptr [esp], xmm1
       E887ECFFFF   call     Xunit.Assert:Equal(float,float)
       46           inc      esi
       83FE04       cmp      esi, 4
       C5FD10442424 vmovupd  ymm0, ymmword ptr[esp+24H]
       7CC0         jl       SHORT G_M33220_IG05
                                                ;; bbWeight=0    PerfScore 0.00
G_M33220_IG06:
       817C244478563412 cmp      dword ptr [esp+44H], 0x12345678
       7405         je       SHORT G_M33220_IG07
       E80C325051   call     CORINFO_HELP_FAIL_FAST
                                                ;; bbWeight=140    PerfScore 420.00
G_M33220_IG07:
       C5F877       vzeroupper
       83C44C       add      esp, 76
       5B           pop      ebx
       5E           pop      esi
       5F           pop      edi
       8BE5         mov      esp, ebp
       5D           pop      ebp
       C3           ret
                                                ;; bbWeight=140    PerfScore 630.00
G_M33220_IG08:
       E86A6B5051   call     CORINFO_HELP_RNGCHKFAIL
       CC           int3
                                                ;; bbWeight=0    PerfScore 0.00

; Total bytes of code 303, prolog size 60, PerfScore 1128.18, (MethodHash=11177e3b) for method System.Numerics.Tests.GenericVectorTests:NarrowDouble():this
; ============================================================
tannergooding commented 4 years ago

JitDump is here: JitDump.txt The assert indicates the issue is in G_M33220_IG05 (the second for loop), but I can't debug as VS crashes when trying to attach to the managed side. I believe the issue is that vmovss xmm1, dword ptr [esp+4*eax] is off by 1 (sizeof(float)) due to esp having been subtracted.

BruceForstall commented 4 years ago

@kunalspathak Can you investigate this one?