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

[JIT] ARM32/ARM64 - Fixed zero/sign-extension for GT_STORE_LCL_VAR in codegen #84716

Merged
merged 8 commits into from Apr 18, 2023

Conversation

TIHan
Copy link
Member

@TIHan TIHan commented Apr 12, 2023

Resolves #84693

We were not handling zero/sign-extends for NormalizeOnLoad local stores correctly on ARM.

@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 Apr 12, 2023
@ghost ghost assigned TIHan Apr 12, 2023
@ghost
Copy link

ghost commented Apr 12, 2023

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

Issue Details

Resolves #84693

Author: TIHan
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@TIHan TIHan changed the title [JIT] ARM64 - Fix zero-extension for stores [JIT] ARM64 - Fix zero/sign-extension for stores Apr 12, 2023
@TIHan TIHan changed the title [JIT] ARM64 - Fix zero/sign-extension for stores [JIT] ARM32/ARM64 - Fix zero/sign-extension for stores Apr 12, 2023
@TIHan TIHan marked this pull request as ready for review April 12, 2023 19:32
@TIHan
Copy link
Member Author

TIHan commented Apr 12, 2023

@dotnet/jit-contrib @kunalspathak This is ready pending CI.

@TIHan TIHan changed the title [JIT] ARM32/ARM64 - Fix zero/sign-extension for stores [JIT] ARM32/ARM64 - Fix zero/sign-extension for GT_STORE_LCL_VAR Apr 12, 2023
@TIHan TIHan changed the title [JIT] ARM32/ARM64 - Fix zero/sign-extension for GT_STORE_LCL_VAR [JIT] ARM32/ARM64 - Fixed zero/sign-extension for GT_STORE_LCL_VAR in codegen Apr 12, 2023
@SingleAccretion
Copy link
Contributor

What was the underlying problem here (perhaps the one we discussed a while back)?

If it was NOL, that implies fixing the "store" part of code is a workaround.

@TIHan
Copy link
Member Author

TIHan commented Apr 12, 2023

@SingleAccretion From the issue, we were not zero-extending on store for a NOL, here is the before and after diffs in regards to that example in the issue:
image

@SingleAccretion
Copy link
Contributor

In principle this should not matter, since upper bits of a NOL local have to be assumed to be random. Is the dump available?

@TIHan
Copy link
Member Author

TIHan commented Apr 12, 2023

dump.txt

@TIHan
Copy link
Member Author

TIHan commented Apr 12, 2023

On x64, we do the zero-extend:

       mov      rax, 0xD1FFAB1E      ; data for test.Program:s_2
       mov      word  ptr [rax], 1
       movsx    rax, word  ptr [rax]
       neg      eax
       movzx    rcx, al      ; <--- zero-extend
       and      ecx, ecx
       call     [System.Console:WriteLine(int)]
       xor      eax, eax

@SingleAccretion
Copy link
Contributor

So this is a variation of the "NOL does not work well with VN" issue. In particular, the problem is how [000012] is numbered here:

***** BB01, STMT00002(before)
N005 ( 20, 10) [000013] --CXG------                         *  CALL      void   System.Console:WriteLine(int)
N004 (  6,  7) [000016] ----------- arg0 in x0              \--*  CAST      int <- ubyte <- int
N003 (  5,  5) [000012] -----------                            \--*  AND       int   
N001 (  2,  2) [000010] -----------                               +--*  LCL_VAR   int    V00 arg0         u:2
N002 (  2,  2) [000011] -----------                               \--*  LCL_VAR   int    V00 arg0         u:2 (last use)

N001 [000010]   LCL_VAR   V00 arg0         u:2 => <l:$46 {IntCns 255}, c:$200 {$1c0, int <- ubyte <- int}>
N002 [000011]   LCL_VAR   V00 arg0         u:2 (last use) => <l:$46 {IntCns 255}, c:$200 {$1c0, int <- ubyte <- int}>
N003 [000012]   AND       => <l:$46 {IntCns 255}, c:$200 {$1c0, int <- ubyte <- int}>
N004 [000016]   CAST      => <l:$46 {IntCns 255}, c:$201 {$200, int <- ubyte <- int}>
  fgCurMemoryVN[GcHeap] assigned for CALL at [000013] to VN: $c1.
N005 [000013]   CALL      => $VN.Void

***** BB01, STMT00002(after)
N005 ( 20, 10) [000013] --CXG------                         *  CALL      void   System.Console:WriteLine(int) $VN.Void
N004 (  6,  7) [000016] ----------- arg0 in x0              \--*  CAST      int <- ubyte <- int <l:$46, c:$201>
N003 (  5,  5) [000012] -----------                            \--*  AND       int    <l:$46, c:$200>
N001 (  2,  2) [000010] -----------                               +--*  LCL_VAR   int    V00 arg0         u:2 <l:$46, c:$200>
N002 (  2,  2) [000011] -----------                               \--*  LCL_VAR   int    V00 arg0         u:2 (last use) <l:$46, c:$200>

In reality, the value of AND's upper bits is undefined (and equal to V00's). A denormalized NOL local without a cast on top of it is not legal (so one can view the original bug to be in the morph's transform which pushed the cast up).

That said, I would not have objections against merging this change anyway, for consistency between platforms if nothing else (if so, we should also fix LA64 and RISC-V).

@TIHan
Copy link
Member Author

TIHan commented Apr 14, 2023

Diffs
No regressions for arm64. There are some regressions for arm32, but that is fine since this fixes a correctness issue.

@kunalspathak
Copy link
Member

Based on #84693 (comment), does this need to be backported to 7.0?

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you will have to fix the formatting issues before merging.

@TIHan
Copy link
Member Author

TIHan commented Apr 18, 2023

does this need to be backported to 7.0?

Yes we should backport this since it is a correctness issue.

@TIHan
Copy link
Member Author

TIHan commented Apr 18, 2023

CI failures are unrelated. Merging.

@TIHan TIHan merged commit 9cc8163 into dotnet:main Apr 18, 2023
129 of 136 checks passed
@ghost ghost locked as resolved and limited conversation to collaborators May 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fuzzlyn] Arm64 failure for negation, cast, bitwise-and
3 participants