[llvm-bugs] [Bug 42333] New: New Pass Manager unable to statically determine the return value of some functions

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 19 12:09:21 PDT 2019


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

            Bug ID: 42333
           Summary: New Pass Manager unable to statically determine the
                    return value of some functions
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: leonardchan at google.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

Found when enabling the new pass manager by default and running test:
`clang/test/CodeGenCXX/conditional-temporaries.cpp`

The test fails under the new PM because it is unable to optimize some return
values statically as the legacy PM does. For example:

```
static int ctorcalls;
static int dtorcalls;

struct A {
  A() : i(0) { ctorcalls++; }
  ~A() { dtorcalls++; }
  int i;

  friend const A& operator<<(const A& a, int n) {
    return a;
  }
};

void g(int) { }
void g(const A&) { }

void f1(bool b) {
  g(b ? A().i : 0);
  g(b || A().i);
  g(b && A().i);
  g(b ? A() << 1 : A() << 2);
}

struct Checker {
  Checker() {
    f1(true);
    f1(false);
  }
};

Checker c;

}

// CHECK-OPT-LABEL: define i32 @_Z12getCtorCallsv()
int getCtorCalls() {
  // CHECK-OPT: ret i32 5
  return ctorcalls;
}
```

Invoking `%clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2` is
meant to optimize it as a return of 5, but the new PM instead generates:

```
[[RET:%.*]] = load i32, i32* addrspacecast (i32 addrspace(1)*
@_ZN12_GLOBAL__N_19ctorcallsE to i32*), align 4
ret i32 [[RET]]
```

We can see something similar in
`clang/test/CodeGenCXX/member-function-pointer-calls.cpp` where calls to member
functions are not optimized out under new PM.

-- 
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/20190619/f566a191/attachment.html>


More information about the llvm-bugs mailing list