Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

New Pass Manager unable to statically determine the return value of some functions #41303

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR42333
Status NEW
Importance P normal
Reported by Leonard Chan (leonardchan@google.com)
Reported on 2019-06-19 12:09:21 -0700
Last modified on 2020-01-11 12:54:40 -0800
Version trunk
Hardware PC Linux
CC ehudkatz@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

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.

Quuxplusone commented 4 years ago
I tried to reproduce it by running clang with "-fexperimental-new-pass-manager -
O2", and it does produce the desired result.
Am I doing something wrong?