[llvm-bugs] [Bug 37263] New: store of pointer to object into itself treated as escape by GVN

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 26 17:37:49 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37263

            Bug ID: 37263
           Summary: store of pointer to object into itself treated as
                    escape by GVN
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: llvm-bugs at lists.llvm.org

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180427/c88ef39c/attachment.html>


More information about the llvm-bugs mailing list