[llvm] ad9ce81 - [ConstantMerge] Don't merge thread_local constants with non-thread_local constants

Amanieu d'Antras via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 28 15:44:26 PDT 2021


Author: Amanieu d'Antras
Date: 2021-04-28T23:44:20+01:00
New Revision: ad9ce8142dd5b90f725ad362feb054d52a35aa1f

URL: https://github.com/llvm/llvm-project/commit/ad9ce8142dd5b90f725ad362feb054d52a35aa1f
DIFF: https://github.com/llvm/llvm-project/commit/ad9ce8142dd5b90f725ad362feb054d52a35aa1f.diff

LOG: [ConstantMerge] Don't merge thread_local constants with non-thread_local constants

Fixes PR49932

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D100322

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/ConstantMerge.cpp
    llvm/test/Transforms/ConstantMerge/dont-merge.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/ConstantMerge.cpp b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
index 67f1438b9b6ac..8e81f4bad4af2 100644
--- a/llvm/lib/Transforms/IPO/ConstantMerge.cpp
+++ b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
@@ -95,6 +95,8 @@ isUnmergeableGlobal(GlobalVariable *GV,
   // Only process constants with initializers in the default address space.
   return !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
          GV->getType()->getAddressSpace() != 0 || GV->hasSection() ||
+         // Don't touch thread-local variables.
+         GV->isThreadLocal() ||
          // Don't touch values marked with attribute(used).
          UsedGlobals.count(GV);
 }

diff  --git a/llvm/test/Transforms/ConstantMerge/dont-merge.ll b/llvm/test/Transforms/ConstantMerge/dont-merge.ll
index 21e390785df56..b0dab923d2cb2 100644
--- a/llvm/test/Transforms/ConstantMerge/dont-merge.ll
+++ b/llvm/test/Transforms/ConstantMerge/dont-merge.ll
@@ -80,3 +80,15 @@ define void @test4(i32** %P1, i32** %P2, i32** %P3, i32** %P4, i32** %P5, i32**
         store i32* @T4D2, i32** %P8
         ret void
 }
+
+; CHECK: @T5tls
+; CHECK: @T5ua
+
+ at T5tls = private thread_local constant i32 555
+ at T5ua = private unnamed_addr constant i32 555
+
+define void @test5(i32** %P1, i32** %P2) {
+        store i32* @T5tls, i32** %P1
+        store i32* @T5ua, i32** %P2
+        ret void
+}


        


More information about the llvm-commits mailing list