[llvm] [PPC] Replace PPCMergeStringPool with GlobalMerge for Linux (PR #114850)

Zaara Syeda via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 7 08:10:30 PST 2024


https://github.com/syzaara updated https://github.com/llvm/llvm-project/pull/114850

>From 68cbbf18f21f9f350de8ef1b8541f47b09873d02 Mon Sep 17 00:00:00 2001
From: Zaara Syeda <syzaara at ca.ibm.com>
Date: Thu, 31 Oct 2024 16:19:39 -0400
Subject: [PATCH 1/4] [PPC] Replace PPCMergeStringPool with GlobalMerge for
 Linux

---
 llvm/lib/CodeGen/GlobalMerge.cpp              |  19 ++
 llvm/lib/Target/PowerPC/PPCTargetMachine.cpp  |   9 +-
 llvm/test/CodeGen/PowerPC/O3-pipeline.ll      |   1 +
 .../CodeGen/PowerPC/PR35812-neg-cmpxchg.ll    |  32 +--
 .../PowerPC/aix-xcoff-used-with-stringpool.ll |   6 +-
 llvm/test/CodeGen/PowerPC/ctrloop-fp128.ll    |  74 ++---
 .../CodeGen/PowerPC/expand-contiguous-isel.ll |  18 +-
 llvm/test/CodeGen/PowerPC/licm-remat.ll       |   6 +-
 llvm/test/CodeGen/PowerPC/merge-private.ll    |   4 +-
 .../PowerPC/mergeable-string-pool-large.ll    | 272 +++++++++---------
 .../PowerPC/mergeable-string-pool-pr92991.ll  |   4 +-
 .../PowerPC/mergeable-string-pool-tls.ll      | 129 ++++-----
 .../CodeGen/PowerPC/mergeable-string-pool.ll  | 185 ++++++------
 .../CodeGen/PowerPC/toc-load-sched-bug.ll     |   4 +-
 14 files changed, 388 insertions(+), 375 deletions(-)

diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index 9a939d06946dff..30f44e3d61d8b1 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -79,6 +79,7 @@
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/Instruction.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Use.h"
@@ -713,6 +714,24 @@ bool GlobalMergeImpl::run(Module &M) {
     // Ignore all "required" globals:
     if (isMustKeepGlobalVariable(&GV))
       continue;
+    auto checkUsers = [] (const GlobalVariable *GV) {
+      for (const User *CurrentUser : GV->users()) {
+        if (auto *I = dyn_cast<Instruction>(CurrentUser)) {
+          // Do not merge globals in exception pads.
+          if (I->isEHPad())
+            return false;
+          if (auto *II = dyn_cast<IntrinsicInst>(I)) {
+            // Some intrinsics require a plain global.
+            if (II->getIntrinsicID() == Intrinsic::eh_typeid_for)
+              return false;
+          }
+        }
+      }
+      return true;
+    };
+
+    if (!checkUsers(&GV))
+      continue;
 
     // Don't merge tagged globals, as each global should have its own unique
     // memory tag at runtime. TODO(hctim): This can be relaxed: constant globals
diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
index 133c47174570cc..538690090976ce 100644
--- a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -503,17 +503,10 @@ bool PPCPassConfig::addPreISel() {
   // Specifying the command line option overrides the AIX default.
   if ((EnableGlobalMerge.getNumOccurrences() > 0)
           ? EnableGlobalMerge
-          : (TM->getTargetTriple().isOSAIX() &&
-             getOptLevel() != CodeGenOptLevel::None))
+          : getOptLevel() != CodeGenOptLevel::None)
     addPass(createGlobalMergePass(TM, GlobalMergeMaxOffset, false, false, true,
                                   true));
 
-  if ((MergeStringPool.getNumOccurrences() > 0)
-          ? MergeStringPool
-          : (TM->getTargetTriple().isOSLinux() &&
-             getOptLevel() != CodeGenOptLevel::None))
-    addPass(createPPCMergeStringPoolPass());
-
   if (!DisableInstrFormPrep && getOptLevel() != CodeGenOptLevel::None)
     addPass(createPPCLoopInstrFormPrepPass(getPPCTargetMachine()));
 
diff --git a/llvm/test/CodeGen/PowerPC/O3-pipeline.ll b/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
index 8aeea4ba045bf3..f590c599586aed 100644
--- a/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
+++ b/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
@@ -70,6 +70,7 @@
 ; CHECK-NEXT:       CodeGen Prepare
 ; CHECK-NEXT:       Dominator Tree Construction
 ; CHECK-NEXT:       Exception handling preparation
+; CHECK-NEXT:       Merge internal globals
 ; CHECK-NEXT:       Natural Loop Information
 ; CHECK-NEXT:       Scalar Evolution Analysis
 ; CHECK-NEXT:       Prepare loop for ppc preferred instruction forms
diff --git a/llvm/test/CodeGen/PowerPC/PR35812-neg-cmpxchg.ll b/llvm/test/CodeGen/PowerPC/PR35812-neg-cmpxchg.ll
index 896825fcda8a81..8517783e3ebd78 100644
--- a/llvm/test/CodeGen/PowerPC/PR35812-neg-cmpxchg.ll
+++ b/llvm/test/CodeGen/PowerPC/PR35812-neg-cmpxchg.ll
@@ -39,21 +39,21 @@ define signext i32 @main() nounwind {
 ; CHECK-NEXT:    cmplwi 3, 234
 ; CHECK-NEXT:    bne 0, .LBB0_7
 ; CHECK-NEXT:  # %bb.5: # %L.B0001
-; CHECK-NEXT:    addis 3, 2, .L__ModuleStringPool at toc@ha
-; CHECK-NEXT:    addi 3, 3, .L__ModuleStringPool at toc@l
+; CHECK-NEXT:    addis 3, 2, .L_MergedGlobals at toc@ha
+; CHECK-NEXT:    addi 3, 3, .L_MergedGlobals at toc@l
 ; CHECK-NEXT:    bl puts
 ; CHECK-NEXT:    nop
 ; CHECK-NEXT:    li 3, 0
 ; CHECK-NEXT:    b .LBB0_9
 ; CHECK-NEXT:  .LBB0_6: # %L.B0003
-; CHECK-NEXT:    addis 3, 2, .L__ModuleStringPool at toc@ha
-; CHECK-NEXT:    addi 3, 3, .L__ModuleStringPool at toc@l
-; CHECK-NEXT:    addi 3, 3, 7
+; CHECK-NEXT:    addis 3, 2, .L_MergedGlobals at toc@ha
+; CHECK-NEXT:    addi 3, 3, .L_MergedGlobals at toc@l
+; CHECK-NEXT:    addi 3, 3, 16
 ; CHECK-NEXT:    b .LBB0_8
 ; CHECK-NEXT:  .LBB0_7: # %L.B0005
-; CHECK-NEXT:    addis 3, 2, .L__ModuleStringPool at toc@ha
-; CHECK-NEXT:    addi 3, 3, .L__ModuleStringPool at toc@l
-; CHECK-NEXT:    addi 3, 3, 53
+; CHECK-NEXT:    addis 3, 2, .L_MergedGlobals at toc@ha
+; CHECK-NEXT:    addi 3, 3, .L_MergedGlobals at toc@l
+; CHECK-NEXT:    addi 3, 3, 64
 ; CHECK-NEXT:  .LBB0_8: # %L.B0003
 ; CHECK-NEXT:    bl puts
 ; CHECK-NEXT:    nop
@@ -107,21 +107,21 @@ define signext i32 @main() nounwind {
 ; CHECK-P7-NEXT:    cmplwi 3, 234
 ; CHECK-P7-NEXT:    bne 0, .LBB0_7
 ; CHECK-P7-NEXT:  # %bb.5: # %L.B0001
-; CHECK-P7-NEXT:    addis 3, 2, .L__ModuleStringPool at toc@ha
-; CHECK-P7-NEXT:    addi 3, 3, .L__ModuleStringPool at toc@l
+; CHECK-P7-NEXT:    addis 3, 2, .L_MergedGlobals at toc@ha
+; CHECK-P7-NEXT:    addi 3, 3, .L_MergedGlobals at toc@l
 ; CHECK-P7-NEXT:    bl puts
 ; CHECK-P7-NEXT:    nop
 ; CHECK-P7-NEXT:    li 3, 0
 ; CHECK-P7-NEXT:    b .LBB0_9
 ; CHECK-P7-NEXT:  .LBB0_6: # %L.B0003
-; CHECK-P7-NEXT:    addis 3, 2, .L__ModuleStringPool at toc@ha
-; CHECK-P7-NEXT:    addi 3, 3, .L__ModuleStringPool at toc@l
-; CHECK-P7-NEXT:    addi 3, 3, 7
+; CHECK-P7-NEXT:    addis 3, 2, .L_MergedGlobals at toc@ha
+; CHECK-P7-NEXT:    addi 3, 3, .L_MergedGlobals at toc@l
+; CHECK-P7-NEXT:    addi 3, 3, 16
 ; CHECK-P7-NEXT:    b .LBB0_8
 ; CHECK-P7-NEXT:  .LBB0_7: # %L.B0005
-; CHECK-P7-NEXT:    addis 3, 2, .L__ModuleStringPool at toc@ha
-; CHECK-P7-NEXT:    addi 3, 3, .L__ModuleStringPool at toc@l
-; CHECK-P7-NEXT:    addi 3, 3, 53
+; CHECK-P7-NEXT:    addis 3, 2, .L_MergedGlobals at toc@ha
+; CHECK-P7-NEXT:    addi 3, 3, .L_MergedGlobals at toc@l
+; CHECK-P7-NEXT:    addi 3, 3, 64
 ; CHECK-P7-NEXT:  .LBB0_8: # %L.B0003
 ; CHECK-P7-NEXT:    bl puts
 ; CHECK-P7-NEXT:    nop
diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-used-with-stringpool.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-used-with-stringpool.ll
index 7f93661c37ee8c..bbcba59e2e33ac 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-used-with-stringpool.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-used-with-stringpool.ll
@@ -2,11 +2,11 @@
 ;; in llvm.used or in llvm.compiler.used.
 
 ; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc-ibm-aix-xcoff \
-; RUN:   -ppc-merge-string-pool=true -global-merge-all-const=false -data-sections=false < %s | \
+; RUN:   -data-sections=false < %s | \
 ; RUN:   FileCheck %s
 
 ; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc64-ibm-aix-xcoff \
-; RUN:   -ppc-merge-string-pool=true -global-merge-all-const=false -data-sections=false < %s | \
+; RUN:   -data-sections=false < %s | \
 ; RUN:   FileCheck %s
 
 @keep_this = internal constant [5 x i8] c"keep1", align 1
@@ -53,7 +53,7 @@ entry:
 ; CHECK:  keep_this:
 ; CHECK:    .lglobl keep_this2
 ; CHECK:  keep_this2:
-; CHECK:  L..__ModuleStringPool:
+; CHECK:  L.._MergedGlobals:
 ; CHECK:    .string "str1_STRING"
 ; CHECK:    .string "str2_STRING"
 ; CHECK:    .string "str3_STRING"
diff --git a/llvm/test/CodeGen/PowerPC/ctrloop-fp128.ll b/llvm/test/CodeGen/PowerPC/ctrloop-fp128.ll
index 23d021a2629341..d6dd9593654011 100644
--- a/llvm/test/CodeGen/PowerPC/ctrloop-fp128.ll
+++ b/llvm/test/CodeGen/PowerPC/ctrloop-fp128.ll
@@ -9,24 +9,17 @@
 define void @fmul_ctrloop_fp128() nounwind {
 ; PWR9-LABEL: fmul_ctrloop_fp128:
 ; PWR9:       # %bb.0: # %entry
-; PWR9-NEXT:    addis 3, 2, a at toc@ha
+; PWR9-NEXT:    addis 3, 2, .L_MergedGlobals at toc@ha
 ; PWR9-NEXT:    li 4, 4
-; PWR9-NEXT:    addi 3, 3, a at toc@l
+; PWR9-NEXT:    addi 3, 3, .L_MergedGlobals at toc@l
 ; PWR9-NEXT:    lxv 34, 0(3)
-; PWR9-NEXT:    addis 3, 2, y at toc@ha
 ; PWR9-NEXT:    mtctr 4
-; PWR9-NEXT:    addis 4, 2, x at toc@ha
-; PWR9-NEXT:    addi 3, 3, y at toc@l
-; PWR9-NEXT:    addi 4, 4, x at toc@l
-; PWR9-NEXT:    addi 3, 3, -16
-; PWR9-NEXT:    addi 4, 4, -16
 ; PWR9-NEXT:    .p2align 5
 ; PWR9-NEXT:  .LBB0_1: # %for.body
 ; PWR9-NEXT:    #
-; PWR9-NEXT:    lxv 35, 16(4)
-; PWR9-NEXT:    addi 4, 4, 16
+; PWR9-NEXT:    lxv 35, 16(3)
 ; PWR9-NEXT:    xsmulqp 3, 2, 3
-; PWR9-NEXT:    stxv 35, 16(3)
+; PWR9-NEXT:    stxv 35, 80(3)
 ; PWR9-NEXT:    addi 3, 3, 16
 ; PWR9-NEXT:    bdnz .LBB0_1
 ; PWR9-NEXT:  # %bb.2: # %for.end
@@ -38,40 +31,33 @@ define void @fmul_ctrloop_fp128() nounwind {
 ; PWR8-NEXT:    stdu 1, -112(1)
 ; PWR8-NEXT:    li 3, 48
 ; PWR8-NEXT:    std 0, 128(1)
+; PWR8-NEXT:    std 30, 96(1) # 8-byte Folded Spill
+; PWR8-NEXT:    std 27, 72(1) # 8-byte Folded Spill
 ; PWR8-NEXT:    std 28, 80(1) # 8-byte Folded Spill
+; PWR8-NEXT:    li 28, 16
+; PWR8-NEXT:    li 27, 80
 ; PWR8-NEXT:    std 29, 88(1) # 8-byte Folded Spill
-; PWR8-NEXT:    std 30, 96(1) # 8-byte Folded Spill
-; PWR8-NEXT:    li 30, 4
-; PWR8-NEXT:    li 29, 16
-; PWR8-NEXT:    std 26, 64(1) # 8-byte Folded Spill
 ; PWR8-NEXT:    stxvd2x 63, 1, 3 # 16-byte Folded Spill
-; PWR8-NEXT:    addis 3, 2, a at toc@ha
-; PWR8-NEXT:    addi 3, 3, a at toc@l
-; PWR8-NEXT:    std 27, 72(1) # 8-byte Folded Spill
-; PWR8-NEXT:    lxvd2x 0, 0, 3
-; PWR8-NEXT:    addis 3, 2, y at toc@ha
-; PWR8-NEXT:    addi 3, 3, y at toc@l
-; PWR8-NEXT:    addi 28, 3, -16
-; PWR8-NEXT:    addis 3, 2, x at toc@ha
-; PWR8-NEXT:    addi 3, 3, x at toc@l
-; PWR8-NEXT:    addi 3, 3, -16
+; PWR8-NEXT:    addis 3, 2, .L_MergedGlobals at toc@ha
+; PWR8-NEXT:    li 29, 4
+; PWR8-NEXT:    addi 30, 3, .L_MergedGlobals at toc@l
+; PWR8-NEXT:    std 26, 64(1) # 8-byte Folded Spill
+; PWR8-NEXT:    lxvd2x 0, 0, 30
 ; PWR8-NEXT:    xxswapd 63, 0
 ; PWR8-NEXT:    .p2align 4
 ; PWR8-NEXT:  .LBB0_1: # %for.body
 ; PWR8-NEXT:    #
-; PWR8-NEXT:    lxvd2x 0, 3, 29
+; PWR8-NEXT:    lxvd2x 0, 30, 28
 ; PWR8-NEXT:    vmr 2, 31
-; PWR8-NEXT:    addi 27, 28, 16
-; PWR8-NEXT:    addi 26, 3, 16
+; PWR8-NEXT:    addi 26, 30, 16
 ; PWR8-NEXT:    xxswapd 35, 0
 ; PWR8-NEXT:    bl __mulkf3
 ; PWR8-NEXT:    nop
-; PWR8-NEXT:    addi 30, 30, -1
+; PWR8-NEXT:    addi 29, 29, -1
 ; PWR8-NEXT:    xxswapd 0, 34
-; PWR8-NEXT:    mr 3, 26
-; PWR8-NEXT:    cmpldi 30, 0
-; PWR8-NEXT:    stxvd2x 0, 28, 29
-; PWR8-NEXT:    mr 28, 27
+; PWR8-NEXT:    cmpldi 29, 0
+; PWR8-NEXT:    stxvd2x 0, 30, 27
+; PWR8-NEXT:    mr 30, 26
 ; PWR8-NEXT:    bc 12, 1, .LBB0_1
 ; PWR8-NEXT:  # %bb.2: # %for.end
 ; PWR8-NEXT:    li 3, 48
@@ -110,9 +96,9 @@ define void @fpext_ctrloop_fp128(ptr %a) nounwind {
 ; PWR9-NEXT:    li 4, 4
 ; PWR9-NEXT:    addi 3, 3, -8
 ; PWR9-NEXT:    mtctr 4
-; PWR9-NEXT:    addis 4, 2, y at toc@ha
-; PWR9-NEXT:    addi 4, 4, y at toc@l
-; PWR9-NEXT:    addi 4, 4, -16
+; PWR9-NEXT:    addis 4, 2, .L_MergedGlobals at toc@ha
+; PWR9-NEXT:    addi 4, 4, .L_MergedGlobals at toc@l
+; PWR9-NEXT:    addi 4, 4, 64
 ; PWR9-NEXT:    .p2align 5
 ; PWR9-NEXT:  .LBB1_1: # %for.body
 ; PWR9-NEXT:    #
@@ -133,11 +119,11 @@ define void @fpext_ctrloop_fp128(ptr %a) nounwind {
 ; PWR8-NEXT:    std 30, -16(1) # 8-byte Folded Spill
 ; PWR8-NEXT:    stdu 1, -64(1)
 ; PWR8-NEXT:    addi 30, 3, -8
-; PWR8-NEXT:    addis 3, 2, y at toc@ha
+; PWR8-NEXT:    addis 3, 2, .L_MergedGlobals at toc@ha
 ; PWR8-NEXT:    li 29, 4
 ; PWR8-NEXT:    std 0, 80(1)
-; PWR8-NEXT:    addi 3, 3, y at toc@l
-; PWR8-NEXT:    addi 28, 3, -16
+; PWR8-NEXT:    addi 3, 3, .L_MergedGlobals at toc@l
+; PWR8-NEXT:    addi 28, 3, 64
 ; PWR8-NEXT:    .p2align 4
 ; PWR8-NEXT:  .LBB1_1: # %for.body
 ; PWR8-NEXT:    #
@@ -182,9 +168,8 @@ define void @fptrunc_ctrloop_fp128(ptr %a) nounwind {
 ; PWR9-NEXT:    li 4, 4
 ; PWR9-NEXT:    addi 3, 3, -8
 ; PWR9-NEXT:    mtctr 4
-; PWR9-NEXT:    addis 4, 2, x at toc@ha
-; PWR9-NEXT:    addi 4, 4, x at toc@l
-; PWR9-NEXT:    addi 4, 4, -16
+; PWR9-NEXT:    addis 4, 2, .L_MergedGlobals at toc@ha
+; PWR9-NEXT:    addi 4, 4, .L_MergedGlobals at toc@l
 ; PWR9-NEXT:    .p2align 5
 ; PWR9-NEXT:  .LBB2_1: # %for.body
 ; PWR9-NEXT:    #
@@ -205,11 +190,10 @@ define void @fptrunc_ctrloop_fp128(ptr %a) nounwind {
 ; PWR8-NEXT:    std 30, -16(1) # 8-byte Folded Spill
 ; PWR8-NEXT:    stdu 1, -64(1)
 ; PWR8-NEXT:    addi 30, 3, -8
-; PWR8-NEXT:    addis 3, 2, x at toc@ha
+; PWR8-NEXT:    addis 3, 2, .L_MergedGlobals at toc@ha
 ; PWR8-NEXT:    li 29, 4
 ; PWR8-NEXT:    std 0, 80(1)
-; PWR8-NEXT:    addi 3, 3, x at toc@l
-; PWR8-NEXT:    addi 28, 3, -16
+; PWR8-NEXT:    addi 28, 3, .L_MergedGlobals at toc@l
 ; PWR8-NEXT:    .p2align 4
 ; PWR8-NEXT:  .LBB2_1: # %for.body
 ; PWR8-NEXT:    #
diff --git a/llvm/test/CodeGen/PowerPC/expand-contiguous-isel.ll b/llvm/test/CodeGen/PowerPC/expand-contiguous-isel.ll
index 9e53c7e88b0e30..3668a24a538094 100644
--- a/llvm/test/CodeGen/PowerPC/expand-contiguous-isel.ll
+++ b/llvm/test/CodeGen/PowerPC/expand-contiguous-isel.ll
@@ -110,11 +110,12 @@ define i64 @_Z3fn1N4llvm9StringRefE([2 x i64] %Str.coerce) {
 ; CHECK-GEN-ISEL-TRUE-NEXT:    mtlr r0
 ; CHECK-GEN-ISEL-TRUE-NEXT:    blr
 ; CHECK-GEN-ISEL-TRUE-NEXT:  .LBB0_15: # %cond.false.i
-; CHECK-GEN-ISEL-TRUE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; CHECK-GEN-ISEL-TRUE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; CHECK-GEN-ISEL-TRUE-NEXT:    addi r5, r3, .L_MergedGlobals at toc@l
+; CHECK-GEN-ISEL-TRUE-NEXT:    addi r3, r5, 3
+; CHECK-GEN-ISEL-TRUE-NEXT:    addi r4, r5, 134
+; CHECK-GEN-ISEL-TRUE-NEXT:    addi r6, r5, 38
 ; CHECK-GEN-ISEL-TRUE-NEXT:    li r5, 225
-; CHECK-GEN-ISEL-TRUE-NEXT:    addi r4, r3, .L__ModuleStringPool at toc@l
-; CHECK-GEN-ISEL-TRUE-NEXT:    addi r3, r4, 53
-; CHECK-GEN-ISEL-TRUE-NEXT:    addi r6, r4, 88
 ; CHECK-GEN-ISEL-TRUE-NEXT:    bl __assert_fail
 ; CHECK-GEN-ISEL-TRUE-NEXT:    nop
 ; CHECK-GEN-ISEL-TRUE-NEXT:  .LBB0_16: # %if.then9
@@ -226,11 +227,12 @@ define i64 @_Z3fn1N4llvm9StringRefE([2 x i64] %Str.coerce) {
 ; CHECK-NEXT:    mtlr r0
 ; CHECK-NEXT:    blr
 ; CHECK-NEXT:  .LBB0_20: # %cond.false.i
-; CHECK-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; CHECK-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; CHECK-NEXT:    addi r5, r3, .L_MergedGlobals at toc@l
+; CHECK-NEXT:    addi r3, r5, 3
+; CHECK-NEXT:    addi r4, r5, 134
+; CHECK-NEXT:    addi r6, r5, 38
 ; CHECK-NEXT:    li r5, 225
-; CHECK-NEXT:    addi r4, r3, .L__ModuleStringPool at toc@l
-; CHECK-NEXT:    addi r3, r4, 53
-; CHECK-NEXT:    addi r6, r4, 88
 ; CHECK-NEXT:    bl __assert_fail
 ; CHECK-NEXT:    nop
 ; CHECK-NEXT:  .LBB0_21: # %if.then9
diff --git a/llvm/test/CodeGen/PowerPC/licm-remat.ll b/llvm/test/CodeGen/PowerPC/licm-remat.ll
index cf3e3ac089a498..543061b0e65153 100644
--- a/llvm/test/CodeGen/PowerPC/licm-remat.ll
+++ b/llvm/test/CodeGen/PowerPC/licm-remat.ll
@@ -20,10 +20,10 @@ declare void @llvm.memcpy.p0.p0.i64(ptr nocapture writeonly, ptr nocapture reado
 define linkonce_odr void @ZN6snappyDecompressor_(ptr %this, ptr %writer) {
 ; CHECK-LABEL: ZN6snappyDecompressor_:
 ; CHECK:       # %bb.0: # %entry
-; CHECK:       addis 4, 2, .L__ModuleStringPool at toc@ha
-; CHECK:       addi 26, 4, .L__ModuleStringPool at toc@l
+; CHECK:       addis 4, 2, .L_MergedGlobals at toc@ha
+; CHECK:       addi 26, 4, .L_MergedGlobals at toc@l
 ; CHECK:       .LBB0_2: # %for.cond
-; CHECK-NOT:   addis {{[0-9]+}}, 2, .L__ModuleStringPool at toc@ha
+; CHECK-NOT:   addis {{[0-9]+}}, 2, .L_MergedGlobals at toc@ha
 ; CHECK:       bctrl
 entry:
   %ip_limit_ = getelementptr inbounds %"class.snappy::SnappyDecompressor", ptr %this, i64 0, i32 2
diff --git a/llvm/test/CodeGen/PowerPC/merge-private.ll b/llvm/test/CodeGen/PowerPC/merge-private.ll
index d3f29108264233..b50783d10928e2 100644
--- a/llvm/test/CodeGen/PowerPC/merge-private.ll
+++ b/llvm/test/CodeGen/PowerPC/merge-private.ll
@@ -6,10 +6,10 @@
 ; RUN:     -ppc-asm-full-reg-names < %s | FileCheck %s \
 ; RUN:     --check-prefix=AIX32
 ; RUN: llc -verify-machineinstrs -mtriple powerpc64le-unknown-linux -mcpu=pwr8 \
-; RUN:     -ppc-asm-full-reg-names -ppc-global-merge=true < %s | FileCheck %s \
+; RUN:     -ppc-asm-full-reg-names < %s | FileCheck %s \
 ; RUN:     --check-prefix=LINUX64LE
 ; RUN: llc -verify-machineinstrs -mtriple powerpc64-unknown-linux -mcpu=pwr8 \
-; RUN:     -ppc-asm-full-reg-names -ppc-global-merge=true < %s | FileCheck %s \
+; RUN:     -ppc-asm-full-reg-names < %s | FileCheck %s \
 ; RUN:     --check-prefix=LINUX64BE
 ; The below run line is added to ensure that the assembly corresponding to
 ; the following check-prefix is generated by default on AIX (without any
diff --git a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-large.ll b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-large.ll
index 27923e47b86b66..e6f6ce236bb2d9 100644
--- a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-large.ll
+++ b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-large.ll
@@ -3,9 +3,9 @@
 ; RUN:   -ppc-asm-full-reg-names < %s | FileCheck %s --check-prefixes=AIX32
 ; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr8 -ppc-global-merge-max-offset=50000 \
 ; RUN:   -ppc-asm-full-reg-names < %s | FileCheck %s --check-prefixes=AIX64
-; RUN: llc -verify-machineinstrs -mtriple powerpc64-unknown-linux -mcpu=pwr8 \
+; RUN: llc -verify-machineinstrs -mtriple powerpc64-unknown-linux -mcpu=pwr8 -ppc-global-merge-max-offset=50000 \
 ; RUN:   -ppc-asm-full-reg-names < %s | FileCheck %s --check-prefixes=LINUX64BE
-; RUN: llc -verify-machineinstrs -mtriple powerpc64le-unknown-linux -mcpu=pwr8 \
+; RUN: llc -verify-machineinstrs -mtriple powerpc64le-unknown-linux -mcpu=pwr8 -ppc-global-merge-max-offset=50000 \
 ; RUN:   -ppc-asm-full-reg-names < %s | FileCheck %s --check-prefixes=LINUX64LE
 
 @.str.1 = private unnamed_addr constant [12 x i8] c"str1_STRING\00", align 1
@@ -268,12 +268,9 @@ define dso_local signext i32 @str1() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -112(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64BE-NEXT:    li r4, 0
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 128(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    ori r4, r4, 35612
-; LINUX64BE-NEXT:    add r3, r3, r4
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addi r1, r1, 112
@@ -283,20 +280,17 @@ define dso_local signext i32 @str1() local_unnamed_addr #0 {
 ;
 ; LINUX64LE-LABEL: str1:
 ; LINUX64LE:       # %bb.0: # %entry
-; LINUX64LE-NEXT:    mflr r0
-; LINUX64LE-NEXT:    stdu r1, -32(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64LE-NEXT:    li r4, 0
-; LINUX64LE-NEXT:    std r0, 48(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    ori r4, r4, 35612
-; LINUX64LE-NEXT:    add r3, r3, r4
-; LINUX64LE-NEXT:    bl callee
-; LINUX64LE-NEXT:    nop
-; LINUX64LE-NEXT:    addi r1, r1, 32
-; LINUX64LE-NEXT:    ld r0, 16(r1)
-; LINUX64LE-NEXT:    mtlr r0
-; LINUX64LE-NEXT:    blr
+; LINUX64LE-NEXT:     mflr r0
+; LINUX64LE-NEXT:     stdu r1, -32(r1)
+; LINUX64LE-NEXT:     addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:     std r0, 48(r1)
+; LINUX64LE-NEXT:     addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:     bl callee
+; LINUX64LE-NEXT:     nop
+; LINUX64LE-NEXT:     addi r1, r1, 32
+; LINUX64LE-NEXT:     ld r0, 16(r1)
+; LINUX64LE-NEXT:     mtlr r0
+; LINUX64LE-NEXT:     blr
 entry:
   %call = tail call signext i32 @callee(ptr noundef nonnull @.str.1)
   ret i32 %call
@@ -356,15 +350,14 @@ define dso_local signext i32 @array0() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -144(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64BE-NEXT:    li r4, 0
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64BE-NEXT:    li r4, 24
 ; LINUX64BE-NEXT:    std r0, 160(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    ori r5, r4, 35596
-; LINUX64BE-NEXT:    ori r4, r4, 35584
-; LINUX64BE-NEXT:    lxvw4x vs0, r3, r5
-; LINUX64BE-NEXT:    addi r5, r1, 124
-; LINUX64BE-NEXT:    stxvw4x vs0, 0, r5
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    lxvw4x vs0, r3, r4
+; LINUX64BE-NEXT:    addi r4, r1, 124
+; LINUX64BE-NEXT:    stxvw4x vs0, 0, r4
+; LINUX64BE-NEXT:    li r4, 12
 ; LINUX64BE-NEXT:    lxvw4x vs0, r3, r4
 ; LINUX64BE-NEXT:    addi r3, r1, 112
 ; LINUX64BE-NEXT:    stxvw4x vs0, 0, r3
@@ -377,26 +370,25 @@ define dso_local signext i32 @array0() local_unnamed_addr #0 {
 ;
 ; LINUX64LE-LABEL: array0:
 ; LINUX64LE:       # %bb.0: # %entry
-; LINUX64LE-NEXT:    mflr r0
-; LINUX64LE-NEXT:    stdu r1, -64(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64LE-NEXT:    li r4, 0
-; LINUX64LE-NEXT:    std r0, 80(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    ori r5, r4, 35596
-; LINUX64LE-NEXT:    ori r4, r4, 35584
-; LINUX64LE-NEXT:    lxvd2x vs0, r3, r5
-; LINUX64LE-NEXT:    addi r5, r1, 44
-; LINUX64LE-NEXT:    stxvd2x vs0, 0, r5
-; LINUX64LE-NEXT:    lxvd2x vs0, r3, r4
-; LINUX64LE-NEXT:    addi r3, r1, 32
-; LINUX64LE-NEXT:    stxvd2x vs0, 0, r3
-; LINUX64LE-NEXT:    bl calleeInt
-; LINUX64LE-NEXT:    nop
-; LINUX64LE-NEXT:    addi r1, r1, 64
-; LINUX64LE-NEXT:    ld r0, 16(r1)
-; LINUX64LE-NEXT:    mtlr r0
-; LINUX64LE-NEXT:    blr
+; LINUX64LE-NEXT:     mflr r0
+; LINUX64LE-NEXT:     stdu r1, -64(r1)
+; LINUX64LE-NEXT:     addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:     li r4, 24
+; LINUX64LE-NEXT:     std r0, 80(r1)
+; LINUX64LE-NEXT:     addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:     lxvd2x vs0, r3, r4
+; LINUX64LE-NEXT:     addi r4, r1, 44
+; LINUX64LE-NEXT:     stxvd2x vs0, 0, r4
+; LINUX64LE-NEXT:     li r4, 12
+; LINUX64LE-NEXT:     lxvd2x vs0, r3, r4
+; LINUX64LE-NEXT:     addi r3, r1, 32
+; LINUX64LE-NEXT:     stxvd2x vs0, 0, r3
+; LINUX64LE-NEXT:     bl calleeInt
+; LINUX64LE-NEXT:     nop
+; LINUX64LE-NEXT:     addi r1, r1, 64
+; LINUX64LE-NEXT:     ld r0, 16(r1)
+; LINUX64LE-NEXT:     mtlr r0
+; LINUX64LE-NEXT:     blr
 entry:
   %IntArray = alloca [7 x i32], align 4
   call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %IntArray)
@@ -493,29 +485,36 @@ define dso_local signext i32 @array1() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -224(r1)
-; LINUX64BE-NEXT:    addis r4, r2, .L__ModuleStringPool at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64BE-NEXT:    li r4, 136
 ; LINUX64BE-NEXT:    li r5, 96
-; LINUX64BE-NEXT:    addi r3, r1, 112
 ; LINUX64BE-NEXT:    std r0, 240(r1)
-; LINUX64BE-NEXT:    addi r4, r4, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    lxvw4x vs0, r4, r5
-; LINUX64BE-NEXT:    stxvw4x vs0, r3, r5
-; LINUX64BE-NEXT:    li r5, 80
-; LINUX64BE-NEXT:    lxvw4x vs0, r4, r5
-; LINUX64BE-NEXT:    stxvw4x vs0, r3, r5
-; LINUX64BE-NEXT:    li r5, 64
-; LINUX64BE-NEXT:    lxvw4x vs0, r4, r5
-; LINUX64BE-NEXT:    stxvw4x vs0, r3, r5
-; LINUX64BE-NEXT:    li r5, 48
-; LINUX64BE-NEXT:    lxvw4x vs0, r4, r5
-; LINUX64BE-NEXT:    stxvw4x vs0, r3, r5
-; LINUX64BE-NEXT:    li r5, 32
-; LINUX64BE-NEXT:    lxvw4x vs0, r4, r5
-; LINUX64BE-NEXT:    stxvw4x vs0, r3, r5
-; LINUX64BE-NEXT:    li r5, 16
-; LINUX64BE-NEXT:    lxvw4x vs0, r4, r5
+; LINUX64BE-NEXT:    addi r6, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r1, 112
+; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
+; LINUX64BE-NEXT:    li r4, 120
 ; LINUX64BE-NEXT:    stxvw4x vs0, r3, r5
-; LINUX64BE-NEXT:    lxvw4x vs0, 0, r4
+; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
+; LINUX64BE-NEXT:    li r4, 80
+; LINUX64BE-NEXT:    stxvw4x vs0, r3, r4
+; LINUX64BE-NEXT:    li r4, 104
+; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
+; LINUX64BE-NEXT:    li r4, 64
+; LINUX64BE-NEXT:    stxvw4x vs0, r3, r4
+; LINUX64BE-NEXT:    li r4, 88
+; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
+; LINUX64BE-NEXT:    li r4, 48
+; LINUX64BE-NEXT:    stxvw4x vs0, r3, r4
+; LINUX64BE-NEXT:    li r4, 72
+; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
+; LINUX64BE-NEXT:    li r4, 32
+; LINUX64BE-NEXT:    stxvw4x vs0, r3, r4
+; LINUX64BE-NEXT:    li r4, 56
+; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
+; LINUX64BE-NEXT:    li r4, 16
+; LINUX64BE-NEXT:    stxvw4x vs0, r3, r4
+; LINUX64BE-NEXT:    li r4, 40
+; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
 ; LINUX64BE-NEXT:    stxvw4x vs0, 0, r3
 ; LINUX64BE-NEXT:    bl calleeInt
 ; LINUX64BE-NEXT:    nop
@@ -528,29 +527,36 @@ define dso_local signext i32 @array1() local_unnamed_addr #0 {
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
 ; LINUX64LE-NEXT:    stdu r1, -144(r1)
-; LINUX64LE-NEXT:    addis r4, r2, .L__ModuleStringPool at toc@ha
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    li r4, 136
 ; LINUX64LE-NEXT:    li r5, 96
-; LINUX64LE-NEXT:    addi r3, r1, 32
 ; LINUX64LE-NEXT:    std r0, 160(r1)
-; LINUX64LE-NEXT:    addi r4, r4, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    lxvd2x vs0, r4, r5
-; LINUX64LE-NEXT:    stxvd2x vs0, r3, r5
-; LINUX64LE-NEXT:    li r5, 80
-; LINUX64LE-NEXT:    lxvd2x vs0, r4, r5
-; LINUX64LE-NEXT:    stxvd2x vs0, r3, r5
-; LINUX64LE-NEXT:    li r5, 64
-; LINUX64LE-NEXT:    lxvd2x vs0, r4, r5
-; LINUX64LE-NEXT:    stxvd2x vs0, r3, r5
-; LINUX64LE-NEXT:    li r5, 48
-; LINUX64LE-NEXT:    lxvd2x vs0, r4, r5
-; LINUX64LE-NEXT:    stxvd2x vs0, r3, r5
-; LINUX64LE-NEXT:    li r5, 32
-; LINUX64LE-NEXT:    lxvd2x vs0, r4, r5
-; LINUX64LE-NEXT:    stxvd2x vs0, r3, r5
-; LINUX64LE-NEXT:    li r5, 16
-; LINUX64LE-NEXT:    lxvd2x vs0, r4, r5
+; LINUX64LE-NEXT:    addi r6, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r1, 32
+; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
+; LINUX64LE-NEXT:    li r4, 120
 ; LINUX64LE-NEXT:    stxvd2x vs0, r3, r5
-; LINUX64LE-NEXT:    lxvd2x vs0, 0, r4
+; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
+; LINUX64LE-NEXT:    li r4, 80
+; LINUX64LE-NEXT:    stxvd2x vs0, r3, r4
+; LINUX64LE-NEXT:    li r4, 104
+; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
+; LINUX64LE-NEXT:    li r4, 64
+; LINUX64LE-NEXT:    stxvd2x vs0, r3, r4
+; LINUX64LE-NEXT:    li r4, 88
+; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
+; LINUX64LE-NEXT:    li r4, 48
+; LINUX64LE-NEXT:    stxvd2x vs0, r3, r4
+; LINUX64LE-NEXT:    li r4, 72
+; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
+; LINUX64LE-NEXT:    li r4, 32
+; LINUX64LE-NEXT:    stxvd2x vs0, r3, r4
+; LINUX64LE-NEXT:    li r4, 56
+; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
+; LINUX64LE-NEXT:    li r4, 16
+; LINUX64LE-NEXT:    stxvd2x vs0, r3, r4
+; LINUX64LE-NEXT:    li r4, 40
+; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
 ; LINUX64LE-NEXT:    stxvd2x vs0, 0, r3
 ; LINUX64LE-NEXT:    bl calleeInt
 ; LINUX64LE-NEXT:    nop
@@ -654,35 +660,35 @@ define dso_local signext i32 @array2() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -224(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64BE-NEXT:    li r4, 208
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64BE-NEXT:    li r4, 248
 ; LINUX64BE-NEXT:    li r5, 96
 ; LINUX64BE-NEXT:    std r0, 240(r1)
-; LINUX64BE-NEXT:    addi r6, r3, .L__ModuleStringPool at toc@l
+; LINUX64BE-NEXT:    addi r6, r3, .L_MergedGlobals at toc@l
 ; LINUX64BE-NEXT:    addi r3, r1, 112
 ; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
-; LINUX64BE-NEXT:    li r4, 192
+; LINUX64BE-NEXT:    li r4, 232
 ; LINUX64BE-NEXT:    stxvw4x vs0, r3, r5
 ; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
 ; LINUX64BE-NEXT:    li r4, 80
 ; LINUX64BE-NEXT:    stxvw4x vs0, r3, r4
-; LINUX64BE-NEXT:    li r4, 176
+; LINUX64BE-NEXT:    li r4, 216
 ; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
 ; LINUX64BE-NEXT:    li r4, 64
 ; LINUX64BE-NEXT:    stxvw4x vs0, r3, r4
-; LINUX64BE-NEXT:    li r4, 160
+; LINUX64BE-NEXT:    li r4, 200
 ; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
 ; LINUX64BE-NEXT:    li r4, 48
 ; LINUX64BE-NEXT:    stxvw4x vs0, r3, r4
-; LINUX64BE-NEXT:    li r4, 144
+; LINUX64BE-NEXT:    li r4, 184
 ; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
 ; LINUX64BE-NEXT:    li r4, 32
 ; LINUX64BE-NEXT:    stxvw4x vs0, r3, r4
-; LINUX64BE-NEXT:    li r4, 128
+; LINUX64BE-NEXT:    li r4, 168
 ; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
 ; LINUX64BE-NEXT:    li r4, 16
 ; LINUX64BE-NEXT:    stxvw4x vs0, r3, r4
-; LINUX64BE-NEXT:    li r4, 112
+; LINUX64BE-NEXT:    li r4, 152
 ; LINUX64BE-NEXT:    lxvw4x vs0, r6, r4
 ; LINUX64BE-NEXT:    stxvw4x vs0, 0, r3
 ; LINUX64BE-NEXT:    bl calleeInt
@@ -696,35 +702,35 @@ define dso_local signext i32 @array2() local_unnamed_addr #0 {
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
 ; LINUX64LE-NEXT:    stdu r1, -144(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64LE-NEXT:    li r4, 208
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    li r4, 248
 ; LINUX64LE-NEXT:    li r5, 96
 ; LINUX64LE-NEXT:    std r0, 160(r1)
-; LINUX64LE-NEXT:    addi r6, r3, .L__ModuleStringPool at toc@l
+; LINUX64LE-NEXT:    addi r6, r3, .L_MergedGlobals at toc@l
 ; LINUX64LE-NEXT:    addi r3, r1, 32
 ; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
-; LINUX64LE-NEXT:    li r4, 192
+; LINUX64LE-NEXT:    li r4, 232
 ; LINUX64LE-NEXT:    stxvd2x vs0, r3, r5
 ; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
 ; LINUX64LE-NEXT:    li r4, 80
 ; LINUX64LE-NEXT:    stxvd2x vs0, r3, r4
-; LINUX64LE-NEXT:    li r4, 176
+; LINUX64LE-NEXT:    li r4, 216
 ; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
 ; LINUX64LE-NEXT:    li r4, 64
 ; LINUX64LE-NEXT:    stxvd2x vs0, r3, r4
-; LINUX64LE-NEXT:    li r4, 160
+; LINUX64LE-NEXT:    li r4, 200
 ; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
 ; LINUX64LE-NEXT:    li r4, 48
 ; LINUX64LE-NEXT:    stxvd2x vs0, r3, r4
-; LINUX64LE-NEXT:    li r4, 144
+; LINUX64LE-NEXT:    li r4, 184
 ; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
 ; LINUX64LE-NEXT:    li r4, 32
 ; LINUX64LE-NEXT:    stxvd2x vs0, r3, r4
-; LINUX64LE-NEXT:    li r4, 128
+; LINUX64LE-NEXT:    li r4, 168
 ; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
 ; LINUX64LE-NEXT:    li r4, 16
 ; LINUX64LE-NEXT:    stxvd2x vs0, r3, r4
-; LINUX64LE-NEXT:    li r4, 112
+; LINUX64LE-NEXT:    li r4, 152
 ; LINUX64LE-NEXT:    lxvd2x vs0, r6, r4
 ; LINUX64LE-NEXT:    stxvd2x vs0, 0, r3
 ; LINUX64LE-NEXT:    bl calleeInt
@@ -791,17 +797,17 @@ define dso_local signext i32 @array3() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -288(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 304(r1)
-; LINUX64BE-NEXT:    std r30, 272(r1) # 8-byte Folded Spill
+; LINUX64BE-NEXT:    std r30, 272(r1)                        # 8-byte Folded Spill
 ; LINUX64BE-NEXT:    addi r30, r1, 112
 ; LINUX64BE-NEXT:    li r5, 160
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    addi r4, r3, 224
-; LINUX64BE-NEXT:    mr r3, r30
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r4, r3, 264
+; LINUX64BE-NEXT:    mr      r3, r30
 ; LINUX64BE-NEXT:    bl memcpy
 ; LINUX64BE-NEXT:    nop
-; LINUX64BE-NEXT:    mr r3, r30
+; LINUX64BE-NEXT:    mr      r3, r30
 ; LINUX64BE-NEXT:    bl calleeInt
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    ld r30, 272(r1) # 8-byte Folded Reload
@@ -813,23 +819,23 @@ define dso_local signext i32 @array3() local_unnamed_addr #0 {
 ; LINUX64LE-LABEL: array3:
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
-; LINUX64LE-NEXT:    std r30, -16(r1) # 8-byte Folded Spill
+; LINUX64LE-NEXT:    std r30, -16(r1)                        # 8-byte Folded Spill
 ; LINUX64LE-NEXT:    stdu r1, -208(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    addi r30, r1, 32
 ; LINUX64LE-NEXT:    li r5, 160
 ; LINUX64LE-NEXT:    std r0, 224(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r4, r3, 224
-; LINUX64LE-NEXT:    mr r3, r30
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r4, r3, 264
+; LINUX64LE-NEXT:    mr      r3, r30
 ; LINUX64LE-NEXT:    bl memcpy
 ; LINUX64LE-NEXT:    nop
-; LINUX64LE-NEXT:    mr r3, r30
+; LINUX64LE-NEXT:    mr      r3, r30
 ; LINUX64LE-NEXT:    bl calleeInt
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 208
 ; LINUX64LE-NEXT:    ld r0, 16(r1)
-; LINUX64LE-NEXT:    ld r30, -16(r1) # 8-byte Folded Reload
+; LINUX64LE-NEXT:    ld r30, -16(r1)                         # 8-byte Folded Reload
 ; LINUX64LE-NEXT:    mtlr r0
 ; LINUX64LE-NEXT:    blr
 entry:
@@ -890,17 +896,17 @@ define dso_local signext i32 @array4() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -448(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 464(r1)
-; LINUX64BE-NEXT:    std r30, 432(r1) # 8-byte Folded Spill
+; LINUX64BE-NEXT:    std r30, 432(r1)                        # 8-byte Folded Spill
 ; LINUX64BE-NEXT:    addi r30, r1, 112
 ; LINUX64BE-NEXT:    li r5, 320
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    addi r4, r3, 384
-; LINUX64BE-NEXT:    mr r3, r30
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r4, r3, 424
+; LINUX64BE-NEXT:    mr      r3, r30
 ; LINUX64BE-NEXT:    bl memcpy
 ; LINUX64BE-NEXT:    nop
-; LINUX64BE-NEXT:    mr r3, r30
+; LINUX64BE-NEXT:    mr      r3, r30
 ; LINUX64BE-NEXT:    bl calleeInt
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    ld r30, 432(r1) # 8-byte Folded Reload
@@ -913,20 +919,20 @@ define dso_local signext i32 @array4() local_unnamed_addr #0 {
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
 ; LINUX64LE-NEXT:    stdu r1, -368(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    std r0, 384(r1)
-; LINUX64LE-NEXT:    std r30, 352(r1) # 8-byte Folded Spill
+; LINUX64LE-NEXT:    std r30, 352(r1)                        # 8-byte Folded Spill
 ; LINUX64LE-NEXT:    addi r30, r1, 32
 ; LINUX64LE-NEXT:    li r5, 320
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r4, r3, 384
-; LINUX64LE-NEXT:    mr r3, r30
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r4, r3, 424
+; LINUX64LE-NEXT:    mr      r3, r30
 ; LINUX64LE-NEXT:    bl memcpy
 ; LINUX64LE-NEXT:    nop
-; LINUX64LE-NEXT:    mr r3, r30
+; LINUX64LE-NEXT:    mr      r3, r30
 ; LINUX64LE-NEXT:    bl calleeInt
 ; LINUX64LE-NEXT:    nop
-; LINUX64LE-NEXT:    ld r30, 352(r1) # 8-byte Folded Reload
+; LINUX64LE-NEXT:    ld r30, 352(r1)                         # 8-byte Folded Reload
 ; LINUX64LE-NEXT:    addi r1, r1, 368
 ; LINUX64LE-NEXT:    ld r0, 16(r1)
 ; LINUX64LE-NEXT:    mtlr r0
diff --git a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-pr92991.ll b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-pr92991.ll
index 4e9c69e5fe4cfc..06607a3eed34df 100644
--- a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-pr92991.ll
+++ b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-pr92991.ll
@@ -7,8 +7,8 @@
 define void @test(ptr %p, ptr %p2) {
 ; CHECK-LABEL: test:
 ; CHECK:       # %bb.0:
-; CHECK-NEXT:    addis 5, 2, .L__ModuleStringPool at toc@ha
-; CHECK-NEXT:    addi 5, 5, .L__ModuleStringPool at toc@l
+; CHECK-NEXT:    addis 5, 2, .L_MergedGlobals at toc@ha
+; CHECK-NEXT:    addi 5, 5, .L_MergedGlobals at toc@l
 ; CHECK-NEXT:    addi 6, 5, 12
 ; CHECK-NEXT:    std 6, 0(3)
 ; CHECK-NEXT:    addi 3, 5, 16
diff --git a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-tls.ll b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-tls.ll
index 1f2ee88ea7645c..d55763bd6b16f3 100644
--- a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-tls.ll
+++ b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-tls.ll
@@ -75,10 +75,9 @@ define void @print_tls_func() {
 ; LINUX64LE-NEXT:    addi r4, r3, a at tprel@l
 ; LINUX64LE-NEXT:    addis r3, r13, b at tprel@ha
 ; LINUX64LE-NEXT:    addi r5, r3, b at tprel@l
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64LE-NEXT:    addi r6, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r3, r6, 71
-; LINUX64LE-NEXT:    addi r6, r6, 56
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    addi r6, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r6, 72
 ; LINUX64LE-NEXT:    bl printf
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 96
@@ -95,7 +94,7 @@ define void @print_tls_func() {
 ; LINUX64BE-NEXT:    .cfi_offset lr, 16
 ; LINUX64BE-NEXT:    .cfi_offset r30, -16
 ; LINUX64BE-NEXT:    addis r3, r2, a at got@tlsld at ha
-; LINUX64BE-NEXT:    std r30, 112(r1) # 8-byte Folded Spill
+; LINUX64BE-NEXT:    std r30, 112(r1)                        # 8-byte Folded Spill
 ; LINUX64BE-NEXT:    addi r3, r3, a at got@tlsld at l
 ; LINUX64BE-NEXT:    bl __tls_get_addr(a at tlsld)
 ; LINUX64BE-NEXT:    nop
@@ -106,15 +105,14 @@ define void @print_tls_func() {
 ; LINUX64BE-NEXT:    bl __tls_get_addr(b at tlsld)
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addis r3, r3, b at dtprel@ha
+; LINUX64BE-NEXT:    mr      r4, r30
 ; LINUX64BE-NEXT:    addi r5, r3, b at dtprel@l
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64BE-NEXT:    addi r4, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    addi r3, r4, 71
-; LINUX64BE-NEXT:    addi r6, r4, 56
-; LINUX64BE-NEXT:    mr r4, r30
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64BE-NEXT:    addi r6, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r6, 72
 ; LINUX64BE-NEXT:    bl printf
 ; LINUX64BE-NEXT:    nop
-; LINUX64BE-NEXT:    ld r30, 112(r1) # 8-byte Folded Reload
+; LINUX64BE-NEXT:    ld r30, 112(r1)                         # 8-byte Folded Reload
 ; LINUX64BE-NEXT:    addi r1, r1, 128
 ; LINUX64BE-NEXT:    ld r0, 16(r1)
 ; LINUX64BE-NEXT:    mtlr r0
@@ -154,7 +152,6 @@ define void @test_func() {
 ; CHECK32-NEXT:    lwz r0, 8(r1)
 ; CHECK32-NEXT:    mtlr r0
 ; CHECK32-NEXT:    blr
-;
 ; LINUX64LE-LABEL: test_func:
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
@@ -162,9 +159,9 @@ define void @test_func() {
 ; LINUX64LE-NEXT:    std r0, 48(r1)
 ; LINUX64LE-NEXT:    .cfi_def_cfa_offset 32
 ; LINUX64LE-NEXT:    .cfi_offset lr, 16
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r3, r3, 16
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, 32
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 32
@@ -179,9 +176,9 @@ define void @test_func() {
 ; LINUX64BE-NEXT:    std r0, 128(r1)
 ; LINUX64BE-NEXT:    .cfi_def_cfa_offset 112
 ; LINUX64BE-NEXT:    .cfi_offset lr, 16
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    addi r3, r3, 16
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, 32
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addi r1, r1, 112
@@ -229,8 +226,9 @@ define void @test_func2() {
 ; LINUX64LE-NEXT:    std r0, 48(r1)
 ; LINUX64LE-NEXT:    .cfi_def_cfa_offset 32
 ; LINUX64LE-NEXT:    .cfi_offset lr, 16
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, 16
 ; LINUX64LE-NEXT:    bl callee2
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 32
@@ -245,8 +243,9 @@ define void @test_func2() {
 ; LINUX64BE-NEXT:    std r0, 128(r1)
 ; LINUX64BE-NEXT:    .cfi_def_cfa_offset 112
 ; LINUX64BE-NEXT:    .cfi_offset lr, 16
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, 16
 ; LINUX64BE-NEXT:    bl callee2
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addi r1, r1, 112
@@ -332,49 +331,51 @@ entry:
 ; CHECK32-NEXT:	.tc b[TC],b[TL]@ld
 
 ; LINUX64LE: a:
-; LINUX64LE-NEXT:	.asciz	"tls1"
-; LINUX64LE-NEXT:	.size	a, 5
+; LINUX64LE-NEXT:       .asciz  "tls1"
+; LINUX64LE-NEXT:       .size   a, 5
 ; LINUX64LE: b:
-; LINUX64LE-NEXT:	.asciz	"tls2"
-; LINUX64LE-NEXT:	.size	b, 5
-; LINUX64LE: .L__ModuleStringPool:
-; LINUX64LE-NEXT:	.long	0x42af999a
-; LINUX64LE-NEXT:	.long	0x42b1999a
-; LINUX64LE-NEXT:	.long	0x42b3cccd
-; LINUX64LE-NEXT:	.long	0x42b5999a
-; LINUX64LE-NEXT:	.long	1
-; LINUX64LE-NEXT:	.long	2
-; LINUX64LE-NEXT:	.long	3
-; LINUX64LE-NEXT:	.long	4
-; LINUX64LE-NEXT:	.long	5
-; LINUX64LE-NEXT:	.long	6
-; LINUX64LE-NEXT:	.long	7
-; LINUX64LE-NEXT:	.long	8
-; LINUX64LE-NEXT:	.long	9
-; LINUX64LE-NEXT:	.long	10
-; LINUX64LE-NEXT:	.asciz	"Regular global"
-; LINUX64LE-NEXT:	.asciz	"TLS variable 1, 2 and non-TLS var: %s, %s, %s\n"
+; LINUX64LE-NEXT:       .asciz  "tls2"
+; LINUX64LE-NEXT:       .size   b, 5
+; LINUX64LE: .L_MergedGlobals:
+; LINUX64LE-NEXT:       .asciz  "Regular global"
+; LINUX64LE-NEXT:       .space  1
+; LINUX64LE-NEXT:       .long   0x42af999a
+; LINUX64LE-NEXT:       .long   0x42b1999a
+; LINUX64LE-NEXT:       .long   0x42b3cccd
+; LINUX64LE-NEXT:       .long   0x42b5999a
+; LINUX64LE-NEXT:       .long   1
+; LINUX64LE-NEXT:       .long   2
+; LINUX64LE-NEXT:       .long   3
+; LINUX64LE-NEXT:       .long   4
+; LINUX64LE-NEXT:       .long   5
+; LINUX64LE-NEXT:       .long   6
+; LINUX64LE-NEXT:       .long   7
+; LINUX64LE-NEXT:       .long   8
+; LINUX64LE-NEXT:       .long   9
+; LINUX64LE-NEXT:       .long   10
+; LINUX64LE-NEXT:       .asciz  "TLS variable 1, 2 and non-TLS var: %s, %s, %s\n"
 
 ; LINUX64BE: a:
-; LINUX64BE-NEXT:	.asciz	"tls1"
-; LINUX64BE-NEXT:	.size	a, 5
+; LINUX64BE-NEXT:       .asciz  "tls1"
+; LINUX64BE-NEXT:       .size   a, 5
 ; LINUX64BE: b:
-; LINUX64BE-NEXT:	.asciz	"tls2"
-; LINUX64BE-NEXT:	.size	b, 5
-; LINUX64BE: .L__ModuleStringPool:
-; LINUX64BE-NEXT:	.long	0x42af999a
-; LINUX64BE-NEXT:	.long	0x42b1999a
-; LINUX64BE-NEXT:	.long	0x42b3cccd
-; LINUX64BE-NEXT:	.long	0x42b5999a
-; LINUX64BE-NEXT:	.long	1
-; LINUX64BE-NEXT:	.long	2
-; LINUX64BE-NEXT:	.long	3
-; LINUX64BE-NEXT:	.long	4
-; LINUX64BE-NEXT:	.long	5
-; LINUX64BE-NEXT:	.long	6
-; LINUX64BE-NEXT:	.long	7
-; LINUX64BE-NEXT:	.long	8
-; LINUX64BE-NEXT:	.long	9
-; LINUX64BE-NEXT:	.long	10
-; LINUX64BE-NEXT:	.asciz	"Regular global"
-; LINUX64BE-NEXT:	.asciz	"TLS variable 1, 2 and non-TLS var: %s, %s, %s\n"
+; LINUX64BE-NEXT:       .asciz  "tls2"
+; LINUX64BE-NEXT:       .size   b, 5
+; LINUX64BE: .L_MergedGlobals:
+; LINUX64BE-NEXT:       .asciz  "Regular global"
+; LINUX64BE-NEXT:       .space  1
+; LINUX64BE-NEXT:       .long   0x42af999a
+; LINUX64BE-NEXT:       .long   0x42b1999a
+; LINUX64BE-NEXT:       .long   0x42b3cccd
+; LINUX64BE-NEXT:       .long   0x42b5999a
+; LINUX64BE-NEXT:       .long   1
+; LINUX64BE-NEXT:       .long   2
+; LINUX64BE-NEXT:       .long   3
+; LINUX64BE-NEXT:       .long   4
+; LINUX64BE-NEXT:       .long   5
+; LINUX64BE-NEXT:       .long   6
+; LINUX64BE-NEXT:       .long   7
+; LINUX64BE-NEXT:       .long   8
+; LINUX64BE-NEXT:       .long   9
+; LINUX64BE-NEXT:       .long   10
+; LINUX64BE-NEXT:       .asciz  "TLS variable 1, 2 and non-TLS var: %s, %s, %s\n"
diff --git a/llvm/test/CodeGen/PowerPC/mergeable-string-pool.ll b/llvm/test/CodeGen/PowerPC/mergeable-string-pool.ll
index 2a937806f4bbfd..6a21a100bb9908 100644
--- a/llvm/test/CodeGen/PowerPC/mergeable-string-pool.ll
+++ b/llvm/test/CodeGen/PowerPC/mergeable-string-pool.ll
@@ -68,10 +68,10 @@ define dso_local signext i32 @str1() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -112(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 128(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    addi r3, r3, 422
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, 20
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addi r1, r1, 112
@@ -83,10 +83,10 @@ define dso_local signext i32 @str1() local_unnamed_addr #0 {
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
 ; LINUX64LE-NEXT:    stdu r1, -32(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    std r0, 48(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r3, r3, 422
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, 20
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 32
@@ -133,10 +133,10 @@ define dso_local signext i32 @str2() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -112(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 128(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    addi r3, r3, 388
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, 32
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addi r1, r1, 112
@@ -148,10 +148,10 @@ define dso_local signext i32 @str2() local_unnamed_addr #0 {
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
 ; LINUX64LE-NEXT:    stdu r1, -32(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    std r0, 48(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r3, r3, 388
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, 32
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 32
@@ -215,16 +215,16 @@ define dso_local signext i32 @str3() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -144(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 160(r1)
 ; LINUX64BE-NEXT:    std r29, 120(r1) # 8-byte Folded Spill
-; LINUX64BE-NEXT:    addi r29, r3, .L__ModuleStringPool at toc@l
+; LINUX64BE-NEXT:    addi r29, r3, .L_MergedGlobals at toc@l
 ; LINUX64BE-NEXT:    std r30, 128(r1) # 8-byte Folded Spill
-; LINUX64BE-NEXT:    addi r3, r29, 434
+; LINUX64BE-NEXT:    addi r3, r29, 44
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    mr r30, r3
-; LINUX64BE-NEXT:    addi r3, r29, 388
+; LINUX64BE-NEXT:    addi r3, r29, 32
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    add r3, r3, r30
@@ -242,14 +242,14 @@ define dso_local signext i32 @str3() local_unnamed_addr #0 {
 ; LINUX64LE-NEXT:    std r29, -24(r1) # 8-byte Folded Spill
 ; LINUX64LE-NEXT:    std r30, -16(r1) # 8-byte Folded Spill
 ; LINUX64LE-NEXT:    stdu r1, -64(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    std r0, 80(r1)
-; LINUX64LE-NEXT:    addi r29, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r3, r29, 434
+; LINUX64LE-NEXT:    addi r29, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r29, 44
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    mr r30, r3
-; LINUX64LE-NEXT:    addi r3, r29, 388
+; LINUX64LE-NEXT:    addi r3, r29, 32
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    add r3, r3, r30
@@ -300,10 +300,10 @@ define dso_local signext i32 @str4() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -112(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 128(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    addi r3, r3, 446
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, 56
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addi r1, r1, 112
@@ -315,10 +315,10 @@ define dso_local signext i32 @str4() local_unnamed_addr #0 {
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
 ; LINUX64LE-NEXT:    stdu r1, -32(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    std r0, 48(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r3, r3, 446
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, 56
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 32
@@ -363,10 +363,10 @@ define dso_local signext i32 @str5() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -112(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 128(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    addi r3, r3, 493
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, 736
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addi r1, r1, 112
@@ -378,10 +378,10 @@ define dso_local signext i32 @str5() local_unnamed_addr #0 {
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
 ; LINUX64LE-NEXT:    stdu r1, -32(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    std r0, 48(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r3, r3, 493
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, 736
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 32
@@ -441,14 +441,14 @@ define dso_local signext i32 @array1() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -144(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64BE-NEXT:    li r4, 372
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64BE-NEXT:    li r4, 308
 ; LINUX64BE-NEXT:    std r0, 160(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
 ; LINUX64BE-NEXT:    lxvw4x vs0, r3, r4
 ; LINUX64BE-NEXT:    addi r4, r1, 124
 ; LINUX64BE-NEXT:    stxvw4x vs0, 0, r4
-; LINUX64BE-NEXT:    li r4, 360
+; LINUX64BE-NEXT:    li r4, 296
 ; LINUX64BE-NEXT:    lxvw4x vs0, r3, r4
 ; LINUX64BE-NEXT:    addi r3, r1, 112
 ; LINUX64BE-NEXT:    stxvw4x vs0, 0, r3
@@ -463,14 +463,14 @@ define dso_local signext i32 @array1() local_unnamed_addr #0 {
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
 ; LINUX64LE-NEXT:    stdu r1, -64(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64LE-NEXT:    li r4, 372
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    li r4, 308
 ; LINUX64LE-NEXT:    std r0, 80(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
 ; LINUX64LE-NEXT:    lxvd2x vs0, r3, r4
 ; LINUX64LE-NEXT:    addi r4, r1, 44
 ; LINUX64LE-NEXT:    stxvd2x vs0, 0, r4
-; LINUX64LE-NEXT:    li r4, 360
+; LINUX64LE-NEXT:    li r4, 296
 ; LINUX64LE-NEXT:    lxvd2x vs0, r3, r4
 ; LINUX64LE-NEXT:    addi r3, r1, 32
 ; LINUX64LE-NEXT:    stxvd2x vs0, 0, r3
@@ -711,9 +711,9 @@ define dso_local signext i32 @str7() local_unnamed_addr #0 {
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    mr r30, r3
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    addi r3, r3, 458
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, 80
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    add r3, r3, r30
@@ -735,9 +735,9 @@ define dso_local signext i32 @str7() local_unnamed_addr #0 {
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    mr r30, r3
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r3, r3, 458
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, 80
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    add r3, r3, r30
@@ -810,9 +810,9 @@ define dso_local signext i32 @mixed1() local_unnamed_addr #0 {
 ; LINUX64BE-NEXT:    bl calleeInt
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    mr r30, r3
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64BE-NEXT:    addi r3, r3, 400
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, 68
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    add r3, r3, r30
@@ -834,9 +834,9 @@ define dso_local signext i32 @mixed1() local_unnamed_addr #0 {
 ; LINUX64LE-NEXT:    bl calleeInt
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    mr r30, r3
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool at toc@l
-; LINUX64LE-NEXT:    addi r3, r3, 400
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, 68
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    add r3, r3, r30
@@ -936,16 +936,16 @@ define dso_local signext i32 @mixed2() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -176(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 192(r1)
 ; LINUX64BE-NEXT:    std r29, 152(r1) # 8-byte Folded Spill
-; LINUX64BE-NEXT:    li r4, 372
+; LINUX64BE-NEXT:    li r4, 308
 ; LINUX64BE-NEXT:    std r30, 160(r1) # 8-byte Folded Spill
-; LINUX64BE-NEXT:    addi r29, r3, .L__ModuleStringPool at toc@l
+; LINUX64BE-NEXT:    addi r29, r3, .L_MergedGlobals at toc@l
 ; LINUX64BE-NEXT:    addi r3, r1, 124
 ; LINUX64BE-NEXT:    lxvw4x vs0, r29, r4
 ; LINUX64BE-NEXT:    stxvw4x vs0, 0, r3
-; LINUX64BE-NEXT:    li r3, 360
+; LINUX64BE-NEXT:    li r3, 296
 ; LINUX64BE-NEXT:    lxvw4x vs0, r29, r3
 ; LINUX64BE-NEXT:    addi r3, r1, 112
 ; LINUX64BE-NEXT:    stxvw4x vs0, 0, r3
@@ -957,11 +957,11 @@ define dso_local signext i32 @mixed2() local_unnamed_addr #0 {
 ; LINUX64BE-NEXT:    bl calleeInt
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    add r30, r3, r30
-; LINUX64BE-NEXT:    addi r3, r29, 400
+; LINUX64BE-NEXT:    addi r3, r29, 68
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    add r30, r30, r3
-; LINUX64BE-NEXT:    addi r3, r29, 473
+; LINUX64BE-NEXT:    addi r3, r29, 273
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    add r3, r30, r3
@@ -979,14 +979,14 @@ define dso_local signext i32 @mixed2() local_unnamed_addr #0 {
 ; LINUX64LE-NEXT:    std r29, -24(r1) # 8-byte Folded Spill
 ; LINUX64LE-NEXT:    std r30, -16(r1) # 8-byte Folded Spill
 ; LINUX64LE-NEXT:    stdu r1, -96(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L__ModuleStringPool at toc@ha
-; LINUX64LE-NEXT:    li r4, 372
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    li r4, 308
 ; LINUX64LE-NEXT:    std r0, 112(r1)
-; LINUX64LE-NEXT:    addi r29, r3, .L__ModuleStringPool at toc@l
+; LINUX64LE-NEXT:    addi r29, r3, .L_MergedGlobals at toc@l
 ; LINUX64LE-NEXT:    addi r3, r1, 44
 ; LINUX64LE-NEXT:    lxvd2x vs0, r29, r4
 ; LINUX64LE-NEXT:    stxvd2x vs0, 0, r3
-; LINUX64LE-NEXT:    li r3, 360
+; LINUX64LE-NEXT:    li r3, 296
 ; LINUX64LE-NEXT:    lxvd2x vs0, r29, r3
 ; LINUX64LE-NEXT:    addi r3, r1, 32
 ; LINUX64LE-NEXT:    stxvd2x vs0, 0, r3
@@ -998,11 +998,11 @@ define dso_local signext i32 @mixed2() local_unnamed_addr #0 {
 ; LINUX64LE-NEXT:    bl calleeInt
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    add r30, r3, r30
-; LINUX64LE-NEXT:    addi r3, r29, 400
+; LINUX64LE-NEXT:    addi r3, r29, 68
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    add r30, r30, r3
-; LINUX64LE-NEXT:    addi r3, r29, 473
+; LINUX64LE-NEXT:    addi r3, r29, 273
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    add r3, r30, r3
@@ -1061,9 +1061,10 @@ define dso_local signext i32 @str9() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -112(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L.str.9 at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 128(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L.str.9 at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, 128
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addi r1, r1, 112
@@ -1075,9 +1076,10 @@ define dso_local signext i32 @str9() local_unnamed_addr #0 {
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
 ; LINUX64LE-NEXT:    stdu r1, -32(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L.str.9 at toc@ha
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    std r0, 48(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L.str.9 at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, 128
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 32
@@ -1122,9 +1124,10 @@ define dso_local signext i32 @str10() local_unnamed_addr #0 {
 ; LINUX64BE:       # %bb.0: # %entry
 ; LINUX64BE-NEXT:    mflr r0
 ; LINUX64BE-NEXT:    stdu r1, -112(r1)
-; LINUX64BE-NEXT:    addis r3, r2, .L.str.10 at toc@ha
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 128(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L.str.10 at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64BE-NEXT:    addi r3, r3, 256
 ; LINUX64BE-NEXT:    bl callee
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addi r1, r1, 112
@@ -1136,9 +1139,10 @@ define dso_local signext i32 @str10() local_unnamed_addr #0 {
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
 ; LINUX64LE-NEXT:    stdu r1, -32(r1)
-; LINUX64LE-NEXT:    addis r3, r2, .L.str.10 at toc@ha
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    std r0, 48(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L.str.10 at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    addi r3, r3, 256
 ; LINUX64LE-NEXT:    bl callee
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 32
@@ -1173,20 +1177,23 @@ attributes #0 = { nounwind }
 ; AIXDATA:       .vbyte  4, 32                           # 0x20
 ; AIXDATA:       .string "longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_STRING"
 
-; LINUXDATA: .L__ModuleStringPool:
-; LINUXDATA:    .long	5                               # 0x5
-; LINUXDATA:    .long	7                               # 0x7
-; LINUXDATA:    .long	9                               # 0x9
-; LINUXDATA:    .long	11                              # 0xb
-; LINUXDATA:    .long	17                              # 0x11
-; LINUXDATA:    .long	1235                            # 0x4d3
-; LINUXDATA:    .long	32                              # 0x20
-; LINUXDATA:    .asciz	"str2_STRING"
-; LINUXDATA:    .asciz	"MixedString"
-; LINUXDATA:    .asciz	"ABCABCABC"
-; LINUXDATA:    .asciz	"str1_STRING"
-; LINUXDATA:    .asciz	"str3_STRING"
-; LINUXDATA:    .asciz	"str4_STRING"
-; LINUXDATA:    .asciz	"Static Global\n"
-; LINUXDATA:    .asciz	"Different String 01"
-; LINUXDATA:    .asciz	"longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_STRING"
+; LINUXDATA: .L_MergedGlobals:
+; LINUXDATA:    .asciz  "ABCABCABC"
+; LINUXDATA:    .asciz  "str1_STRING"
+; LINUXDATA:    .asciz  "str2_STRING"
+; LINUXDATA:    .asciz  "str3_STRING"
+; LINUXDATA:    .asciz  "str4_STRING"
+; LINUXDATA:    .asciz  "MixedString"
+; LINUXDATA:    .asciz  "Static Global\n"
+; LINUXDATA:    .asciz  "str9_STRING....."
+; LINUXDATA:    .asciz  "str10_STRING...."
+; LINUXDATA:    .asciz  "Different String 01"
+; LINUXDATA:    .long   5                               # 0x5
+; LINUXDATA:    .long   7                               # 0x7
+; LINUXDATA:    .long   9                               # 0x9
+; LINUXDATA:    .long   11                              # 0xb
+; LINUXDATA:    .long   17                              # 0x11
+; LINUXDATA:    .long   1235                            # 0x4d3
+; LINUXDATA:    .long   32                              # 0x20
+; LINUXDATA:    .asciz  "This is the global string that is at the top.\n"
+; LINUXDATA:    .asciz  "longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_longerstr5_STRING"
diff --git a/llvm/test/CodeGen/PowerPC/toc-load-sched-bug.ll b/llvm/test/CodeGen/PowerPC/toc-load-sched-bug.ll
index c2c90864bb7f5f..74187672128c63 100644
--- a/llvm/test/CodeGen/PowerPC/toc-load-sched-bug.ll
+++ b/llvm/test/CodeGen/PowerPC/toc-load-sched-bug.ll
@@ -164,8 +164,8 @@ entry:
 ; CHECK: .globl	_ZN4llvm11ParseIRFileERKSsRNS_12SMDiagnosticERNS_11LLVMContextE
 ; CHECK: bctrl
 ; CHECK: ld 2, 24(1)
-; CHECK: addis [[REG:[0-9]+]], 2, .L__ModuleStringPool at toc@ha
-; CHECK: addi {{[0-9]+}}, [[REG]], .L__ModuleStringPool at toc@l
+; CHECK: addis [[REG:[0-9]+]], 2, .L_MergedGlobals at toc@ha
+; CHECK: addi {{[0-9]+}}, [[REG]], .L_MergedGlobals at toc@l
 ; CHECK: bl _ZNSs6insertEmPKcm
   %.atomicdst.i.i.i.i.i46 = alloca i32, align 4
   %ref.tmp.i.i47 = alloca %"class.std::allocator", align 1

>From 81df2283c9c391ca29a6ce6740cd26d92d87e229 Mon Sep 17 00:00:00 2001
From: Zaara Syeda <syzaara at ca.ibm.com>
Date: Wed, 6 Nov 2024 20:55:20 +0000
Subject: [PATCH 2/4] Address review comments

---
 llvm/lib/CodeGen/GlobalMerge.cpp              |  17 +-
 llvm/lib/Target/PowerPC/CMakeLists.txt        |   1 -
 llvm/lib/Target/PowerPC/PPC.h                 |   2 -
 .../lib/Target/PowerPC/PPCMergeStringPool.cpp | 334 ------------------
 llvm/lib/Target/PowerPC/PPCTargetMachine.cpp  |   1 -
 .../PowerPC/merge-string-used-by-metadata.mir |  52 ---
 .../PowerPC/mergeable-string-pool-large.ll    |  88 ++---
 .../mergeable-string-pool-pass-only.mir       | 114 ------
 .../PowerPC/mergeable-string-pool-tls.ll      |   7 +-
 .../llvm/lib/Target/PowerPC/BUILD.gn          |   1 -
 10 files changed, 57 insertions(+), 560 deletions(-)
 delete mode 100644 llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
 delete mode 100644 llvm/test/CodeGen/PowerPC/merge-string-used-by-metadata.mir
 delete mode 100644 llvm/test/CodeGen/PowerPC/mergeable-string-pool-pass-only.mir

diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index 30f44e3d61d8b1..a4070de8489830 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -716,15 +716,16 @@ bool GlobalMergeImpl::run(Module &M) {
       continue;
     auto checkUsers = [] (const GlobalVariable *GV) {
       for (const User *CurrentUser : GV->users()) {
-        if (auto *I = dyn_cast<Instruction>(CurrentUser)) {
-          // Do not merge globals in exception pads.
-          if (I->isEHPad())
+        auto *I = dyn_cast<Instruction>(CurrentUser);
+        if (!I)
+          continue;
+        // Do not merge globals in exception pads.
+        if (I->isEHPad())
+          return false;
+        if (auto *II = dyn_cast<IntrinsicInst>(I)) {
+          // Some intrinsics require a plain global.
+          if (II->getIntrinsicID() == Intrinsic::eh_typeid_for)
             return false;
-          if (auto *II = dyn_cast<IntrinsicInst>(I)) {
-            // Some intrinsics require a plain global.
-            if (II->getIntrinsicID() == Intrinsic::eh_typeid_for)
-              return false;
-          }
         }
       }
       return true;
diff --git a/llvm/lib/Target/PowerPC/CMakeLists.txt b/llvm/lib/Target/PowerPC/CMakeLists.txt
index cd4c76013d2041..8f7b53b622065d 100644
--- a/llvm/lib/Target/PowerPC/CMakeLists.txt
+++ b/llvm/lib/Target/PowerPC/CMakeLists.txt
@@ -41,7 +41,6 @@ add_llvm_target(PowerPCCodeGen
   PPCMachineFunctionInfo.cpp
   PPCMachineScheduler.cpp
   PPCMacroFusion.cpp
-  PPCMergeStringPool.cpp
   PPCMIPeephole.cpp
   PPCRegisterInfo.cpp
   PPCSubtarget.cpp
diff --git a/llvm/lib/Target/PowerPC/PPC.h b/llvm/lib/Target/PowerPC/PPC.h
index 94a59d14601b2a..acd111d8824b4d 100644
--- a/llvm/lib/Target/PowerPC/PPC.h
+++ b/llvm/lib/Target/PowerPC/PPC.h
@@ -53,7 +53,6 @@ class ModulePass;
   FunctionPass *createPPCPreEmitPeepholePass();
   FunctionPass *createPPCExpandAtomicPseudoPass();
   FunctionPass *createPPCCTRLoopsPass();
-  ModulePass *createPPCMergeStringPoolPass();
   void LowerPPCMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,
                                     AsmPrinter &AP);
   bool LowerPPCMachineOperandToMCOperand(const MachineOperand &MO,
@@ -79,7 +78,6 @@ class ModulePass;
   void initializePPCExpandAtomicPseudoPass(PassRegistry &);
   void initializePPCCTRLoopsPass(PassRegistry &);
   void initializePPCDAGToDAGISelLegacyPass(PassRegistry &);
-  void initializePPCMergeStringPoolPass(PassRegistry &);
 
   extern char &PPCVSXFMAMutateID;
 
diff --git a/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp b/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
deleted file mode 100644
index daf6a0e65d54b2..00000000000000
--- a/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp
+++ /dev/null
@@ -1,334 +0,0 @@
-//===-- PPCMergeStringPool.cpp -------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This transformation tries to merge the strings in the module into one pool
-// of strings. The idea is to reduce the number of TOC entries in the module so
-// that instead of having one TOC entry for each string there is only one global
-// TOC entry and all of the strings are referenced off of that one entry plus
-// an offset.
-//
-//===----------------------------------------------------------------------===//
-
-#include "PPC.h"
-#include "llvm/ADT/Statistic.h"
-#include "llvm/Analysis/DomTreeUpdater.h"
-#include "llvm/Analysis/LoopInfo.h"
-#include "llvm/Analysis/LoopIterator.h"
-#include "llvm/Analysis/ScalarEvolution.h"
-#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
-#include "llvm/IR/Constants.h"
-#include "llvm/IR/Instructions.h"
-#include "llvm/IR/IntrinsicInst.h"
-#include "llvm/IR/Module.h"
-#include "llvm/IR/ValueSymbolTable.h"
-#include "llvm/Pass.h"
-#include "llvm/Support/CommandLine.h"
-
-#define DEBUG_TYPE "ppc-merge-strings"
-
-STATISTIC(NumPooledStrings, "Number of Strings Pooled");
-
-using namespace llvm;
-
-static cl::opt<unsigned>
-    MaxStringsPooled("ppc-max-strings-pooled", cl::Hidden, cl::init(-1),
-                     cl::desc("Maximum Number of Strings to Pool."));
-
-static cl::opt<unsigned>
-    MinStringsBeforePool("ppc-min-strings-before-pool", cl::Hidden, cl::init(2),
-                         cl::desc("Minimum number of string candidates before "
-				  "pooling is considered."));
-
-namespace {
-struct {
-  bool operator()(const GlobalVariable *LHS, const GlobalVariable *RHS) const {
-    // First priority is alignment.
-    // If elements are sorted in terms of alignment then there won't be an
-    // issue with incorrect alignment that would require padding.
-    Align LHSAlign = LHS->getAlign().valueOrOne();
-    Align RHSAlign = RHS->getAlign().valueOrOne();
-    if (LHSAlign > RHSAlign)
-      return true;
-    else if (LHSAlign < RHSAlign)
-      return false;
-
-    // Next priority is the number of uses.
-    // Smaller offsets are easier to materialize because materializing a large
-    // offset may require more than one instruction. (ie addis, addi).
-    if (LHS->getNumUses() > RHS->getNumUses())
-      return true;
-    else if (LHS->getNumUses() < RHS->getNumUses())
-      return false;
-
-    const Constant *ConstLHS = LHS->getInitializer();
-    const ConstantDataSequential *ConstDataLHS =
-        dyn_cast<ConstantDataSequential>(ConstLHS);
-    unsigned LHSSize =
-        ConstDataLHS->getNumElements() * ConstDataLHS->getElementByteSize();
-    const Constant *ConstRHS = RHS->getInitializer();
-    const ConstantDataSequential *ConstDataRHS =
-        dyn_cast<ConstantDataSequential>(ConstRHS);
-    unsigned RHSSize =
-        ConstDataRHS->getNumElements() * ConstDataRHS->getElementByteSize();
-
-    // Finally smaller constants should go first. This is, again, trying to
-    // minimize the offsets into the final struct.
-    return LHSSize < RHSSize;
-  }
-} CompareConstants;
-
-class PPCMergeStringPool : public ModulePass {
-public:
-  static char ID;
-  PPCMergeStringPool() : ModulePass(ID) {}
-
-  bool doInitialization(Module &M) override { return mergeModuleStringPool(M); }
-  bool runOnModule(Module &M) override { return false; }
-
-  StringRef getPassName() const override { return "PPC Merge String Pool"; }
-
-  void getAnalysisUsage(AnalysisUsage &AU) const override {
-    AU.addPreserved<DominatorTreeWrapperPass>();
-    AU.addPreserved<LoopInfoWrapperPass>();
-    AU.addPreserved<ScalarEvolutionWrapperPass>();
-    AU.addPreserved<SCEVAAWrapperPass>();
-  }
-
-private:
-  // Globals in a Module are already unique so a set is not required and a
-  // vector will do.
-  std::vector<GlobalVariable *> MergeableStrings;
-  Align MaxAlignment;
-  Type *PooledStructType;
-  LLVMContext *Context;
-  void collectCandidateConstants(Module &M);
-  bool mergeModuleStringPool(Module &M);
-  void replaceUsesWithGEP(GlobalVariable *GlobalToReplace, GlobalVariable *GPool,
-                          unsigned ElementIndex);
-};
-
-
-// In order for a constant to be pooled we need to be able to replace all of
-// the uses for that constant. This function checks all of the uses to make
-// sure that they can be replaced.
-static bool hasReplaceableUsers(GlobalVariable &GV) {
-  for (User *CurrentUser : GV.users()) {
-    if (auto *I = dyn_cast<Instruction>(CurrentUser)) {
-      // Do not merge globals in exception pads.
-      if (I->isEHPad())
-        return false;
-
-      if (auto *II = dyn_cast<IntrinsicInst>(I)) {
-        // Some intrinsics require a plain global.
-        if (II->getIntrinsicID() == Intrinsic::eh_typeid_for)
-          return false;
-      }
-
-      // Other instruction users are always valid.
-      continue;
-    }
-
-    // We cannot replace GlobalValue users because they are not just nodes
-    // in IR. To replace a user like this we would need to create a new
-    // GlobalValue with the replacement and then try to delete the original
-    // GlobalValue. Deleting the original would only happen if it has no other
-    // uses.
-    if (isa<GlobalValue>(CurrentUser))
-      return false;
-
-    // We only support Instruction and Constant users.
-    if (!isa<Constant>(CurrentUser))
-      return false;
-  }
-
-  return true;
-}
-
-// Run through all of the constants in the module and determine if they are
-// valid candidates to be merged into the string pool. Valid candidates will
-// be added to MergeableStrings.
-void PPCMergeStringPool::collectCandidateConstants(Module &M) {
-  SmallVector<GlobalValue *, 4> UsedV;
-  collectUsedGlobalVariables(M, UsedV, /*CompilerUsed=*/false);
-  SmallVector<GlobalValue *, 4> UsedVCompiler;
-  collectUsedGlobalVariables(M, UsedVCompiler, /*CompilerUsed=*/true);
-  // Combine all of the Global Variables marked as used into a SmallPtrSet for
-  // faster lookup inside the loop.
-  SmallPtrSet<GlobalValue *, 8> AllUsedGlobals;
-  AllUsedGlobals.insert(UsedV.begin(), UsedV.end());
-  AllUsedGlobals.insert(UsedVCompiler.begin(), UsedVCompiler.end());
-
-  for (GlobalVariable &Global : M.globals()) {
-    LLVM_DEBUG(dbgs() << "Looking at global:");
-    LLVM_DEBUG(Global.dump());
-    LLVM_DEBUG(dbgs() << "isConstant() " << Global.isConstant() << "\n");
-    LLVM_DEBUG(dbgs() << "hasInitializer() " << Global.hasInitializer()
-                      << "\n");
-
-    // We can only pool non-thread-local constants.
-    if (!Global.isConstant() || !Global.hasInitializer() ||
-        Global.isThreadLocal())
-      continue;
-
-    // If a global constant has a section we do not try to pool it because
-    // there is no guarantee that other constants will also be in the same
-    // section. Trying to pool constants from different sections (or no
-    // section) means that the pool has to be in multiple sections at the same
-    // time.
-    if (Global.hasSection())
-      continue;
-
-    // Do not pool constants with metadata because we should not add metadata
-    // to the pool when that metadata refers to a single constant in the pool.
-    if (Global.hasMetadata())
-      continue;
-
-    ConstantDataSequential *ConstData =
-        dyn_cast<ConstantDataSequential>(Global.getInitializer());
-
-    // If the constant is undef then ConstData will be null.
-    if (!ConstData)
-      continue;
-
-    // Do not pool globals that are part of llvm.used or llvm.compiler.end.
-    if (AllUsedGlobals.contains(&Global))
-      continue;
-
-    if (!hasReplaceableUsers(Global))
-      continue;
-
-    Align AlignOfGlobal = Global.getAlign().valueOrOne();
-
-    // TODO: At this point do not allow over-aligned types. Adding a type
-    //       with larger alignment may lose the larger alignment once it is
-    //       added to the struct.
-    //       Fix this in a future patch.
-    if (AlignOfGlobal.value() > ConstData->getElementByteSize())
-      continue;
-
-    // Make sure that the global is only visible inside the compilation unit.
-    if (Global.getLinkage() != GlobalValue::PrivateLinkage &&
-        Global.getLinkage() != GlobalValue::InternalLinkage)
-      continue;
-
-    LLVM_DEBUG(dbgs() << "Constant data of Global: ");
-    LLVM_DEBUG(ConstData->dump());
-    LLVM_DEBUG(dbgs() << "\n\n");
-
-    MergeableStrings.push_back(&Global);
-    if (MaxAlignment < AlignOfGlobal)
-      MaxAlignment = AlignOfGlobal;
-
-    // If we have already reached the maximum number of pooled strings then
-    // there is no point in looking for more.
-    if (MergeableStrings.size() >= MaxStringsPooled)
-      break;
-  }
-}
-
-bool PPCMergeStringPool::mergeModuleStringPool(Module &M) {
-
-  LLVM_DEBUG(dbgs() << "Merging string pool for module: " << M.getName()
-                    << "\n");
-  LLVM_DEBUG(dbgs() << "Number of globals is: " << M.global_size() << "\n");
-
-  collectCandidateConstants(M);
-
-  // If we have too few constants in the module that are merge candidates we
-  // will skip doing the merging.
-  if (MergeableStrings.size() < MinStringsBeforePool)
-    return false;
-
-  // Sort the global constants to make access more efficient.
-  std::sort(MergeableStrings.begin(), MergeableStrings.end(), CompareConstants);
-
-  SmallVector<Constant *> ConstantsInStruct;
-  for (GlobalVariable *GV : MergeableStrings)
-    ConstantsInStruct.push_back(GV->getInitializer());
-
-  // Use an anonymous struct to pool the strings.
-  // TODO: This pass uses a single anonymous struct for all of the pooled
-  // entries. This may cause a performance issue in the situation where
-  // computing the offset requires two instructions (addis, addi). For the
-  // future we may want to split this into multiple structs.
-  Constant *ConstantPool = ConstantStruct::getAnon(ConstantsInStruct);
-  PooledStructType = ConstantPool->getType();
-
-  // The GlobalVariable constructor calls
-  // MM->insertGlobalVariable(PooledGlobal).
-  GlobalVariable *PooledGlobal =
-      new GlobalVariable(M, PooledStructType,
-                         /* isConstant */ true, GlobalValue::PrivateLinkage,
-                         ConstantPool, "__ModuleStringPool");
-  PooledGlobal->setAlignment(MaxAlignment);
-
-  LLVM_DEBUG(dbgs() << "Constructing global variable for string pool: ");
-  LLVM_DEBUG(PooledGlobal->dump());
-
-  Context = &M.getContext();
-  size_t ElementIndex = 0;
-  for (GlobalVariable *GV : MergeableStrings) {
-
-    LLVM_DEBUG(dbgs() << "The global:\n");
-    LLVM_DEBUG(GV->dump());
-    LLVM_DEBUG(dbgs() << "Has " << GV->getNumUses() << " uses.\n");
-
-    // Access to the pooled constant strings require an offset. Add a GEP
-    // before every use in order to compute this offset.
-    replaceUsesWithGEP(GV, PooledGlobal, ElementIndex);
-
-    // Replace all the uses by metadata.
-    if (GV->isUsedByMetadata()) {
-      Constant *Indices[2] = {
-          ConstantInt::get(Type::getInt32Ty(*Context), 0),
-          ConstantInt::get(Type::getInt32Ty(*Context), ElementIndex)};
-      Constant *ConstGEP = ConstantExpr::getInBoundsGetElementPtr(
-          PooledStructType, PooledGlobal, Indices);
-      ValueAsMetadata::handleRAUW(GV, ConstGEP);
-    }
-    assert(!GV->isUsedByMetadata() && "Should be no metadata use anymore");
-
-    // This GV has no more uses so we can erase it.
-    if (GV->use_empty())
-      GV->eraseFromParent();
-
-    NumPooledStrings++;
-    ElementIndex++;
-  }
-  return true;
-}
-
-// For pooled strings we need to add the offset into the pool for each string.
-// This is done by adding a Get Element Pointer (GEP) before each user. This
-// function adds the GEP.
-void PPCMergeStringPool::replaceUsesWithGEP(GlobalVariable *GlobalToReplace,
-                                            GlobalVariable *GPool,
-                                            unsigned ElementIndex) {
-  SmallVector<Value *, 2> Indices;
-  Indices.push_back(ConstantInt::get(Type::getInt32Ty(*Context), 0));
-  Indices.push_back(ConstantInt::get(Type::getInt32Ty(*Context), ElementIndex));
-
-  Constant *ConstGEP =
-      ConstantExpr::getInBoundsGetElementPtr(PooledStructType, GPool, Indices);
-  LLVM_DEBUG(dbgs() << "Replacing this global:\n");
-  LLVM_DEBUG(GlobalToReplace->dump());
-  LLVM_DEBUG(dbgs() << "with this:\n");
-  LLVM_DEBUG(ConstGEP->dump());
-  GlobalToReplace->replaceAllUsesWith(ConstGEP);
-}
-
-} // namespace
-
-char PPCMergeStringPool::ID = 0;
-
-INITIALIZE_PASS(PPCMergeStringPool, DEBUG_TYPE, "PPC Merge String Pool", false,
-                false)
-
-ModulePass *llvm::createPPCMergeStringPoolPass() {
-  return new PPCMergeStringPool();
-}
diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
index 538690090976ce..b494e4be326220 100644
--- a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -150,7 +150,6 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCTarget() {
   initializeGlobalISel(PR);
   initializePPCCTRLoopsPass(PR);
   initializePPCDAGToDAGISelLegacyPass(PR);
-  initializePPCMergeStringPoolPass(PR);
 }
 
 static bool isLittleEndianTriple(const Triple &T) {
diff --git a/llvm/test/CodeGen/PowerPC/merge-string-used-by-metadata.mir b/llvm/test/CodeGen/PowerPC/merge-string-used-by-metadata.mir
deleted file mode 100644
index 4a40974a2a227b..00000000000000
--- a/llvm/test/CodeGen/PowerPC/merge-string-used-by-metadata.mir
+++ /dev/null
@@ -1,52 +0,0 @@
-# RUN: llc -run-pass=ppc-merge-strings -mcpu=pwr8 -mtriple powerpc64le-unknown-linux-gnu \
-# RUN:   -verify-machineinstrs -o - %s | FileCheck %s
-# RUN: llc -run-pass=ppc-merge-strings -mcpu=pwr8 -mtriple powerpc64-ibm-aix-xcoff \
-# RUN:   -verify-machineinstrs -o - %s | FileCheck %s
-
---- |
-  ; Constants list.
-  @const.1 = internal constant [7 x i8] c"const1\00", align 1
-  @const.2 = internal constant [7 x i8] c"const2\00", align 1
-
-  ;;
-  ;; Start of test code.
-  ;;
-
-  define noundef ptr @func1(ptr noundef nonnull align 8 dereferenceable(8) %this) #0 !dbg !6 {
-  ; CHECK-LABEL: func1
-  ; CHECK:       ret ptr getelementptr inbounds ({ [7 x i8], [7 x i8] }, ptr @__ModuleStringPool, i32 0, i32 1), !dbg !14
-  entry:
-    ret ptr @const.2, !dbg !14
-  }
-
-  define noundef ptr @func2(ptr noundef nonnull align 8 dereferenceable(8) %this) #0 {
-  ; CHECK-LABEL: func2
-  ; CHECK:       ret ptr @__ModuleStringPool
-  entry:
-    ret ptr @const.1
-  }
-
-  attributes #0 = { noinline nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="pwr8" "target-features"="+altivec,+bpermd,+crbits,+crypto,+direct-move,+extdiv,+htm,+isa-v206-instructions,+isa-v207-instructions,+power8-vector,+quadword-atomics,+vsx,-aix-small-local-exec-tls,-isa-v30-instructions,-power9-vector,-privileged,-rop-protect,-spe" }
-
-  !llvm.dbg.cu = !{!0}
-  !llvm.module.flags = !{!3, !4}
-  !llvm.ident = !{!5}
-
-  ; CHECK:       !10 = !DITemplateValueParameter(name: "ID", type: !11, value: ptr getelementptr inbounds ({ [7 x i8], [7 x i8] }, ptr @__ModuleStringPool, i32 0, i32 1))
-  !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
-  !1 = !DIFile(filename: "constant-pointers.cpp", directory: "/tmp/dbginfo")
-  !2 = !{}
-  !3 = !{i32 7, !"Dwarf Version", i32 3}
-  !4 = !{i32 2, !"Debug Info Version", i32 3}
-  !5 = !{!"clang version 17.0.0"}
-  !6 = distinct !DISubprogram(name: "getId", linkageName: "func1", scope: !1, file: !1, line: 2, type: !7, scopeLine: 2, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, templateParams: !9, retainedNodes: !2)
-  !7 = !DISubroutineType(types: !8)
-  !8 = !{null}
-  !9 = !{!10}
-  !10 = !DITemplateValueParameter(name: "ID", type: !11, value: ptr @const.2)
-  !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
-  !12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !13)
-  !13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char)
-  !14 = !DILocation(line: 3, scope: !6)
-
-...
diff --git a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-large.ll b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-large.ll
index e6f6ce236bb2d9..bc143e8c7ea4c0 100644
--- a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-large.ll
+++ b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-large.ll
@@ -280,17 +280,17 @@ define dso_local signext i32 @str1() local_unnamed_addr #0 {
 ;
 ; LINUX64LE-LABEL: str1:
 ; LINUX64LE:       # %bb.0: # %entry
-; LINUX64LE-NEXT:     mflr r0
-; LINUX64LE-NEXT:     stdu r1, -32(r1)
-; LINUX64LE-NEXT:     addis r3, r2, .L_MergedGlobals at toc@ha
-; LINUX64LE-NEXT:     std r0, 48(r1)
-; LINUX64LE-NEXT:     addi r3, r3, .L_MergedGlobals at toc@l
-; LINUX64LE-NEXT:     bl callee
-; LINUX64LE-NEXT:     nop
-; LINUX64LE-NEXT:     addi r1, r1, 32
-; LINUX64LE-NEXT:     ld r0, 16(r1)
-; LINUX64LE-NEXT:     mtlr r0
-; LINUX64LE-NEXT:     blr
+; LINUX64LE-NEXT:    mflr r0
+; LINUX64LE-NEXT:    stdu r1, -32(r1)
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    std r0, 48(r1)
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    bl callee
+; LINUX64LE-NEXT:    nop
+; LINUX64LE-NEXT:    addi r1, r1, 32
+; LINUX64LE-NEXT:    ld r0, 16(r1)
+; LINUX64LE-NEXT:    mtlr r0
+; LINUX64LE-NEXT:    blr
 entry:
   %call = tail call signext i32 @callee(ptr noundef nonnull @.str.1)
   ret i32 %call
@@ -370,25 +370,25 @@ define dso_local signext i32 @array0() local_unnamed_addr #0 {
 ;
 ; LINUX64LE-LABEL: array0:
 ; LINUX64LE:       # %bb.0: # %entry
-; LINUX64LE-NEXT:     mflr r0
-; LINUX64LE-NEXT:     stdu r1, -64(r1)
-; LINUX64LE-NEXT:     addis r3, r2, .L_MergedGlobals at toc@ha
-; LINUX64LE-NEXT:     li r4, 24
-; LINUX64LE-NEXT:     std r0, 80(r1)
-; LINUX64LE-NEXT:     addi r3, r3, .L_MergedGlobals at toc@l
-; LINUX64LE-NEXT:     lxvd2x vs0, r3, r4
-; LINUX64LE-NEXT:     addi r4, r1, 44
-; LINUX64LE-NEXT:     stxvd2x vs0, 0, r4
-; LINUX64LE-NEXT:     li r4, 12
-; LINUX64LE-NEXT:     lxvd2x vs0, r3, r4
-; LINUX64LE-NEXT:     addi r3, r1, 32
-; LINUX64LE-NEXT:     stxvd2x vs0, 0, r3
-; LINUX64LE-NEXT:     bl calleeInt
-; LINUX64LE-NEXT:     nop
-; LINUX64LE-NEXT:     addi r1, r1, 64
-; LINUX64LE-NEXT:     ld r0, 16(r1)
-; LINUX64LE-NEXT:     mtlr r0
-; LINUX64LE-NEXT:     blr
+; LINUX64LE-NEXT:    mflr r0
+; LINUX64LE-NEXT:    stdu r1, -64(r1)
+; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
+; LINUX64LE-NEXT:    li r4, 24
+; LINUX64LE-NEXT:    std r0, 80(r1)
+; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
+; LINUX64LE-NEXT:    lxvd2x vs0, r3, r4
+; LINUX64LE-NEXT:    addi r4, r1, 44
+; LINUX64LE-NEXT:    stxvd2x vs0, 0, r4
+; LINUX64LE-NEXT:    li r4, 12
+; LINUX64LE-NEXT:    lxvd2x vs0, r3, r4
+; LINUX64LE-NEXT:    addi r3, r1, 32
+; LINUX64LE-NEXT:    stxvd2x vs0, 0, r3
+; LINUX64LE-NEXT:    bl calleeInt
+; LINUX64LE-NEXT:    nop
+; LINUX64LE-NEXT:    addi r1, r1, 64
+; LINUX64LE-NEXT:    ld r0, 16(r1)
+; LINUX64LE-NEXT:    mtlr r0
+; LINUX64LE-NEXT:    blr
 entry:
   %IntArray = alloca [7 x i32], align 4
   call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %IntArray)
@@ -799,15 +799,15 @@ define dso_local signext i32 @array3() local_unnamed_addr #0 {
 ; LINUX64BE-NEXT:    stdu r1, -288(r1)
 ; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 304(r1)
-; LINUX64BE-NEXT:    std r30, 272(r1)                        # 8-byte Folded Spill
+; LINUX64BE-NEXT:    std r30, 272(r1) # 8-byte Folded Spill
 ; LINUX64BE-NEXT:    addi r30, r1, 112
 ; LINUX64BE-NEXT:    li r5, 160
 ; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
 ; LINUX64BE-NEXT:    addi r4, r3, 264
-; LINUX64BE-NEXT:    mr      r3, r30
+; LINUX64BE-NEXT:    mr r3, r30
 ; LINUX64BE-NEXT:    bl memcpy
 ; LINUX64BE-NEXT:    nop
-; LINUX64BE-NEXT:    mr      r3, r30
+; LINUX64BE-NEXT:    mr r3, r30
 ; LINUX64BE-NEXT:    bl calleeInt
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    ld r30, 272(r1) # 8-byte Folded Reload
@@ -819,7 +819,7 @@ define dso_local signext i32 @array3() local_unnamed_addr #0 {
 ; LINUX64LE-LABEL: array3:
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
-; LINUX64LE-NEXT:    std r30, -16(r1)                        # 8-byte Folded Spill
+; LINUX64LE-NEXT:    std r30, -16(r1) # 8-byte Folded Spill
 ; LINUX64LE-NEXT:    stdu r1, -208(r1)
 ; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    addi r30, r1, 32
@@ -827,15 +827,15 @@ define dso_local signext i32 @array3() local_unnamed_addr #0 {
 ; LINUX64LE-NEXT:    std r0, 224(r1)
 ; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
 ; LINUX64LE-NEXT:    addi r4, r3, 264
-; LINUX64LE-NEXT:    mr      r3, r30
+; LINUX64LE-NEXT:    mr r3, r30
 ; LINUX64LE-NEXT:    bl memcpy
 ; LINUX64LE-NEXT:    nop
-; LINUX64LE-NEXT:    mr      r3, r30
+; LINUX64LE-NEXT:    mr r3, r30
 ; LINUX64LE-NEXT:    bl calleeInt
 ; LINUX64LE-NEXT:    nop
 ; LINUX64LE-NEXT:    addi r1, r1, 208
 ; LINUX64LE-NEXT:    ld r0, 16(r1)
-; LINUX64LE-NEXT:    ld r30, -16(r1)                         # 8-byte Folded Reload
+; LINUX64LE-NEXT:    ld r30, -16(r1) # 8-byte Folded Reload
 ; LINUX64LE-NEXT:    mtlr r0
 ; LINUX64LE-NEXT:    blr
 entry:
@@ -898,15 +898,15 @@ define dso_local signext i32 @array4() local_unnamed_addr #0 {
 ; LINUX64BE-NEXT:    stdu r1, -448(r1)
 ; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    std r0, 464(r1)
-; LINUX64BE-NEXT:    std r30, 432(r1)                        # 8-byte Folded Spill
+; LINUX64BE-NEXT:    std r30, 432(r1) # 8-byte Folded Spill
 ; LINUX64BE-NEXT:    addi r30, r1, 112
 ; LINUX64BE-NEXT:    li r5, 320
 ; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
 ; LINUX64BE-NEXT:    addi r4, r3, 424
-; LINUX64BE-NEXT:    mr      r3, r30
+; LINUX64BE-NEXT:    mr r3, r30
 ; LINUX64BE-NEXT:    bl memcpy
 ; LINUX64BE-NEXT:    nop
-; LINUX64BE-NEXT:    mr      r3, r30
+; LINUX64BE-NEXT:    mr r3, r30
 ; LINUX64BE-NEXT:    bl calleeInt
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    ld r30, 432(r1) # 8-byte Folded Reload
@@ -921,18 +921,18 @@ define dso_local signext i32 @array4() local_unnamed_addr #0 {
 ; LINUX64LE-NEXT:    stdu r1, -368(r1)
 ; LINUX64LE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64LE-NEXT:    std r0, 384(r1)
-; LINUX64LE-NEXT:    std r30, 352(r1)                        # 8-byte Folded Spill
+; LINUX64LE-NEXT:    std r30, 352(r1) # 8-byte Folded Spill
 ; LINUX64LE-NEXT:    addi r30, r1, 32
 ; LINUX64LE-NEXT:    li r5, 320
 ; LINUX64LE-NEXT:    addi r3, r3, .L_MergedGlobals at toc@l
 ; LINUX64LE-NEXT:    addi r4, r3, 424
-; LINUX64LE-NEXT:    mr      r3, r30
+; LINUX64LE-NEXT:    mr r3, r30
 ; LINUX64LE-NEXT:    bl memcpy
 ; LINUX64LE-NEXT:    nop
-; LINUX64LE-NEXT:    mr      r3, r30
+; LINUX64LE-NEXT:    mr r3, r30
 ; LINUX64LE-NEXT:    bl calleeInt
 ; LINUX64LE-NEXT:    nop
-; LINUX64LE-NEXT:    ld r30, 352(r1)                         # 8-byte Folded Reload
+; LINUX64LE-NEXT:    ld r30, 352(r1) # 8-byte Folded Reload
 ; LINUX64LE-NEXT:    addi r1, r1, 368
 ; LINUX64LE-NEXT:    ld r0, 16(r1)
 ; LINUX64LE-NEXT:    mtlr r0
diff --git a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-pass-only.mir b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-pass-only.mir
deleted file mode 100644
index 3d8afb604fd3ca..00000000000000
--- a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-pass-only.mir
+++ /dev/null
@@ -1,114 +0,0 @@
-# RUN: llc -run-pass=ppc-merge-strings -mcpu=pwr8 -mtriple powerpc64le-unknown-linux-gnu \
-# RUN:   -verify-machineinstrs -o - %s | FileCheck %s
-# RUN: llc -run-pass=ppc-merge-strings -mcpu=pwr8 -mtriple powerpc64-ibm-aix-xcoff \
-# RUN:   -verify-machineinstrs -o - %s | FileCheck %s
-
---- |
-  ; Constants list.
-  @.str = private unnamed_addr constant [8 x i8] c"ABCDEFG\00", align 1
-  @__const.test2.A = private unnamed_addr constant [6 x i32] [i32 34, i32 23, i32 653, i32 12, i32 75, i32 32], align 4
-  @__const.test3.A = private unnamed_addr constant [7 x float] [float 0x400AA3D700000000, float 0x4021EB8520000000, float 0x4023147AE0000000, float 0x401CEB8520000000, float 0x401C8F5C20000000, float 0x402075C280000000, float 0x3FF1C28F60000000], align 4
-  @__const.test4.A = private unnamed_addr constant [7 x double] [double 3.330000e+00, double 8.960000e+00, double 0x4023147AE147AE14, double 7.230000e+00, double 7.140000e+00, double 8.230000e+00, double 1.110000e+00], align 8
-  @.str.1 = private unnamed_addr constant [16 x i8] c"DifferentString\00", align 1
-  @__const.test5.B = private unnamed_addr constant [6 x i32] [i32 134, i32 123, i32 53, i32 142, i32 375, i32 132], align 4
-  @__const.test5.C = private unnamed_addr constant [7 x float] [float 0x4037547AE0000000, float 0x403CF5C280000000, float 0x40338A3D80000000, float 0x40313AE140000000, float 0x404111EB80000000, float 0x40323AE140000000, float 0x40263851E0000000], align 4
-  @__const.test5.D = private unnamed_addr constant [7 x double] [double 2.333000e+01, double 2.896000e+01, double 1.954000e+01, double 1.723000e+01, double 3.414000e+01, double 1.823000e+01, double 1.111000e+01], align 8
-
-  ; CHECK: @__ModuleStringPool = private constant { [7 x double], [7 x double], [6 x i32], [6 x i32], [7 x float], [7 x float], [8 x i8], [16 x i8] } { [7 x double] [double 3.330000e+00, double 8.960000e+00, double 0x4023147AE147AE14, double 7.230000e+00, double 7.140000e+00, double 8.230000e+00, double 1.110000e+00], [7 x double] [double 2.333000e+01, double 2.896000e+01, double 1.954000e+01, double 1.723000e+01, double 3.414000e+01, double 1.823000e+01, double 1.111000e+01], [6 x i32] [i32 34, i32 23, i32 653, i32 12, i32 75, i32 32], [6 x i32] [i32 134, i32 123, i32 53, i32 142, i32 375, i32 132], [7 x float] [float 0x400AA3D700000000, float 0x4021EB8520000000, float 0x4023147AE0000000, float 0x401CEB8520000000, float 0x401C8F5C20000000, float 0x402075C280000000, float 0x3FF1C28F60000000], [7 x float] [float 0x4037547AE0000000, float 0x403CF5C280000000, float 0x40338A3D80000000, float 0x40313AE140000000, float 0x404111EB80000000, float 0x40323AE140000000, float 0x40263851E0000000], [8 x i8] c"ABCDEFG\00", [16 x i8] c"DifferentString\00" }, align 8
-
-  ; List of callee functions.
-  declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0
-  declare signext i32 @calleeStr(ptr noundef) local_unnamed_addr #0
-  declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0
-  declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0
-  declare signext i32 @calleeInt(ptr noundef) local_unnamed_addr #0
-  declare signext i32 @calleeFloat(ptr noundef) local_unnamed_addr #0
-  declare signext i32 @calleeDouble(ptr noundef) local_unnamed_addr #0
-
-  ;;
-  ;; Start of test code.
-  ;;
-
-  define dso_local signext i32 @test1() local_unnamed_addr #0 {
-  entry:
-    %call = tail call signext i32 @calleeStr(ptr noundef nonnull @.str) #0
-    ret i32 %call
-
-  ; CHECK-LABEL: test1
-  ; CHECK:         %call = tail call signext i32 @calleeStr(ptr noundef nonnull getelementptr inbounds ({ [7 x double], [7 x double], [6 x i32], [6 x i32], [7 x float], [7 x float], [8 x i8], [16 x i8] }, ptr @__ModuleStringPool, i32 0, i32 6))
-  }
-
-  define dso_local signext i32 @test2() local_unnamed_addr #0 {
-  entry:
-    %A = alloca [6 x i32], align 4
-    call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %A) #0
-    call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) %A, ptr noundef nonnull align 4 dereferenceable(24) @__const.test2.A, i64 24, i1 false)
-    %call = call signext i32 @calleeInt(ptr noundef nonnull %A) #0
-    call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %A) #0
-    ret i32 %call
-
-  ; CHECK-LABEL: test2
-  ; CHECK:         call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) %A, ptr noundef nonnull align 4 dereferenceable(24) getelementptr inbounds ({ [7 x double], [7 x double], [6 x i32], [6 x i32], [7 x float], [7 x float], [8 x i8], [16 x i8] }, ptr @__ModuleStringPool, i32 0, i32 2), i64 24, i1 false)
-  ; CHECK:         call signext i32 @calleeInt
-  }
-
-  define dso_local signext i32 @test3() local_unnamed_addr #0 {
-  entry:
-    %A = alloca [7 x float], align 4
-    call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %A) #0
-    call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(28) %A, ptr noundef nonnull align 4 dereferenceable(28) @__const.test3.A, i64 28, i1 false)
-    %call = call signext i32 @calleeFloat(ptr noundef nonnull %A) #0
-    call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %A) #0
-    ret i32 %call
-  ; CHECK-LABEL: test3
-  ; CHECK:         call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(28) %A, ptr noundef nonnull align 4 dereferenceable(28) getelementptr inbounds ({ [7 x double], [7 x double], [6 x i32], [6 x i32], [7 x float], [7 x float], [8 x i8], [16 x i8] }, ptr @__ModuleStringPool, i32 0, i32 4), i64 28, i1 false)
-  ; CHECK:         call signext i32 @calleeFloat
-  }
-
-  define dso_local signext i32 @test4() local_unnamed_addr #0 {
-  entry:
-    %A = alloca [7 x double], align 8
-    call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %A) #0
-    call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %A, ptr noundef nonnull align 8 dereferenceable(56) @__const.test4.A, i64 56, i1 false)
-    %call = call signext i32 @calleeDouble(ptr noundef nonnull %A) #0
-    call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %A) #0
-    ret i32 %call
-  ; CHECK-LABEL: test4
-  ; CHECK:         call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %A, ptr noundef nonnull align 8 dereferenceable(56) @__ModuleStringPool, i64 56, i1 false)
-  ; CHECK:         call signext i32 @calleeDouble
-  }
-
-  define dso_local signext i32 @test5() local_unnamed_addr #0 {
-  entry:
-    %B = alloca [6 x i32], align 4
-    %C = alloca [7 x float], align 4
-    %D = alloca [7 x double], align 8
-    call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %B) #0
-    call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) %B, ptr noundef nonnull align 4 dereferenceable(24) @__const.test5.B, i64 24, i1 false)
-    call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %C) #0
-    call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(28) %C, ptr noundef nonnull align 4 dereferenceable(28) @__const.test5.C, i64 28, i1 false)
-    call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %D) #0
-    call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %D, ptr noundef nonnull align 8 dereferenceable(56) @__const.test5.D, i64 56, i1 false)
-    %call = tail call signext i32 @calleeStr(ptr noundef nonnull @.str.1) #0
-    %call1 = call signext i32 @calleeInt(ptr noundef nonnull %B) #0
-    %add = add nsw i32 %call1, %call
-    %call3 = call signext i32 @calleeFloat(ptr noundef nonnull %C) #0
-    %add4 = add nsw i32 %add, %call3
-    %call6 = call signext i32 @calleeDouble(ptr noundef nonnull %D) #0
-    %add7 = add nsw i32 %add4, %call6
-    call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %D) #0
-    call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %C) #0
-    call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %B) #0
-    ret i32 %add7
-  ; CHECK-LABEL: test5
-  ; CHECK:         call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) %B, ptr noundef nonnull align 4 dereferenceable(24) getelementptr inbounds ({ [7 x double], [7 x double], [6 x i32], [6 x i32], [7 x float], [7 x float], [8 x i8], [16 x i8] }, ptr @__ModuleStringPool, i32 0, i32 3), i64 24, i1 false)
-  ; CHECK:         call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(28) %C, ptr noundef nonnull align 4 dereferenceable(28) getelementptr inbounds ({ [7 x double], [7 x double], [6 x i32], [6 x i32], [7 x float], [7 x float], [8 x i8], [16 x i8] }, ptr @__ModuleStringPool, i32 0, i32 5), i64 28, i1 false)
-  ; CHECK:         call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %D, ptr noundef nonnull align 8 dereferenceable(56) getelementptr inbounds ({ [7 x double], [7 x double], [6 x i32], [6 x i32], [7 x float], [7 x float], [8 x i8], [16 x i8] }, ptr @__ModuleStringPool, i32 0, i32 1), i64 56, i1 false)
-  ; CHECK:         call signext i32 @calleeStr(ptr noundef nonnull getelementptr inbounds ({ [7 x double], [7 x double], [6 x i32], [6 x i32], [7 x float], [7 x float], [8 x i8], [16 x i8] }, ptr @__ModuleStringPool, i32 0, i32 7))
-  ; CHECK:         call signext i32 @calleeInt
-  ; CHECK:         call signext i32 @calleeFloat
-  ; CHECK:         call signext i32 @calleeDouble
-  }
-
-  attributes #0 = { nounwind }
-...
diff --git a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-tls.ll b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-tls.ll
index d55763bd6b16f3..a726e7741cf0fe 100644
--- a/llvm/test/CodeGen/PowerPC/mergeable-string-pool-tls.ll
+++ b/llvm/test/CodeGen/PowerPC/mergeable-string-pool-tls.ll
@@ -94,7 +94,7 @@ define void @print_tls_func() {
 ; LINUX64BE-NEXT:    .cfi_offset lr, 16
 ; LINUX64BE-NEXT:    .cfi_offset r30, -16
 ; LINUX64BE-NEXT:    addis r3, r2, a at got@tlsld at ha
-; LINUX64BE-NEXT:    std r30, 112(r1)                        # 8-byte Folded Spill
+; LINUX64BE-NEXT:    std r30, 112(r1) # 8-byte Folded Spill
 ; LINUX64BE-NEXT:    addi r3, r3, a at got@tlsld at l
 ; LINUX64BE-NEXT:    bl __tls_get_addr(a at tlsld)
 ; LINUX64BE-NEXT:    nop
@@ -105,14 +105,14 @@ define void @print_tls_func() {
 ; LINUX64BE-NEXT:    bl __tls_get_addr(b at tlsld)
 ; LINUX64BE-NEXT:    nop
 ; LINUX64BE-NEXT:    addis r3, r3, b at dtprel@ha
-; LINUX64BE-NEXT:    mr      r4, r30
+; LINUX64BE-NEXT:    mr r4, r30
 ; LINUX64BE-NEXT:    addi r5, r3, b at dtprel@l
 ; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals at toc@ha
 ; LINUX64BE-NEXT:    addi r6, r3, .L_MergedGlobals at toc@l
 ; LINUX64BE-NEXT:    addi r3, r6, 72
 ; LINUX64BE-NEXT:    bl printf
 ; LINUX64BE-NEXT:    nop
-; LINUX64BE-NEXT:    ld r30, 112(r1)                         # 8-byte Folded Reload
+; LINUX64BE-NEXT:    ld r30, 112(r1) # 8-byte Folded Reload
 ; LINUX64BE-NEXT:    addi r1, r1, 128
 ; LINUX64BE-NEXT:    ld r0, 16(r1)
 ; LINUX64BE-NEXT:    mtlr r0
@@ -152,6 +152,7 @@ define void @test_func() {
 ; CHECK32-NEXT:    lwz r0, 8(r1)
 ; CHECK32-NEXT:    mtlr r0
 ; CHECK32-NEXT:    blr
+
 ; LINUX64LE-LABEL: test_func:
 ; LINUX64LE:       # %bb.0: # %entry
 ; LINUX64LE-NEXT:    mflr r0
diff --git a/llvm/utils/gn/secondary/llvm/lib/Target/PowerPC/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/Target/PowerPC/BUILD.gn
index 9e5ad929a3132f..1ae976da2bed6a 100644
--- a/llvm/utils/gn/secondary/llvm/lib/Target/PowerPC/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/Target/PowerPC/BUILD.gn
@@ -83,7 +83,6 @@ static_library("LLVMPowerPCCodeGen") {
     "PPCMachineFunctionInfo.cpp",
     "PPCMachineScheduler.cpp",
     "PPCMacroFusion.cpp",
-    "PPCMergeStringPool.cpp",
     "PPCPreEmitPeephole.cpp",
     "PPCReduceCRLogicals.cpp",
     "PPCRegisterInfo.cpp",

>From 408abb2353fdc359de09d2ba3d3521ce2b5fd0b1 Mon Sep 17 00:00:00 2001
From: Zaara Syeda <syzaara at ca.ibm.com>
Date: Wed, 6 Nov 2024 21:51:23 +0000
Subject: [PATCH 3/4] Fix formatting

---
 llvm/lib/CodeGen/GlobalMerge.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index a4070de8489830..8ab834966b1063 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -714,7 +714,7 @@ bool GlobalMergeImpl::run(Module &M) {
     // Ignore all "required" globals:
     if (isMustKeepGlobalVariable(&GV))
       continue;
-    auto checkUsers = [] (const GlobalVariable *GV) {
+    auto checkUsers = [](const GlobalVariable *GV) {
       for (const User *CurrentUser : GV->users()) {
         auto *I = dyn_cast<Instruction>(CurrentUser);
         if (!I)

>From 0c61b814f64c15cf020b8d7df1c8b564ccc699eb Mon Sep 17 00:00:00 2001
From: Zaara Syeda <syzaara at ca.ibm.com>
Date: Thu, 7 Nov 2024 16:22:55 +0000
Subject: [PATCH 4/4] Address review comments

---
 llvm/lib/CodeGen/GlobalMerge.cpp | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)

diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index 8ab834966b1063..f1a8541d0d4db8 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -633,10 +633,13 @@ void GlobalMergeImpl::setMustKeepGlobalVariables(Module &M) {
   for (Function &F : M) {
     for (BasicBlock &BB : F) {
       Instruction *Pad = BB.getFirstNonPHI();
-      if (!Pad->isEHPad())
+      auto *II = dyn_cast<IntrinsicInst>(Pad);
+      if (!Pad->isEHPad() &&
+          !(II && II->getIntrinsicID() == Intrinsic::eh_typeid_for))
         continue;
 
-      // Keep globals used by landingpads and catchpads.
+      // Keep globals used by landingpads, catchpads,
+      // or instrinsics that require a plain global.
       for (const Use &U : Pad->operands()) {
         if (const GlobalVariable *GV =
                 dyn_cast<GlobalVariable>(U->stripPointerCasts()))
@@ -714,25 +717,6 @@ bool GlobalMergeImpl::run(Module &M) {
     // Ignore all "required" globals:
     if (isMustKeepGlobalVariable(&GV))
       continue;
-    auto checkUsers = [](const GlobalVariable *GV) {
-      for (const User *CurrentUser : GV->users()) {
-        auto *I = dyn_cast<Instruction>(CurrentUser);
-        if (!I)
-          continue;
-        // Do not merge globals in exception pads.
-        if (I->isEHPad())
-          return false;
-        if (auto *II = dyn_cast<IntrinsicInst>(I)) {
-          // Some intrinsics require a plain global.
-          if (II->getIntrinsicID() == Intrinsic::eh_typeid_for)
-            return false;
-        }
-      }
-      return true;
-    };
-
-    if (!checkUsers(&GV))
-      continue;
 
     // Don't merge tagged globals, as each global should have its own unique
     // memory tag at runtime. TODO(hctim): This can be relaxed: constant globals



More information about the llvm-commits mailing list