Skip to content

RyuJIT sometimes drops volatile reads #10619

Open
@mikedn

Description

@mikedn

Morph issue:

static volatile int x;

[MethodImpl(MethodImplOptions.NoInlining)]
static int Test(int a) => x & 0;

generates

G_M55886_IG01:
G_M55886_IG02:
       33C0                 xor      eax, eax
G_M55886_IG03:
       C3                   ret

Similar issue but involving VN/assertion propagation:

static int Test(int a)
{
    int k = a > 42 ? 0 : 0;
    return x & k;
}

generates the same code as above.
In this case VN assigned x & k the VN of constant 0 and then assertion propagation drops the x load because it only considers persistent side effects.

Found while working on dotnet/coreclr#18257. Initially I thought that we can simple make assertion propagation use GTF_ALL_EFFECT only to discover that it doesn't work because gtNodeHasSideEffects doesn't pay attention to side effects other than GTF_SIDE_EFFECT. So who's paying attention to GTF_ORDER_SIDEEFF and GTF_GLOB_REF?!

category:correctness
theme:volatile
skill-level:expert
cost:large

Metadata

Metadata

Assignees

No one assigned

    Labels

    JitUntriagedCLR JIT issues needing additional triagearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbughard-problemmemory modelissues associated with memory model

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions