<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><blockquote type="cite"><div>On Jul 7, 2014, at 10:28 PM, Benjamin Kramer <<a href="mailto:benny.kra@gmail.com">benny.kra@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">On 07.07.2014, at 20:20, Pete Cooper <</span><a href="mailto:pete.cooper@gmail.com" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">pete.cooper@gmail.com</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">> wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Hey Ben<br><br>This is crashing our test suite.  Mind taking a look?  This may be related to what Richard has just pointed out too.<br></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">I think this is something different. Feel free to revert if this is blocking you in the meantime.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></div></blockquote>Thanks Ben.  I’m able to repro the crash for the attached file, and have it pass, just by reverting.</div><div><br></div><div>Going to do that now.</div><div><br></div><div>Thanks,</div><div>Pete<br><blockquote type="cite"><div><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">- Ben</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br>Attached a reduced test which crashes the following "opt dce.ll -globaldce -o file.bc”<br><br>Cheers,<br>Pete<br><br><br><br><br>On Fri, Jul 4, 2014 at 1:36 PM, Benjamin Kramer <<a href="mailto:benny.kra@googlemail.com">benny.kra@googlemail.com</a>> wrote:<br>Author: d0k<br>Date: Fri Jul  4 07:36:05 2014<br>New Revision: 212337<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=212337&view=rev">http://llvm.org/viewvc/llvm-project?rev=212337&view=rev</a><br>Log:<br>GlobalDCE: Delete available_externally initializers if it allows removing the value the initializer is referring to.<br><br>This is useful for functions that are not actually available externally but<br>referenced by a vtable of some kind. Clang emits functions like this for the MS<br>ABI.<br><br>PR20182.<br><br>Modified:<br>   llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp<br>   llvm/trunk/test/Transforms/GlobalDCE/externally_available.ll<br><br>Modified: llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp?rev=212337&r1=212336&r2=212337&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp?rev=212337&r1=212336&r2=212337&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp (original)<br>+++ llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp Fri Jul  4 07:36:05 2014<br>@@ -44,14 +44,19 @@ namespace {<br>    bool runOnModule(Module &M) override;<br><br>  private:<br>-    SmallPtrSet<GlobalValue*, 32> AliveGlobals;<br>+    SmallPtrSet<Constant *, 32> AliveGlobals;<br>    SmallPtrSet<Constant *, 8> SeenConstants;<br>+    SmallPtrSet<GlobalVariable *, 8> DiscardableGlobalInitializers;<br><br>    /// GlobalIsNeeded - mark the specific global value as needed, and<br>    /// recursively mark anything that it uses as also needed.<br>    void GlobalIsNeeded(GlobalValue *GV);<br>    void MarkUsedGlobalsAsNeeded(Constant *C);<br><br>+    /// \brief Checks if C is alive or is a ConstantExpr that refers to an alive<br>+    /// value.<br>+    bool ContainsUsedGlobal(Constant *C);<br>+<br>    bool RemoveUnusedGlobalValue(GlobalValue &GV);<br>  };<br>}<br>@@ -162,6 +167,19 @@ bool GlobalDCE::runOnModule(Module &M) {<br>      I->setAliasee(nullptr);<br>    }<br><br>+  // Look for available externally constants that we can turn into normal<br>+  // externals by deleting their initalizers. This allows us to remove other<br>+  // globals that are referenced by the initializer.<br>+  if (!DiscardableGlobalInitializers.empty()) {<br>+    for (GlobalVariable *GV : DiscardableGlobalInitializers) {<br>+      if (!ContainsUsedGlobal(GV->getInitializer())) {<br>+        GV->setInitializer(nullptr);<br>+        GV->setLinkage(GlobalValue::ExternalLinkage);<br>+        Changed = true;<br>+      }<br>+    }<br>+  }<br>+<br>  if (!DeadFunctions.empty()) {<br>    // Now that all interferences have been dropped, delete the actual objects<br>    // themselves.<br>@@ -209,8 +227,12 @@ void GlobalDCE::GlobalIsNeeded(GlobalVal<br>  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(G)) {<br>    // If this is a global variable, we must make sure to add any global values<br>    // referenced by the initializer to the alive set.<br>-    if (GV->hasInitializer())<br>-      MarkUsedGlobalsAsNeeded(GV->getInitializer());<br>+    if (GV->hasInitializer()) {<br>+      if (GV->hasAvailableExternallyLinkage())<br>+        DiscardableGlobalInitializers.insert(GV);<br>+      else<br>+        MarkUsedGlobalsAsNeeded(GV->getInitializer());<br>+    }<br>  } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(G)) {<br>    // The target of a global alias is needed.<br>    MarkUsedGlobalsAsNeeded(GA->getAliasee());<br>@@ -248,6 +270,21 @@ void GlobalDCE::MarkUsedGlobalsAsNeeded(<br>  }<br>}<br><br>+bool GlobalDCE::ContainsUsedGlobal(Constant *C) {<br>+  // C contains a used global If C is alive or we visited it while marking<br>+  // values alive.<br>+  if (AliveGlobals.count(C) || SeenConstants.count(C))<br>+    return true;<br>+<br>+  // Now check all operands of a ConstantExpr.<br>+  for (User::op_iterator I = C->op_begin(), E = C->op_end(); I != E; ++I) {<br>+    Constant *Op = dyn_cast<Constant>(*I);<br>+    if (Op && ContainsUsedGlobal(Op))<br>+      return true;<br>+  }<br>+  return false;<br>+}<br>+<br>// RemoveUnusedGlobalValue - Loop over all of the uses of the specified<br>// GlobalValue, looking for the constant pointer ref that may be pointing to it.<br>// If found, check to see if the constant pointer ref is safe to destroy, and if<br><br>Modified: llvm/trunk/test/Transforms/GlobalDCE/externally_available.ll<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalDCE/externally_available.ll?rev=212337&r1=212336&r2=212337&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalDCE/externally_available.ll?rev=212337&r1=212336&r2=212337&view=diff</a><br>==============================================================================<br>--- llvm/trunk/test/Transforms/GlobalDCE/externally_available.ll (original)<br>+++ llvm/trunk/test/Transforms/GlobalDCE/externally_available.ll Fri Jul  4 07:36:05 2014<br>@@ -1,10 +1,43 @@<br>-; RUN: opt < %s -globaldce -S | not grep test_<br>+; RUN: opt < %s -globaldce -S | FileCheck %s<br><br>; test_function should not be emitted to the .s file.<br>+; CHECK-NOT: @test_function<br>define available_externally i32 @test_function() {<br>  ret i32 4<br>}<br><br>; test_global should not be emitted to the .s file.<br>+; CHECK-NOT: @test_global<br>@test_global = available_externally global i32 4<br><br>+; CHECK: @x = external constant void ()*<br>+@x = available_externally constant void()* @f<br>+; CHECK: @y = external constant i32<br>+@y = available_externally constant i32 ptrtoint (void()* @g to i32)<br>+; @h is still alive, so don't remove the initializer too eagerly.<br>+; CHECK: @z = available_externally constant i8 ptrtoint (void (i8)* @h to i8)<br>+@z = available_externally constant i8 ptrtoint (void(i8)* @h to i8)<br>+<br>+; CHECK-NOT: @f<br>+define linkonce_odr void @f() {<br>+  ret void<br>+}<br>+<br>+; CHECK-NOT: @g<br>+define linkonce_odr void @g() {<br>+  ret void<br>+}<br>+<br>+; CHECK: define linkonce_odr void @h<br>+define linkonce_odr void @h(i8) {<br>+  ret void<br>+}<br>+<br>+define i32 @main() {<br>+  %f = load void()** @x<br>+  call void %f()<br>+  %g = load i32* @y<br>+  %h = load i8* @z<br>+  call void @h(i8 %h)<br>+  ret i32 %g<br>+}<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br><br><dce.ll><br></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">llvm-commits mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><a href="mailto:llvm-commits@cs.uiuc.edu" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">llvm-commits@cs.uiuc.edu</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></blockquote></div><br></body></html>