Skip to content

JIT: Another missing normalize on load example #85672

Closed

Description

@jakobbotsch
// Generated by Fuzzlyn v1.5 on 2023-05-02 17:40:29
// Run on Arm64 MacOS
// Seed: 15874626812102884954
// Reduced from 128.8 KiB to 1.2 KiB in 00:00:50
// Debug: Outputs 0
// Release: Outputs 4294967040
public class Program
{
    public static IRuntime s_rt;
    public static sbyte s_10 = -1;
    public static int[, ] s_72 = new int[, ]{{0}};
    public static uint[, ] s_93 = new uint[, ]{{0}};
    public static void Main()
    {
        s_rt = new Runtime();
        var vr1 = new long[]{0};
        M50(0, vr1, s_10, ref s_93);
    }

    public static void M50(sbyte arg0, long[] arg1, sbyte arg2, ref uint[, ] arg4)
    {
        uint var0 = default(uint);
        bool var5 = default(bool);
        arg2 = arg0;
        try
        {
            arg2 |= arg2;
            arg4[0, 0] = (uint)arg0;
        }
        finally
        {
            var0 = (uint)(var0 * s_72[0, 0]++);
            if (var5)
            {
                arg1 = new long[]{1};
                short var6 = 0;
                s_rt.WriteLine(var6);
            }

            s_rt.WriteLine(var5);
        }

        s_rt.WriteLine(arg2);
        s_rt.WriteLine(arg4[0, 0]);
    }
}

public interface IRuntime
{
    void WriteLine<T>(T value);
}

public class Runtime : IRuntime
{
    public void WriteLine<T>(T value) => System.Console.WriteLine(value);
}

Codegen:

; Assembly listing for method Program:M50(byte,long[],byte,byref)
; Emitting BLENDED_CODE for X64 CPU with AVX - Windows
; optimized code
; rbp based frame
; fully interruptible
; No PGO data
; Final local variable assignments
;
;  V00 arg0         [V00,T09] (  3,  3   )    byte  ->  rcx         single-def
;* V01 arg1         [V01    ] (  0,  0   )     ref  ->  zero-ref    class-hnd single-def
;  V02 arg2         [V02,T03] (  7,  7   )    byte  ->  [rbp+20H]   do-not-enreg[Z] EH-live
;  V03 arg3         [V03,T04] (  4,  4   )   byref  ->  [rbp+28H]   EH-live single-def
;* V04 loc0         [V04    ] (  0,  0   )     int  ->  zero-ref   
;* V05 loc1         [V05,T21] (  0,  0   )    bool  ->  zero-ref    EH-live single-def
;  V06 loc2         [V06,T19] (  2,  2   )     int  ->  rdx         single-def
;* V07 loc3         [V07    ] (  0,  0   )   short  ->  zero-ref    single-def
;  V08 OutArgs      [V08    ] (  1,  1   )  lclBlk (32) [rsp+00H]   "OutgoingArgSpace"
;  V09 tmp1         [V09,T05] (  3,  6   )     ref  ->  rsi         single-def "LDVIRTFTN this pointer"
;  V10 tmp2         [V10,T12] (  2,  4   )    long  ->  rax         "VirtualCall through function pointer"
;  V11 tmp3         [V11,T06] (  3,  6   )     ref  ->  rsi         single-def "LDVIRTFTN this pointer"
;  V12 tmp4         [V12,T13] (  2,  4   )    long  ->  rax         "VirtualCall through function pointer"
;  V13 tmp5         [V13,T07] (  3,  6   )   byref  ->  rcx         single-def "dup spill"
;  V14 tmp6         [V14,T08] (  3,  6   )     ref  ->  rsi         single-def "LDVIRTFTN this pointer"
;  V15 tmp7         [V15,T14] (  2,  4   )    long  ->  rax         "VirtualCall through function pointer"
;* V16 tmp8         [V16    ] (  0,  0   )     ref  ->  zero-ref    class-hnd exact "dup spill"
;* V17 tmp9         [V17    ] (  0,  0   )     ref  ->  zero-ref    single-def "LDVIRTFTN this pointer"
;* V18 tmp10        [V18    ] (  0,  0   )    long  ->  zero-ref    "VirtualCall through function pointer"
;* V19 tmp11        [V19    ] (  0,  0   )     ref  ->  zero-ref    single-def "arr expr"
;  V20 tmp12        [V20,T00] ( 18, 36   )     ref  ->  registers   "MD array shared temp"
;  V21 tmp13        [V21,T01] (  9, 18   )     int  ->  registers   "MD array shared temp"
;  V22 tmp14        [V22,T02] (  9, 18   )     int  ->  registers   "MD array shared temp"
;  V23 PSPSym       [V23,T20] (  1,  1   )    long  ->  [rbp-20H]   do-not-enreg[V] "PSPSym"
;  V24 cse0         [V24,T15] (  3,  3   )     int  ->  rcx         "CSE - moderate"
;  V25 cse1         [V25,T10] (  4,  4   )    long  ->  [rbp-10H]   do-not-enreg[H] EH-live "CSE - aggressive"
;  V26 cse2         [V26,T11] (  4,  4   )    long  ->  [rbp-18H]   do-not-enreg[H] EH-live "CSE - aggressive"
;  V27 cse3         [V27,T16] (  3,  3   )     int  ->   r8         "CSE - moderate"
;  V28 cse4         [V28,T17] (  3,  3   )     int  ->   r8         "CSE - moderate"
;  V29 cse5         [V29,T18] (  3,  3   )     int  ->  rcx         "CSE - moderate"
;
; Lcl frame size = 56

