[llvm] r211762 - GlobalOpt: Don't optimize thread_local for initializers

Pasi Parviainen pasi.parviainen at iki.fi
Fri Jun 27 00:12:04 PDT 2014


On 26.6.2014 6:02, David Majnemer wrote:
> Author: majnemer
> Date: Wed Jun 25 22:02:19 2014
> New Revision: 211762
>
> URL: http://llvm.org/viewvc/llvm-project?rev=211762&view=rev
> Log:
> GlobalOpt: Don't optimize thread_local for initializers
>
> Folding a reference to a thread_local variable into another global
> variable's initializer is very problematic, there is no relocation that
> exists to represent such an access.
>
> Modified:
>      llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
>      llvm/trunk/test/Transforms/GlobalOpt/constantfold-initializers.ll
>
> Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=211762&r1=211761&r2=211762&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
> +++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Wed Jun 25 22:02:19 2014
> @@ -1980,9 +1980,10 @@ isSimpleEnoughValueToCommit(Constant *C,
>   static bool isSimpleEnoughValueToCommitHelper(Constant *C,
>                                      SmallPtrSet<Constant*, 8> &SimpleConstants,
>                                      const DataLayout *DL) {
> -  // Simple global addresses are supported, do not allow dllimport globals.
> +  // Simple global addresses are supported, do not allow dllimport or
> +  // thread-local globals.
>     if (auto *GV = dyn_cast<GlobalValue>(C))
> -    return !GV->hasDLLImportStorageClass();
> +    return !GV->hasDLLImportStorageClass() && !GV->isThreadLocal();
>
>     // Simple integer, undef, constant aggregate zero, etc are all supported.
>     if (C->getNumOperands() == 0 || isa<BlockAddress>(C))
>
> Modified: llvm/trunk/test/Transforms/GlobalOpt/constantfold-initializers.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/constantfold-initializers.ll?rev=211762&r1=211761&r2=211762&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/GlobalOpt/constantfold-initializers.ll (original)
> +++ llvm/trunk/test/Transforms/GlobalOpt/constantfold-initializers.ll Wed Jun 25 22:02:19 2014
> @@ -72,9 +72,19 @@ entry:
>     ret void
>   }
>
> + at threadlocalptr = global i32* null, align 4
> +; CHECK: @threadlocalptr = global i32* null, align 4
> + at threadlocalvar = external thread_local global i32
> +define internal void @test5() {
> +entry:
> +  store i32* @threadlocalvar, i32** @threadlocalptr, align 4
> +  ret void
> +}
> +
>   @llvm.global_ctors = appending constant
> -  [4 x { i32, void ()* }]
> +  [5 x { i32, void ()* }]
>     [{ i32, void ()* } { i32 65535, void ()* @test1 },
>      { i32, void ()* } { i32 65535, void ()* @test2 },
>      { i32, void ()* } { i32 65535, void ()* @test3 },
> +   { i32, void ()* } { i32 65535, void ()* @test4 },
>      { i32, void ()* } { i32 65535, void ()* @test4 }]

Should this array have entry for test5, instead of having duplicate 
entry for test4?

Pasi



More information about the llvm-commits mailing list