<div dir="ltr">Many thanks! Fixed in r211879.<div><br></div><div>-- </div><div>David Majnemer</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jun 27, 2014 at 3:12 AM, Pasi Parviainen <span dir="ltr"><<a href="mailto:pasi.parviainen@iki.fi" target="_blank">pasi.parviainen@iki.fi</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 26.6.2014 6:02, David Majnemer wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: majnemer<br>
Date: Wed Jun 25 22:02:19 2014<br>
New Revision: 211762<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=211762&view=rev" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project?rev=211762&view=rev</a><br>
Log:<br>
GlobalOpt: Don't optimize thread_local for initializers<br>
<br>
Folding a reference to a thread_local variable into another global<br>
variable's initializer is very problematic, there is no relocation that<br>
exists to represent such an access.<br>
<br>
Modified:<br>
     llvm/trunk/lib/Transforms/IPO/<u></u>GlobalOpt.cpp<br>
     llvm/trunk/test/Transforms/<u></u>GlobalOpt/constantfold-<u></u>initializers.ll<br>
<br>
Modified: llvm/trunk/lib/Transforms/IPO/<u></u>GlobalOpt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=211762&r1=211761&r2=211762&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/<u></u>Transforms/IPO/GlobalOpt.cpp?<u></u>rev=211762&r1=211761&r2=<u></u>211762&view=diff</a><br>

==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/lib/Transforms/IPO/<u></u>GlobalOpt.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/IPO/<u></u>GlobalOpt.cpp Wed Jun 25 22:02:19 2014<br>
@@ -1980,9 +1980,10 @@ isSimpleEnoughValueToCommit(<u></u>Constant *C,<br>
  static bool isSimpleEnoughValueToCommitHel<u></u>per(Constant *C,<br>
                                     SmallPtrSet<Constant*, 8> &SimpleConstants,<br>
                                     const DataLayout *DL) {<br>
-  // Simple global addresses are supported, do not allow dllimport globals.<br>
+  // Simple global addresses are supported, do not allow dllimport or<br>
+  // thread-local globals.<br>
    if (auto *GV = dyn_cast<GlobalValue>(C))<br>
-    return !GV->hasDLLImportStorageClass(<u></u>);<br>
+    return !GV->hasDLLImportStorageClass(<u></u>) && !GV->isThreadLocal();<br>
<br>
    // Simple integer, undef, constant aggregate zero, etc are all supported.<br>
    if (C->getNumOperands() == 0 || isa<BlockAddress>(C))<br>
<br>
Modified: llvm/trunk/test/Transforms/<u></u>GlobalOpt/constantfold-<u></u>initializers.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/constantfold-initializers.ll?rev=211762&r1=211761&r2=211762&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/test/<u></u>Transforms/GlobalOpt/<u></u>constantfold-initializers.ll?<u></u>rev=211762&r1=211761&r2=<u></u>211762&view=diff</a><br>

==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/test/Transforms/<u></u>GlobalOpt/constantfold-<u></u>initializers.ll (original)<br>
+++ llvm/trunk/test/Transforms/<u></u>GlobalOpt/constantfold-<u></u>initializers.ll Wed Jun 25 22:02:19 2014<br>
@@ -72,9 +72,19 @@ entry:<br>
    ret void<br>
  }<br>
<br>
+@threadlocalptr = global i32* null, align 4<br>
+; CHECK: @threadlocalptr = global i32* null, align 4<br>
+@threadlocalvar = external thread_local global i32<br>
+define internal void @test5() {<br>
+entry:<br>
+  store i32* @threadlocalvar, i32** @threadlocalptr, align 4<br>
+  ret void<br>
+}<br>
+<br>
  @llvm.global_ctors = appending constant<br>
-  [4 x { i32, void ()* }]<br>
+  [5 x { i32, void ()* }]<br>
    [{ i32, void ()* } { i32 65535, void ()* @test1 },<br>
     { i32, void ()* } { i32 65535, void ()* @test2 },<br>
     { i32, void ()* } { i32 65535, void ()* @test3 },<br>
+   { i32, void ()* } { i32 65535, void ()* @test4 },<br>
     { i32, void ()* } { i32 65535, void ()* @test4 }]<br>
</blockquote>
<br></div></div>
Should this array have entry for test5, instead of having duplicate entry for test4?<span class="HOEnZb"><font color="#888888"><br>
<br>
Pasi<br>
</font></span></blockquote></div><br></div>