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

There needs to be a proper "new, unique" value number for exception sets #63559

Open
SingleAccretion opened this issue Jan 9, 2022 · 7 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI bug
Milestone

Comments

@SingleAccretion
Copy link
Contributor

SingleAccretion commented Jan 9, 2022

Enable the debug checking and full fidelity exception sets for all calls, including user calls. This would entail optimizing the opaque exception to not consume memory by using a custom chunk kind.

category:implementation
theme:value-numbering
skill-level:intermediate
cost:small
impact:small

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jan 9, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@SingleAccretion SingleAccretion self-assigned this Jan 9, 2022
@SingleAccretion SingleAccretion added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI bug and removed untriaged New issue has not been triaged by the area owner labels Jan 9, 2022
@ghost
Copy link

ghost commented Jan 9, 2022

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

Issue Details

Reproduction, run on 32 bit:

using System.Runtime.CompilerServices;

Problem(0, 1, false, false, 0);

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
static bool Problem(long a, long b, bool c1, bool c2, int i)
{
    var zero = 0;
    c1 = ((a / b) * zero) + i == 0;
    c2 = ((b / a) * zero) + i == 0;

    return c2 & c1;
}

Expected result: DivideByZeroException.
Actual result: program runs successfully.

Cause: in the VN logic, HelperMultiplExc is assigned to helpers that can throw some unknown exception. That is too weak, as HelperMultiplExc is a singleton VNFunc (only ever has one numeric VN assigned to it). We need the equivalent of VNForExpr for exception sets to model "an unknown" exception. Using it we will also be able to model user calls "properly" (propagate the exception sets for them), making the exception sets fully precise.

Creating such exception VNs should be "zero-cost", i. e. consume no actual memory as they do not have useful input to store.

Author: SingleAccretion
Assignees: SingleAccretion
Labels:

bug, area-CodeGen-coreclr

Milestone: -

@SingleAccretion SingleAccretion added this to the 7.0.0 milestone Jan 9, 2022
@SingleAccretion
Copy link
Contributor Author

SingleAccretion commented Jan 11, 2022

It is notable that "just" giving a unique value number to helpers that today receive the HelperMultipleExc VN will not work (or, rather, it will work, but lead to huge regressions). For example, it will make all the "get static base" calls non-CSEable. Yet, today those can be silently dropped, so there is clearly a correctness issue to be solved, as, for example, the below program will not throw an exception, even as it must.

using System;
using System.Runtime.CompilerServices;

Console.WriteLine(Problem(0, false, false));

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
private static bool Problem(int b, bool c1, bool c2)
{
    var zero = 0;
    c1 = ClassWithCctorNoThrow.StaticField * zero + b == 0;
    c2 = c1;

    if (ClassWithCctor.StaticField * zero + b == 0)
    {
        Console.WriteLine("No exception was thrown...");
        return false;
    }

    return c2;
}

static class ClassWithCctor
{
    public static int StaticField;
    static ClassWithCctor() => throw new Exception();
}

static class ClassWithCctorNoThrow
{
    public static int StaticField;
    static ClassWithCctorNoThrow() { }
}

@SingleAccretion
Copy link
Contributor Author

The problem with this issue was that actually creating "new, unique" exception sets for calls lead to very large memory consumption regression; I don't think I'll have time to think of a way out of that for 7.0.

@SingleAccretion SingleAccretion modified the milestones: 7.0.0, 8.0.0 Jun 4, 2022
@SingleAccretion SingleAccretion modified the milestones: 8.0.0, 9.0.0 Jul 12, 2023
jakobbotsch added a commit that referenced this issue Apr 17, 2024
The JIT currently models all exceptions thrown by helpers with a
singleton VN. This can cause CSE to remove exception side effects
incorrectly.

This change starts modelling exceptions thrown by the following helpers
accurately:
- The R2R cast helper
- Division helpers
- Static constructor base helpers

Remaining JIT helpers are modelled conservatively, with an opaque VN in
the exception part.

Contributes to #63559
Fix #101028
@jakobbotsch
Copy link
Member

#101062 fixes the issue around JIT helpers. The problem of modelling exception sets for user calls remain.
@SingleAccretion Do you know of any correctness issues related to user call exception sets here? If not I think we can push this out of 9.0.

@SingleAccretion
Copy link
Contributor Author

Do you know of any correctness issues related to user call exception sets here?

There are none. Yeah, no reason to keep it in 9.0 (the issues here were ancient anyway).

@SingleAccretion SingleAccretion modified the milestones: 9.0.0, Future Apr 17, 2024
@jakobbotsch
Copy link
Member

Sounds good. I'll give this back to you (or feel free to unassign yourself...)

matouskozak pushed a commit to matouskozak/runtime that referenced this issue Apr 30, 2024
The JIT currently models all exceptions thrown by helpers with a
singleton VN. This can cause CSE to remove exception side effects
incorrectly.

This change starts modelling exceptions thrown by the following helpers
accurately:
- The R2R cast helper
- Division helpers
- Static constructor base helpers

Remaining JIT helpers are modelled conservatively, with an opaque VN in
the exception part.

Contributes to dotnet#63559
Fix dotnet#101028
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this issue May 30, 2024
The JIT currently models all exceptions thrown by helpers with a
singleton VN. This can cause CSE to remove exception side effects
incorrectly.

This change starts modelling exceptions thrown by the following helpers
accurately:
- The R2R cast helper
- Division helpers
- Static constructor base helpers

Remaining JIT helpers are modelled conservatively, with an opaque VN in
the exception part.

Contributes to dotnet#63559
Fix dotnet#101028
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI bug
Projects
None yet
Development

No branches or pull requests

2 participants