<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Jul 19, 2018 at 7:10 AM Pavel Labath via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: labath<br>
Date: Thu Jul 19 07:05:22 2018<br>
New Revision: 337456<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=337456&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=337456&view=rev</a><br>
Log:<br>
[CodeGen] Disable aggressive structor optimizations at -O0, take 3<br></blockquote><div><br></div><div>I'm really sorry to do this, but I need to revert this patch.... Let me try to explain....</div><div><br></div><div>We're seeing at least two issues with it that are causing *serious* issues for our users, and due to numerous other things, we really need to get top-of-tree into usable shape sooner rather than later. As this is improving a long-standing deficiency in Clang, I think it is reasonable to revert temporarily while we sort it out. I'm CC-ing Richard Smith and Eric Christopher directly as I'm going to ask them to make sure we get satisfactory answers to why this patch causes us so many problems and how we can make progress here.</div><div><br></div><div>I don't have a test case at the moment, and I want to *very clearly* call out that it is on us to find a test case or otherwise clearly explain what problem this patch causes and how it can be addressed, or else this patch should be re-landed.</div><div><br></div><div>To at least give some idea of what is going wrong here......</div><div><br></div><div>First, this patch does increase object code size. This isn't really unexpected based on the nature of the patch, and it does so ostensibly in order to gain material fidelity improvements to debug information. Despite the fact that the increased object size causes us problems (it made a few hundered of our binaries' inputs too large to fit into the quota for the input files to our internal distributed build system) we tried to soldier onward...</div><div><br></div><div>But it also causes the Gold linker at least to use considerably more memory than it used to. This has resulted in over 400 failures to link executables due to running out of available memory on the system.</div><div><br></div><div>There are a number of possible causes for both the input size issues and the linker memory issue:</div><div>- An unexpected side-effect of this change causes lots of redundant sections to be output with -ffunction-sections, all of which merge away into nothing, but this takes huge amounts of object file and linker resources.</div><div>- The object file size increease is expected and unavoidable, but there is some bug in the linker being triggered?</div><div>- Something else</div><div><br></div><div>It is going to take us some time to investigate these issues, and sadly, all of these issues are breaking builds actively for us.</div><div><br></div><div>So while we will work very hard on getting to a resolution, if you also really need this functionality to land sooner rather than later, what I would request is to add it back under a flag. In fact, if you need that and request it, we can do the actual work of adding it back under a flag. I think that's the least we can do here.</div><div><br></div><div>Anyways, again, sorry to revert with relatively little warning and with relatively little info.</div><div><br></div><div>Feel free to reach out to myself or Richard Smith, or Eric Christopher who will all be looking at this first thing next week to understand exactly what is going on here and what the root causes is and whether any of these issues are due to bugs in some tool or another, or whether these are all due to some particular issue with our source code.</div><div><br></div><div>-Chandler</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
The previous version of this patch (r332839) was reverted because it was<br>
causing "definition with same mangled name as another definition" errors<br>
in some module builds. This was caused by an unrelated bug in module<br>
importing which it exposed. The importing problem was fixed in r336240,<br>
so this recommits the original patch (r332839).<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D46685" rel="noreferrer" target="_blank">https://reviews.llvm.org/D46685</a><br>
<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp<br>
    cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp<br>
    cfe/trunk/test/CodeGenCXX/float16-declarations.cpp<br>
<br>
Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=337456&r1=337455&r2=337456&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=337456&r1=337455&r2=337456&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Thu Jul 19 07:05:22 2018<br>
@@ -3737,12 +3737,22 @@ static StructorCodegen getCodegenToUse(C<br>
   }<br>
   llvm::GlobalValue::LinkageTypes Linkage = CGM.getFunctionLinkage(AliasDecl);<br>
<br>
-  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage))<br>
-    return StructorCodegen::RAUW;<br>
+  // All discardable structors can be RAUWed, but we don't want to do that in<br>
+  // unoptimized code, as that makes complete structor symbol disappear<br>
+  // completely, which degrades debugging experience.<br>
+  // Symbols with private linkage can be safely aliased, so we special case them<br>
+  // here.<br>
+  if (llvm::GlobalValue::isLocalLinkage(Linkage))<br>
+    return CGM.getCodeGenOpts().OptimizationLevel > 0 ? StructorCodegen::RAUW<br>
+                                                      : StructorCodegen::Alias;<br>
<br>
+  // Linkonce structors cannot be aliased nor placed in a comdat, so these need<br>
+  // to be emitted separately.<br>
   // FIXME: Should we allow available_externally aliases?<br>
