<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Common code between acquire-release not sunk"
   href="https://bugs.llvm.org/show_bug.cgi?id=47215">47215</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Common code between acquire-release not sunk
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>hiraditya@msn.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ cat test.cpp
```
struct foo {
    [[gnu::weak]] foo() noexcept;
    [[gnu::weak]] ~foo();
    foo* begin() { return this; }
    foo* end() { return this; }
};

__attribute__((noinline))
void bar(foo* i, foo* j) {}

foo* go_leaky() { static foo *f = new foo(); return f; }

int main() {
    bar(go_leaky()->begin(), go_leaky()->end());
    return 0;
}
```

Interesting disassembly code: with clang++ -O3 -std=c++17 -fno-exceptions

```
main:
 push   rbx
 mov    al,BYTE PTR [rip+0x2e81]        # 404058 <guard variable for
go_leaky()::f>
 test   al,al
 je     4011e9 <main+0x19>
 mov    al,BYTE PTR [rip+0x2e77]        # 404058 <guard variable for
go_leaky()::f>
 test   al,al
 je     40121f <main+0x4f>
 xor    eax,eax
 pop    rbx
 ret    
 mov    edi,0x404058
 call   401060 <__cxa_guard_acquire@plt> /// < -------start of acquire-release
 test   eax,eax
 je     4011db <main+0xb>
 mov    edi,0x1
 call   401050 <operator new(unsigned long)@plt>
 mov    rbx,rax
 mov    rdi,rax
 call   401030 <foo::foo()@plt>
 mov    QWORD PTR [rip+0x2e3d],rbx        # 404050 <go_leaky()::f>
 mov    edi,0x404058
 call   401040 <__cxa_guard_release@plt> /// < -------end of acquire-release
 jmp    4011db <main+0xb>
 mov    edi,0x404058
 call   401060 <__cxa_guard_acquire@plt> /// < -------start of acquire-release
 test   eax,eax
 je     4011e5 <main+0x15>
 mov    edi,0x1
 call   401050 <operator new(unsigned long)@plt>
 mov    rbx,rax
 mov    rdi,rax
 call   401030 <foo::foo()@plt>
 mov    QWORD PTR [rip+0x2e07],rbx        # 404050 <go_leaky()::f>
 mov    edi,0x404058
 call   401040 <__cxa_guard_release@plt> /// < -------end of acquire-release
 xor    eax,eax
 pop    rbx
 ret    
 nop    WORD PTR [rax+rax*1+0x0]```

The compiler should be able to fold/sink the common code to a common successor.
Even -gvn-sink didn't seem to help.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>