Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failure System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02 #83316

Closed
v-wenyuxu opened this issue Mar 13, 2023 · 15 comments · Fixed by #88447
Closed

Test failure System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02 #83316

v-wenyuxu opened this issue Mar 13, 2023 · 15 comments · Fixed by #88447
Assignees
Labels
arch-x64 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI blocking-clean-ci-optional Blocking optional rolling runs JitStress CLR JIT issues involving JIT internal stress modes os-windows
Milestone

Comments

@v-wenyuxu
Copy link

Failed in Run: runtime-coreclr libraries-jitstress2-jitstressregs 20230311.1

Failed tests:

net8.0-windows-Release-x64-CoreCLR_checked-jitstress2_jitstressregs3-Windows.10.Amd64.Open
    - System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02

Error message:

Matrix4x4.CreateShadow did not provide expected value.
Expected: True
Actual:   False

Stack trace:

  at System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02() in /_/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs:line 762
  at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
  at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs:line 59
@v-wenyuxu v-wenyuxu added os-windows JitStress CLR JIT issues involving JIT internal stress modes arch-x64 labels Mar 13, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 13, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 13, 2023
@ghost
Copy link

ghost commented Mar 13, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak
See info in area-owners.md if you want to be subscribed.

Issue Details

Failed in Run: runtime-coreclr libraries-jitstress2-jitstressregs 20230311.1

Failed tests:

net8.0-windows-Release-x64-CoreCLR_checked-jitstress2_jitstressregs3-Windows.10.Amd64.Open
    - System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02

Error message:

Matrix4x4.CreateShadow did not provide expected value.
Expected: True
Actual:   False

Stack trace:

  at System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02() in /_/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs:line 762
  at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
  at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs:line 59
Author: v-wenyuxu
Assignees: -
Labels:

os-windows, JitStress, arch-x64, area-CodeGen-coreclr

Milestone: -

@JulieLeeMSFT
Copy link
Member

@tannergooding PTAL.

@JulieLeeMSFT JulieLeeMSFT removed the untriaged New issue has not been triaged by the area owner label Mar 14, 2023
@JulieLeeMSFT JulieLeeMSFT added this to the 8.0.0 milestone Mar 14, 2023
@v-wenyuxu
Copy link
Author

Failed again in: runtime-coreclr libraries-jitstress2-jitstressregs 20230513.1

Failed tests:

net8.0-windows-Release-x64-CoreCLR_checked-jitstress2_jitstressregs3-Windows.10.Amd64.Open
    - System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02

Error message:

 Matrix4x4.CreateShadow did not provide expected value.
Expected: True
Actual:   False

Stack trace:

    at System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02() in /_/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs:line 762
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs:line 59

@BruceForstall
Copy link
Member

@v-wenyuxu
Copy link
Author

Failed again in: runtime-coreclr libraries-jitstress2-jitstressregs 20230527.1

Failed tests:

net8.0-windows-Release-x64-CoreCLR_checked-jitstress2_jitstressregs3-Windows.10.Amd64.Open
    - System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02

Error message:

 Matrix4x4.CreateShadow did not provide expected value.
Expected: True
Actual:   False

Stack trace:

   at System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02() in /_/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs:line 762
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs:line 59

@v-wenyuxu
Copy link
Author

Failed again in: runtime-coreclr libraries-jitstress2-jitstressregs 20230603.1

Failed test:

net8.0-windows-Release-x64-CoreCLR_checked-jitstress2_jitstressregs3-Windows.10.Amd64.Open

- System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02

Error message:

Matrix4x4.CreateShadow did not provide expected value.
Expected: True
Actual:   False



Stack trace
   at System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02() in /_/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs:line 762
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs:line 59

@v-wenyuxu
Copy link
Author

Failed again in: runtime-coreclr libraries-jitstress2-jitstressregs 20230610.1

Failed tests:

net8.0-windows-Release-x64-CoreCLR_checked-jitstress2_jitstressregs3-Windows.10.Amd64.Open
    - System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02

Error message:

 Matrix4x4.CreateShadow did not provide expected value.
Expected: True
Actual:   False

Stack trace:

    at System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02() in /_/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs:line 762
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs:line 59

@BruceForstall BruceForstall added the blocking-clean-ci-optional Blocking optional rolling runs label Jun 12, 2023
@BruceForstall
Copy link
Member

@tannergooding @kunalspathak Since this is only failing under JitStressRegs=3 I assigned it to Kunal.

@kunalspathak
Copy link
Member

Taking a look now.

@kunalspathak
Copy link
Member

kunalspathak commented Jun 22, 2023

The problematic code is the following:

public void Matrix4x4CreateShadowTest02()
{
  if (lightDirInfo.Length() < 0.1f)
       continue;
  Vector3 lightDir = Vector3.Normalize(lightDirInfo);
 ...
 ...
}

[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly float Length()
{
    float lengthSquared = LengthSquared();
    return MathF.Sqrt(lengthSquared);
}


[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 Normalize(Vector3 value)
{
    return value / value.Length();
}

Here, we CSE lightDirInfo.Length() and store its value as float. In Normalize() when we reload the value, we reload the 64 bits float instead of 128 bits in xmm. That leads to incomplete vector getting loaded with few fields 0. This makes the division returning Nan.

G_M15576_IG58:  ;; offset=0187H
       vmovss   dword ptr [rsp+58H], xmm6
						;; size=6 bbWeight=16 PerfScore 16.00
G_M15576_IG59:  ;; offset=018DH
       vsqrtss  xmm7, xmm7, xmm6
						;; size=4 bbWeight=16 PerfScore 176.00
G_M15576_IG60:  ;; offset=0191H
       vmovss   xmm6, dword ptr [rsp+5CH]
						;; size=6 bbWeight=16 PerfScore 48.00
G_M15576_IG61:  ;; offset=0197H
       vucomiss xmm6, xmm7
						;; size=4 bbWeight=16 PerfScore 32.00
G_M15576_IG62:  ;; offset=019BH
       ja       G_M15576_IG166
						;; size=6 bbWeight=16 PerfScore 16.00
G_M15576_IG63:  ;; offset=01A1H
       vmovss   xmm7, dword ptr [rsp+58H]
						;; size=6 bbWeight=8 PerfScore 24.00
G_M15576_IG64:  ;; offset=01A7H
       vsqrtps  xmm7, xmm7
						;; size=4 bbWeight=8 PerfScore 88.00
G_M15576_IG65:  ;; offset=01ABH
       vdivps   xmm7, xmm2, xmm7
                                                                        ┌──▌  t719   simd16 
Generating: N269 (  3,  3) [000094] -----------                   t94 = ▌  HWINTRINSIC float  float ToScalar REG mm6 <l:$688, c:$689>
                                                                        ┌──▌  t94    float  
Generating: N271 (  3,  3) [000635] DA--------z                         ▌  STORE_LCL_VAR float  V62 cse4         d:1 mm6 REG mm6 $VN.Void
Saved:
      G_M15576_IG57:        ; offs=00012CH, size=0006H, bbWeight=16, BB09 [0002], extend
Created:
      G_M15576_IG58:        ; offs=000132H, size=0000H, bbWeight=16, gcrefRegs=0000 {}
Mapped BB09 to G_M15576_IG58
IN0039:        vmovss   dword ptr [V62 rsp+58H], xmm6

...
...
Generating: N287 (  1,  2) [000638] ----------z                  t638 =    LCL_VAR   float  V62 cse4         u:1 mm7 (last use) REG mm7 <l:$688, c:$689>
                                                                        ┌──▌  t638   float  
Generating: N289 (  2,  3) [000107] -----------                  t107 = ▌  HWINTRINSIC simd16 float Sqrt REG mm7 <l:$207, c:$208>
Mapped BB10 to G_M15576_IG63
IN003e:        vmovss   xmm7, dword ptr [V62 rsp+58H]

The / operator that takes float is:

       public static Vector3 operator /(Vector3 value1, float value2)
       {
            return value1 / new Vector3(value2);
       }

        [Intrinsic]
        public Vector3(float value) : this(value, value, value)
        {
        }

which seems that there are one or both the problems:

  1. the nodes that does the conversion of value2 -> Vector3(value2)
  2. we should not be CSEing the value directly.

Still investigating.

@kunalspathak
Copy link
Member

kunalspathak commented Jun 22, 2023

Mostly caused by #81335. JitStressRegs seems to just highlight the problem where we end up spilling the value.

@tannergooding
Copy link
Member

Noting this comes down to a CSE of HWINTRINSIC float float Dot and HWINTRINSIC TYP_SIMD12 float Dot.

Need to determine why VN decides these can be CSE'd even though they have differing return types.

@v-wenyuxu
Copy link
Author

v-wenyuxu commented Jun 25, 2023

Failed again in: runtime-coreclr libraries-jitstress2-jitstressregs 20230624.1

Failed tests:

net8.0-windows-Release-x64-CoreCLR_checked-jitstress2_jitstressregs3-Windows.10.Amd64.Open
    - System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02

Error message:

 Matrix4x4.CreateShadow did not provide expected value.
Expected: True
Actual:   False

Stack trace:

    at System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02() in /_/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs:line 762
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs:line 59

@v-wenyuxu
Copy link
Author

Failed again in: runtime-coreclr libraries-jitstress2-jitstressregs 20230701.1

Failed tests:

net8.0-windows-Release-x64-CoreCLR_checked-jitstress2_jitstressregs3-Windows.10.Amd64.Open
    - System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02

Error message:

Matrix4x4.CreateShadow did not provide expected value.
Expected: True
Actual:   False

Stack trace:

   at System.Numerics.Tests.Matrix4x4Tests.Matrix4x4CreateShadowTest02() in /_/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs:line 762
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs:line 59

@kunalspathak
Copy link
Member

Assigning to @tannergooding to resolve other problems that does not necessarily show up in this issue.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-x64 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI blocking-clean-ci-optional Blocking optional rolling runs JitStress CLR JIT issues involving JIT internal stress modes os-windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants