You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tiered miscompilation of Vector2.Dot(x, x) without SSE4.1 #96939
It looks like the vector multiplication meant to occur after the dot product has somehow disappeared at that step of compilation. JIT expects hadd to broadcast(?)
This works fine for Vector3/4, but for Vector2 when we can't use dpps it breaks down since we only do a single haddps. We therefore need to preserve the Create in the case SSE4.1 isn't available to ensure that we still broadcast the result to all elements.
#95568 is updating the Sum implementation to no longer use haddps and Dot is itself effectively Sum(Mul(x, y)), so we may want to simplify the logic here after that goes in and just implement it as Sum(Mul(x, y)) and have the pattern recognition in morph look for Create(Sqrt(Sum(x))) and Create(Sum(x)) instead. That should improve the perf and also fix the issue.
The backport can do the simpler fix of just avoiding the optimization in morph when SSE4.1 isn't supported and we can't guarantee the broadcast is happening.
Activity
moonheart08 commentedon Jan 13, 2024
It looks like the vector multiplication meant to occur after the dot product has somehow disappeared at that step of compilation. JIT expects hadd to broadcast(?)
tannergooding commentedon Jan 13, 2024
Looks like I introduced the bug in #81335
There is an optimization here that looks for
Create(Dot(..., ...))andCreate(Sqrt(Dot(..., ...))since we normally ensure the result is broadcast across the whole vector: https://github.com/dotnet/runtime/pull/81335/files#diff-5b83397bbbdd17bb9457998b520fdaaa474d165390985b66f32371561b6d0bacThis works fine for Vector3/4, but for Vector2 when we can't use
dppsit breaks down since we only do a singlehaddps. We therefore need to preserve theCreatein the case SSE4.1 isn't available to ensure that we still broadcast the result to all elements.#95568 is updating the
Sumimplementation to no longer usehaddpsandDotis itself effectivelySum(Mul(x, y)), so we may want to simplify the logic here after that goes in and just implement it asSum(Mul(x, y))and have the pattern recognition inmorphlook forCreate(Sqrt(Sum(x)))andCreate(Sum(x))instead. That should improve the perf and also fix the issue.The backport can do the simpler fix of just avoiding the optimization in
morphwhen SSE4.1 isn't supported and we can't guarantee the broadcast is happening.