<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 - store of pointer to object into itself treated as escape by GVN"
   href="https://bugs.llvm.org/show_bug.cgi?id=37263">37263</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>store of pointer to object into itself treated as escape by GVN
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Testcase, in C++ (using libstdc++):

#include <string>
void f();
void g() {
  std::string s = "foo";
  f();
}

We should be able to completely eliminate the local 's' variable here. But we
can't, because we believe that f() might have modified it. The reason is that
(in libstdc++, when the small-string optimization is engaged) s contains a
pointer to itself.

Similar example, reduced to eliminate stdlib dependency:

void f();
void g() {
    void *p = &p;
    f();
    if (p != &p) f();
}

IR:

define dso_local void @_Z1gv() {
entry:
  %p = alloca i8*, align 8
  %0 = bitcast i8** %p to i8*
  store i8* %0, i8** %p, align 8
  call void @_Z1fv()
  %1 = load i8*, i8** %p, align 8
  %2 = bitcast i8** %p to i8*
  %cmp = icmp ne i8* %1, %2
  br i1 %cmp, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  call void @_Z1fv()
  br label %if.end

if.end:                                           ; preds = %if.then, %entry
  ret void
}

declare dso_local void @_Z1fv()


We should be able to optimize this to just:

  call void @_Z1fv()
  ret void</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>