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

JIT: volatile compares should not be foldable #10268

Open
AndyAyersMS opened this issue Apr 30, 2018 · 2 comments
Open

JIT: volatile compares should not be foldable #10268

AndyAyersMS opened this issue Apr 30, 2018 · 2 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI bug JitUntriaged CLR JIT issues needing additional triage memory model issues associated with memory model
Milestone

Comments

@AndyAyersMS
Copy link
Member

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

@mikedn
Copy link
Contributor

mikedn commented May 3, 2018

Apparently this is due to Compiler::gtFoldExprCompare and/or GenTree::Compare. The later returns true for those 2 indirs and then the relop gets folded:
https://github.com/dotnet/coreclr/blob/0a842c03c1d60a5c57b7c60d09a657e6a66e4c95/src/jit/gentree.cpp#L12814-12820

Not clear what exactly is wrong:

  • Should Compare check GTF_IND_VOLATILE?
  • Should gtFoldExprCompare check GTF_ORDER_SIDEEFF?
  • Something else...

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@BruceForstall BruceForstall added the JitUntriaged CLR JIT issues needing additional triage label Oct 28, 2020
@VSadov VSadov self-assigned this Sep 5, 2022
@VSadov VSadov added the memory model issues associated with memory model label Sep 7, 2022
@VSadov
Copy link
Member

VSadov commented Dec 27, 2022

Is this the same issue as in #10619 ?

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 JitUntriaged CLR JIT issues needing additional triage memory model issues associated with memory model
Projects
None yet
Development

No branches or pull requests

5 participants