Hi,<br><br>I don't fully agree with this. It is only applicable in C or C++ non-freestanding modes. We shouldn't break other front ends or languages that happen to use the symbol 'main'.<br><br>Chandler has suggested a 'entry point' or 'noreentry' attribute to be a corollary to norecurse. Perhaps that might help here?<br><br>As is, I don't think we can do this. <br><br>James<br><div class="gmail_quote"><div dir="ltr">On Fri, 25 Dec 2015 at 14:54, Vaivaswatha Nagaraj via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-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">vaivaswatha created this revision.<br>
vaivaswatha added reviewers: jmolloy, hfinkel.<br>
vaivaswatha added a subscriber: llvm-commits.<br>
<br>
This change relaxes the condition for a global, that is only used in "main", to be localized. This relaxation partially undoes the change done in <a href="http://reviews.llvm.org/rL253168" rel="noreferrer" target="_blank">http://reviews.llvm.org/rL253168</a>.<br>
<br>
This is required because the condition that was added earlier, that a store to the global needs to dominate all other references to it in the function is not necessary if the only function that accesses the global is "main". So, similar to the condition prior to the above mentioned change, this change allows "main" as an exception.<br>
<br>
<a href="http://reviews.llvm.org/D15777" rel="noreferrer" target="_blank">http://reviews.llvm.org/D15777</a><br>
<br>
Files:<br>
  lib/Transforms/IPO/GlobalOpt.cpp<br>
  test/Transforms/GlobalOpt/load-store-global.ll<br>
<br>
Index: test/Transforms/GlobalOpt/load-store-global.ll<br>
===================================================================<br>
--- test/Transforms/GlobalOpt/load-store-global.ll<br>
+++ test/Transforms/GlobalOpt/load-store-global.ll<br>
@@ -36,3 +36,16 @@<br>
 ; CHECK-NOT: load<br>
 }<br>
<br>
+; A global used only in "main" can always be localized.<br>
+@b = internal global i64 13, align 8<br>
+; CHECK-NOT: @b<br>
+<br>
+define i64 @main(i32 %argc, i8** %argv) norecurse {<br>
+; CHECK: %b = alloca<br>
+; CHECK store i64 13<br>
+  %a = load i64, i64* @b<br>
+; CHECK %a = load i64<br>
+  store i64 27, i64* @b<br>
+; CHECK store i64 27<br>
+  ret i64 %a<br>
+}<br>
Index: lib/Transforms/IPO/GlobalOpt.cpp<br>
===================================================================<br>
--- lib/Transforms/IPO/GlobalOpt.cpp<br>
+++ lib/Transforms/IPO/GlobalOpt.cpp<br>
@@ -1883,8 +1883,9 @@<br>
       GV->getType()->getAddressSpace() == 0 &&<br>
       !GV->isExternallyInitialized() &&<br>
       allNonInstructionUsersCanBeMadeInstructions(GV) &&<br>
-      GS.AccessingFunction->doesNotRecurse() &&<br>
-      isPointerValueDeadOnEntryToFunction(GS.AccessingFunction, GV) ) {<br>
+      ((GS.AccessingFunction->doesNotRecurse() &&<br>
+        isPointerValueDeadOnEntryToFunction(GS.AccessingFunction, GV)) ||<br>
+       (GS.AccessingFunction->getName() == "main"))) {<br>
     DEBUG(dbgs() << "LOCALIZING GLOBAL: " << *GV << "\n");<br>
     Instruction &FirstI = const_cast<Instruction&>(*GS.AccessingFunction<br>
                                                    ->getEntryBlock().begin());<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>