-  if (!llvm::GlobalAlias::isValidLinkage(Linkage))<br>
-    return StructorCodegen::RAUW;<br>
+  if (llvm::GlobalValue::isDiscardableIfUnused(Linkage) ||<br>
+      !llvm::GlobalAlias::isValidLinkage(Linkage))<br>
+    return CGM.getCodeGenOpts().OptimizationLevel > 0 ? StructorCodegen::RAUW<br>
+                                                      : StructorCodegen::Emit;<br>
<br>
   if (llvm::GlobalValue::isWeakForLinker(Linkage)) {<br>
     // Only ELF and wasm support COMDATs with arbitrary names (C5/D5).<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp?rev=337456&r1=337455&r2=337456&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp?rev=337456&r1=337455&r2=337456&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp Thu Jul 19 07:05:22 2018<br>
@@ -1,5 +1,7 @@<br>
-// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases | FileCheck --check-prefix=NOOPT %s<br>
-<br>
+// RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases > %t<br>
+// RUN: FileCheck --check-prefix=NOOPT1 --input-file=%t %s<br>
+// RUN: FileCheck --check-prefix=NOOPT2 --input-file=%t %s<br>
+// RUN: FileCheck --check-prefix=NOOPT3 --input-file=%t %s<br>
 // RUN: %clang_cc1 %s -triple i686-linux -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-passes > %t<br>
 // RUN: FileCheck --check-prefix=CHECK1 --input-file=%t %s<br>
 // RUN: FileCheck --check-prefix=CHECK2 --input-file=%t %s<br>
@@ -21,6 +23,13 @@ namespace test1 {<br>
 // CHECK1: define weak_odr void @_ZN5test16foobarIvED0Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev)<br>
 // CHECK1-NOT: comdat<br>
<br>
+// This should happen regardless of the opt level.<br>
+// NOOPT1: @_ZN5test16foobarIvEC1Ev = weak_odr unnamed_addr alias void {{.*}} @_ZN5test16foobarIvEC2Ev<br>
+// NOOPT1: @_ZN5test16foobarIvED1Ev = weak_odr unnamed_addr alias void (%"struct.test1::foobar"*), void (%"struct.test1::foobar"*)* @_ZN5test16foobarIvED2Ev<br>
+// NOOPT1: define weak_odr void @_ZN5test16foobarIvEC2Ev({{.*}} comdat($_ZN5test16foobarIvEC5Ev)<br>
+// NOOPT1: define weak_odr void @_ZN5test16foobarIvED2Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev)<br>
+// NOOPT1: define weak_odr void @_ZN5test16foobarIvED0Ev({{.*}} comdat($_ZN5test16foobarIvED5Ev)<br>
+<br>
 // COFF doesn't support comdats with arbitrary names (C5/D5).<br>
 // COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvEC2Ev({{.*}} comdat align<br>
 // COFF: define weak_odr {{.*}} void @_ZN5test16foobarIvEC1Ev({{.*}} comdat align<br>
@@ -37,12 +46,17 @@ template struct foobar<void>;<br>
 }<br>
<br>
 namespace test2 {<br>
-// test that when the destrucor is linkonce_odr we just replace every use of<br>
+// test that when the destructor is linkonce_odr we just replace every use of<br>
 // C1 with C2.<br>
<br>
 // CHECK1: define internal void @__cxx_global_var_init()<br>
 // CHECK1: call void @_ZN5test26foobarIvEC2Ev<br>
 // CHECK1: define linkonce_odr void @_ZN5test26foobarIvEC2Ev({{.*}} comdat align<br>
+<br>
+// At -O0, we should still emit the complete constructor.<br>
+// NOOPT1: define internal void @__cxx_global_var_init()<br>
+// NOOPT1: call void @_ZN5test26foobarIvEC1Ev<br>
+// NOOPT1: define linkonce_odr void @_ZN5test26foobarIvEC1Ev({{.*}} comdat align<br>
 void g();<br>
 template <typename T> struct foobar {<br>
   foobar() { g(); }<br>
@@ -57,6 +71,11 @@ namespace test3 {<br>
 // CHECK1: define internal void @__cxx_global_var_init.1()<br>
 // CHECK1: call i32 @__cxa_atexit{{.*}}_ZN5test312_GLOBAL__N_11AD2Ev<br>
 // CHECK1: define internal void @_ZN5test312_GLOBAL__N_11AD2Ev(<br>
+<br>
+// We can use an alias for internal symbols at -O0.<br>
+// NOOPT2: _ZN5test312_GLOBAL__N_11BD1Ev = internal unnamed_addr alias void {{.*}} @_ZN5test312_GLOBAL__N_11BD2Ev<br>
+// NOOPT2: define internal void @__cxx_global_var_init.1()<br>
+// NOOPT2: call i32 @__cxa_atexit{{.*}}_ZN5test312_GLOBAL__N_11BD1Ev<br>
 namespace {<br>
 struct A {<br>
   ~A() {}<br>
@@ -77,11 +96,12 @@ namespace test4 {<br>
   // CHECK1: call i32 @__cxa_atexit{{.*}}_ZN5test41AD2Ev<br>
   // CHECK1: define linkonce_odr void @_ZN5test41AD2Ev({{.*}} comdat align<br>
<br>
-  // test that we don't do this optimization at -O0 so that the debugger can<br>
-  // see both destructors.<br>
-  // NOOPT: define internal void @__cxx_global_var_init.2()<br>
-  // NOOPT: call i32 @__cxa_atexit{{.*}}@_ZN5test41BD2Ev<br>
-  // NOOPT: define linkonce_odr void @_ZN5test41BD2Ev({{.*}} comdat align<br>
+  // Test that we don't do this optimization at -O0 and call the complete<br>
+  // destructor for B instead. This enables the debugger to see both<br>
+  // destructors.<br>
+  // NOOPT2: define internal void @__cxx_global_var_init.2()<br>
+  // NOOPT2: call i32 @__cxa_atexit{{.*}}@_ZN5test41BD1Ev<br>
+  // NOOPT2: define linkonce_odr void @_ZN5test41BD1Ev({{.*}} comdat align<br>
   struct A {<br>
     virtual ~A() {}<br>
   };<br>
@@ -129,6 +149,11 @@ namespace test7 {<br>
   // out if we should).<br>
   // pr17875.<br>
   // CHECK3: define void @_ZN5test71BD2Ev<br>
+<br>
+  // At -O0, we should emit both destructors, the complete can be an alias to<br>
+  // the base one.<br>
+  // NOOPT3: @_ZN5test71BD1Ev = unnamed_addr alias void {{.*}} @_ZN5test71BD2Ev<br>
+  // NOOPT3: define void @_ZN5test71BD2Ev<br>
   template <typename> struct A {<br>
     ~A() {}<br>
   };<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/float16-declarations.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/float16-declarations.cpp?rev=337456&r1=337455&r2=337456&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/float16-declarations.cpp?rev=337456&r1=337455&r2=337456&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/float16-declarations.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/float16-declarations.cpp Thu Jul 19 07:05:22 2018<br>
@@ -103,7 +103,7 @@ int main(void) {<br>
<br>
   C1 c1(f1l);<br>
 // CHECK-DAG:  [[F1L:%[a-z0-9]+]] = load half, half* %{{.*}}, align 2<br>
-// CHECK-DAG:  call void @_ZN2C1C2EDF16_(%class.C1* %{{.*}}, half %{{.*}})<br>
+// CHECK-DAG:  call void @_ZN2C1C1EDF16_(%class.C1* %{{.*}}, half %{{.*}})<br>
<br>
   S1<_Float16> s1 = { 132.f16 };<br>
 // CHECK-DAG: @_ZZ4mainE2s1 = private unnamed_addr constant %struct.S1 { half 0xH5820 }, align 2<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div>