G_M16055_IG01:              ;; offset=0000H
       55                   push     rbp
       56                   push     rsi
       4883EC38             sub      rsp, 56
       488D6C2440           lea      rbp, [rsp+40H]
       488965E0             mov      qword ptr [rbp-20H], rsp
       44894520             mov      dword ptr [rbp+20H], r8d
       4C894D28             mov      bword ptr [rbp+28H], r9
						;; size=23 bbWeight=1 PerfScore 5.75
G_M16055_IG02:              ;; offset=0017H
       884D20               mov      byte  ptr [rbp+20H], cl
						;; size=3 bbWeight=1 PerfScore 1.00
G_M16055_IG03:              ;; offset=001AH
       8B4D20               mov      ecx, dword ptr [rbp+20H]
       0B4D20               or       ecx, dword ptr [rbp+20H]
       884D20               mov      byte  ptr [rbp+20H], cl
       498B31               mov      rsi, gword ptr [r9]
       33D2                 xor      edx, edx
       2B5618               sub      edx, dword ptr [rsi+18H]
       3B5610               cmp      edx, dword ptr [rsi+10H]
       731C                 jae      SHORT G_M16055_IG04
       448B4614             mov      r8d, dword ptr [rsi+14H]
       410FAFD0             imul     edx, r8d
       33C0                 xor      eax, eax
       2B461C               sub      eax, dword ptr [rsi+1CH]
       413BC0               cmp      eax, r8d
       730A                 jae      SHORT G_M16055_IG04
       03C2                 add      eax, edx
       8BD0                 mov      edx, eax
       894C9620             mov      dword ptr [rsi+4*rdx+20H], ecx
       EB06                 jmp      SHORT G_M16055_IG05
						;; size=50 bbWeight=1 PerfScore 25.25
G_M16055_IG04:              ;; offset=004CH
       E8EF96525F           call     CORINFO_HELP_RNGCHKFAIL
       CC                   int3     
						;; size=6 bbWeight=0 PerfScore 0.00
G_M16055_IG05:              ;; offset=0052H
       488BCC               mov      rcx, rsp
       E883000000           call     G_M16055_IG10
						;; size=8 bbWeight=1 PerfScore 1.25
G_M16055_IG06:              ;; offset=005AH
       90                   nop      
						;; size=1 bbWeight=1 PerfScore 0.25
G_M16055_IG07:              ;; offset=005BH
       488B4DF0             mov      rcx, qword ptr [rbp-10H]
       488B31               mov      rsi, gword ptr [rcx]
       488BCE               mov      rcx, rsi
       488B55E8             mov      rdx, qword ptr [rbp-18H]
       49B888B5D141F97F0000 mov      r8, 0x7FF941D1B588      ; token handle
       E8586E525F           call     CORINFO_HELP_VIRTUAL_FUNC_PTR
       480FBE5520           movsx    rdx, byte  ptr [rbp+20H]
       488BCE               mov      rcx, rsi
       FFD0                 call     rax
       488B4DF0             mov      rcx, qword ptr [rbp-10H]
       488B31               mov      rsi, gword ptr [rcx]
       488BCE               mov      rcx, rsi
       488B55E8             mov      rdx, qword ptr [rbp-18H]
       49B848B6D141F97F0000 mov      r8, 0x7FF941D1B648      ; token handle
       E8316E525F           call     CORINFO_HELP_VIRTUAL_FUNC_PTR
       4C8B4D28             mov      r9, bword ptr [rbp+28H]
       498B11               mov      rdx, gword ptr [r9]
       33C9                 xor      ecx, ecx
       2B4A18               sub      ecx, dword ptr [rdx+18H]
       3B4A10               cmp      ecx, dword ptr [rdx+10H]
       7327                 jae      SHORT G_M16055_IG09
       448B4214             mov      r8d, dword ptr [rdx+14H]
       410FAFC8             imul     ecx, r8d
       4533C9               xor      r9d, r9d
       442B4A1C             sub      r9d, dword ptr [rdx+1CH]
       453BC8               cmp      r9d, r8d
       7313                 jae      SHORT G_M16055_IG09
       4103C9               add      ecx, r9d
       8B548A20             mov      edx, dword ptr [rdx+4*rcx+20H]
       488BCE               mov      rcx, rsi
						;; size=115 bbWeight=1 PerfScore 38.50
G_M16055_IG08:              ;; offset=00CEH
       4883C438             add      rsp, 56
       5E                   pop      rsi
       5D                   pop      rbp
       48FFE0               tail.jmp rax
						;; size=9 bbWeight=1 PerfScore 3.25
G_M16055_IG09:              ;; offset=00D7H
       E86496525F           call     CORINFO_HELP_RNGCHKFAIL
       CC                   int3     
						;; size=6 bbWeight=0 PerfScore 0.00
G_M16055_IG10:              ;; offset=00DDH
       55                   push     rbp
       56                   push     rsi
       4883EC28             sub      rsp, 40
       488B6920             mov      rbp, qword ptr [rcx+20H]
       48896C2420           mov      qword ptr [rsp+20H], rbp
       488D6D40             lea      rbp, [rbp+40H]
						;; size=19 bbWeight=1 PerfScore 5.75
G_M16055_IG11:              ;; offset=00F0H
       48B9581D00EB48020000 mov      rcx, 0x248EB001D58      ; data for Program:s_72
       488B31               mov      rsi, gword ptr [rcx]
       33D2                 xor      edx, edx
       2B5618               sub      edx, dword ptr [rsi+18H]
       3B5610               cmp      edx, dword ptr [rsi+10H]
       735E                 jae      SHORT G_M16055_IG13
       8B4E14               mov      ecx, dword ptr [rsi+14H]
       0FAFD1               imul     edx, ecx
       33C0                 xor      eax, eax
       2B461C               sub      eax, dword ptr [rsi+1CH]
       3BC1                 cmp      eax, ecx
       734F                 jae      SHORT G_M16055_IG13
       03D0                 add      edx, eax
       8BCA                 mov      ecx, edx
       488D4C8E20           lea      rcx, bword ptr [rsi+4*rcx+20H]
       8B11                 mov      edx, dword ptr [rcx]
       FFC2                 inc      edx
       8911                 mov      dword ptr [rcx], edx
       48B9501D00EB48020000 mov      rcx, 0x248EB001D50      ; data for Program:s_rt
       48894DF0             mov      qword ptr [rbp-10H], rcx
       488B31               mov      rsi, gword ptr [rcx]
       488BCE               mov      rcx, rsi
       48BA00AAD141F97F0000 mov      rdx, 0x7FF941D1AA00      ; IRuntime
       488955E8             mov      qword ptr [rbp-18H], rdx
       49B808B7D141F97F0000 mov      r8, 0x7FF941D1B708      ; token handle
       E87A6D525F           call     CORINFO_HELP_VIRTUAL_FUNC_PTR
       488BCE               mov      rcx, rsi
       33D2                 xor      edx, edx
       FFD0                 call     rax
       90                   nop      
						;; size=110 bbWeight=1 PerfScore 32.50
G_M16055_IG12:              ;; offset=015EH
       4883C428             add      rsp, 40
       5E                   pop      rsi
       5D                   pop      rbp
       C3                   ret      
						;; size=7 bbWeight=1 PerfScore 2.25
G_M16055_IG13:              ;; offset=0165H
       E8D695525F           call     CORINFO_HELP_RNGCHKFAIL
       CC                   int3     
						;; size=6 bbWeight=0 PerfScore 0.00

; Total bytes of code 363, prolog size 23, PerfScore 152.05, instruction count 109, allocated bytes for code 363 (MethodHash=953ac148) for method Program:M50(byte,long[],byte,byref)
; ============================================================

False
0
4294967040

There seem to be a missing normalize-on-load for arg0.

Activity

  1. ghost added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on May 2, 2023
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on May 2, 2023
  3. added this to the 8.0.0 milestone on May 3, 2023
  4. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on May 3, 2023
  5. jakobbotsch commented on Jul 6, 2023

    @jakobbotsch
    MemberAuthor

    This program no longer exposes the problem after #86491

  6. ghost locked as resolved and limited conversation to collaborators on Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:3Work that is nice to havearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions