[llvm] [WebAssembly] Remove threadlocal.address when disabling TLS (PR #88209)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 23:59:15 PDT 2024


================
@@ -289,6 +289,19 @@ class CoalesceFeaturesAndStripAtomics final : public ModulePass {
 
   bool stripThreadLocals(Module &M) {
     bool Stripped = false;
+    for (auto &F : M) {
+      for (auto &B : F) {
+        for (auto &I : make_early_inc_range(B)) {
+          if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I)) {
+            if (II->getIntrinsicID() == Intrinsic::threadlocal_address) {
+              II->replaceAllUsesWith(II->getArgOperand(0));
+              II->eraseFromParent();
+              Stripped = true;
+            }
+          }
+        }
+      }
+    }
     for (auto &GV : M.globals()) {
       if (GV.isThreadLocal()) {
----------------
nikic wrote:

Wouldn't it be better to walk the users of GV, rather than doing a walk over all instructions in all functions?

https://github.com/llvm/llvm-project/pull/88209


More information about the llvm-commits mailing list