<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59076>59076</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            GVN hoists `sync` call over side-effect if `memory` attribute doesn't contain side-effect location
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            nikic
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jdoerfert
      </td>
    </tr>
</table>

<pre>
    [I think I reported this before, or something similar. Since I couldn't find it, here we go:]

As part of https://reviews.llvm.org/D137937 I realized (again) that a load can be hoisted over a sync barrier annotated with `inaccesiblemem`. 
he funny part is that the test comment states this should only happen if the function is `nosync`, anyway.
The old wisdom for these cases is that any sync function should have a read-write memory effect on all memory it can "synchronize over", however, that is not really what we want in the long run.
I hope we can move to a sync/`nosync` aware world soon and close this with a proper solution.

Repro (https://godbolt.org/z/aKhr54bEo), `opt -aa-pipeline=basic-aa,globals-aa -passes='require<globals-aa>,gvn' `
```
@G2 = internal global i32 undef

define void @test_unknown(i1 %c) {
  br i1 %c, label %init, label %check
init:
  store i32 0, ptr @G2
  br label %check
check:
  call void @unknown() memory(inaccessiblemem: readwrite)
  %v = load i32, ptr @G2
  %cmp = icmp eq i32 %v, 0
  call void @llvm.assume(i1 %cmp)
  ret void
}

declare void @unknown()
declare void @llvm.assume(i1 noundef)
```

@nikic @fhahn @jayfoad @nhaehnle 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxtVU1v4zgM_TXOhUjgjziODz5k2plBscAedhd7Xcg2HauVJY8kx8j8-iVlJ01nCriN9UHy8fGRrk17raL8ywv4Xuo3eAGLo7EeW95wUGNnLEbpExgLzgzI187g5CCVsDv4W-oGyaoxk2p1lBYeOqlbkJ5terQIM8LZRNkpyp-jmJ7T8v_kYBTWg-mg9350fCP9Ro_Fi8TZ7ZS6DDtjz7T1nGRFmRUBn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