diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2014-05-03 00:41:18 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2014-05-03 00:41:18 +0000 |
commit | d78f92fbb26b388b30192dfa88fd614db35dbbad (patch) | |
tree | 3e07496fe683abf375a92778a2229b38ba7cfd55 /clang/test/CodeGenCXX/nrvo.cpp | |
parent | e39ee215519e6189d56b345e21f2cee2ffeed3ab (diff) | |
download | bcm5719-llvm-d78f92fbb26b388b30192dfa88fd614db35dbbad.tar.gz bcm5719-llvm-d78f92fbb26b388b30192dfa88fd614db35dbbad.zip |
Rewrite NRVO determination. Track NRVO candidates on the parser Scope and apply the NRVO candidate flag to all possible NRVO candidates here, and remove the flags in computeNRVO or upon template instantiation. A variable now has NRVO applied if and only if every return statement in that scope returns that variable. This is nearly optimal.
Performs NRVO roughly 7% more often in a bootstrap build of clang. Patch co-authored by Richard Smith.
llvm-svn: 207890
Diffstat (limited to 'clang/test/CodeGenCXX/nrvo.cpp')
-rw-r--r-- | clang/test/CodeGenCXX/nrvo.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/clang/test/CodeGenCXX/nrvo.cpp b/clang/test/CodeGenCXX/nrvo.cpp index b83dd727e0b..c48709a0aa3 100644 --- a/clang/test/CodeGenCXX/nrvo.cpp +++ b/clang/test/CodeGenCXX/nrvo.cpp @@ -9,6 +9,14 @@ public: ~X(); }; +template<typename T> struct Y { + Y(); + static Y f() { + Y y; + return y; + } +}; + // CHECK-LABEL: define void @_Z5test0v // CHECK-EH-LABEL: define void @_Z5test0v X test0() { @@ -108,12 +116,18 @@ X test2(bool B) { } +// CHECK-LABEL: define void @_Z5test3b X test3(bool B) { - // FIXME: We don't manage to apply NRVO here, although we could. - { + // FIXME: llvm should apply tail here. + // CHECK: call {{.*}} @_ZN1XC1Ev + // CHECK-NOT: call {{.*}} @_ZN1XC1ERKS_ + // CHECK: call {{.*}} @_ZN1XC1Ev + // CHECK: call {{.*}} @_ZN1XC1ERKS_ + if (B) { X y; return y; } + // FIXME: we should NRVO this variable too. X x; return x; } @@ -161,4 +175,29 @@ X test6() { // CHECK-NEXT: ret void } +X test7(bool b) { + if (b) { + X x; + return x; + } + return X(); +} + +X test8(bool b) { + if (b) { + X x; + return x; + } else { + X y; + return y; + } +} + +Y<int> test9() { + Y<int>::f(); +} + +// CHECK-LABEL: define linkonce_odr void @_ZN1YIiE1fEv +// CHECK: tail call {{.*}} @_ZN1YIiEC1Ev + // CHECK-EH: attributes [[NR_NUW]] = { noreturn nounwind } |