JIT: Track sideness of arrOp in GetCheckedBoundArithInfo#100848
JIT: Track sideness of arrOp in GetCheckedBoundArithInfo#100848EgorBo merged 5 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
|
PTAL @AndyAyersMS, @dotnet/jit-contrib Do we need to backport this to net8? The repro seems to be small, but it has to be a very specific pattern to kick in.. |
I think we should make a case for it, since it was found by one of our users. |
|
Maybe another consideration is whether this is a regression. Original issue said this does not happen in .NET 6, but I think that code pattern is fairly old. So it's worth trying your repro on .NET 7 or .NET 6 to understand what happens there. |
|
If this is not backported to NET8, could you provide the alternative pattern that solves the issue - given the code in the original issue. The original issue uses framework calls to Array.Copy, inside which the above problem arises if I'm not mistaken. Asking only since @AndyAyersMS mentions the pattern as being fairly old. Thanks! |
The bug was there for quite a while, it was exposed it .NET 8.0 in #81998 that introduced a VN optimization that kicks in here for |
|
I'll try to backport it.
It seems like the pattern itself is located in the standard library so it's hard to workaround it. You may try to disable |
|
/backport to release/8.0-staging |
|
Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/8653024932 |
|
@EgorBo backporting to release/8.0-staging failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Add ArrOpLHS to CompareCheckedBoundArithInfo
Using index info to reconstruct a base tree...
M src/coreclr/jit/optcse.cpp
M src/coreclr/jit/valuenum.h
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/jit/valuenum.h
Auto-merging src/coreclr/jit/optcse.cpp
CONFLICT (content): Merge conflict in src/coreclr/jit/optcse.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Add ArrOpLHS to CompareCheckedBoundArithInfo
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128Please backport manually! |
|
@EgorBo an error occurred while backporting to release/8.0-staging, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
Fixes #100809
Minimal repro:
It prints
Falsein Debug andTruein Release.Here we have
((arr_len - (arr_len + -2)) >= 0)expression which should evaluate into2 >= 0->true. But instead, we evaluate it as-2 >= 0->false. It happens becauseGetCheckedBoundArithInfolooses track where it took arrOp in cmpOp - from op1 or op2? the order is important since we don't guarantee that arrOper is commutative.