Skip to content

JIT: volatile compares should not be foldable #10268

Open
@AndyAyersMS

Description

@AndyAyersMS
using System;

class X
{
    volatile int a;
    
    public static int Main()
    {
        var x = new X();
        x.a = 50;
        x.a = 100;
        if (x.a == x.a) return 100;
        return -1;
    }
}

currently generates:

G_M32182_IG01:
       4883EC28             sub      rsp, 40

G_M32182_IG02:
       48B95852BB61F97F0000 mov      rcx, 0x7FF961BB5258
       E85DFA7F5F           call     CORINFO_HELP_NEWSFAST
       C7400832000000       mov      dword ptr [rax+8], 50
       C7400864000000       mov      dword ptr [rax+8], 100
       B864000000           mov      eax, 100

G_M32182_IG03:
       4883C428             add      rsp, 40
       C3                   ret

Folding the compare is unsafe in general.

See also the somewhat related #6280.

category:correctness
theme:basic-cq
skill-level:intermediate
cost:small

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions