Skip to content

JIT should be able to elide zeroing of fields after allocations #96942

Open

Description

@jakobbotsch
using System;

class Program
{
    static void Main()
    {
        Program p = new();
        p.Test = false;
    }

    public bool Test;
}

Codegen:

       call     CORINFO_HELP_NEWSFAST
       mov      byte  ptr [rax+0x08], 0

Expected:

       call     CORINFO_HELP_NEWSFAST

I looked at representing this in VN once, but it seemed hard with how we represent memory in VN.

Activity

  1. ghost added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Jan 13, 2024
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jan 13, 2024
  3. removed
    untriagedNew issue has not been triaged by the area owner
    on Jan 13, 2024
  4. self-assigned this
    on Jan 13, 2024
  5. added this to the 9.0.0 milestone on Jan 13, 2024
  6. EgorBo commented on Jan 13, 2024

    @EgorBo
    Member

    ... and remove the allocation after it 🙂

  7. modified the milestones: 9.0.0, 10.0.0 on Aug 1, 2024
  8. jakobbotsch commented on May 28, 2025

    @jakobbotsch
    MemberAuthor

    I am not totally convinced this is a good idea anymore since removing explicit stores can break store-to-load forwarding done by the CPU, which comes with a large penalty. I will move this to future as something to potentially investigate.

  9. modified the milestones: 10.0.0, Future on May 28, 2025
  10. EgorBo commented on May 28, 2025

    @EgorBo
    Member

    ... and remove the allocation after it 🙂

    It's cool that your initial snippet is now optimized to just no-op with help of EA 🙂 I know it's not what the issue is about, but still..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions