Skip to content

[PPC] Replace PPCMergeStringPool with GlobalMerge for Linux #114850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 12, 2024

Conversation

syzaara
Copy link
Contributor

@syzaara syzaara commented Nov 4, 2024

Enable merging all constants without looking at use in GlobalMerge by default to replace PPCMergeStringPool pass on Linux.

@llvmbot
Copy link
Member

llvmbot commented Nov 4, 2024

@llvm/pr-subscribers-backend-powerpc

Author: Zaara Syeda (syzaara)

Changes

Enable merging all constants without looking at use in GlobalMerge by default to replace PPCMergeStringPool pass on Linux.


Patch is 62.33 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/114850.diff

14 Files Affected:

  • (modified) llvm/lib/CodeGen/GlobalMerge.cpp (+19)
  • (modified) llvm/lib/Target/PowerPC/PPCTargetMachine.cpp (+1-8)
  • (modified) llvm/test/CodeGen/PowerPC/O3-pipeline.ll (+1)
  • (modified) llvm/test/CodeGen/PowerPC/PR35812-neg-cmpxchg.ll (+16-16)
  • (modified) llvm/test/CodeGen/PowerPC/aix-xcoff-used-with-stringpool.ll (+3-3)
  • (modified) llvm/test/CodeGen/PowerPC/ctrloop-fp128.ll (+29-45)
  • (modified) llvm/test/CodeGen/PowerPC/expand-contiguous-isel.ll (+10-8)
  • (modified) llvm/test/CodeGen/PowerPC/licm-remat.ll (+3-3)
  • (modified) llvm/test/CodeGen/PowerPC/merge-private.ll (+2-2)
  • (modified) llvm/test/CodeGen/PowerPC/mergeable-string-pool-large.ll (+139-133)
  • (modified) llvm/test/CodeGen/PowerPC/mergeable-string-pool-pr92991.ll (+2-2)
  • (modified) llvm/test/CodeGen/PowerPC/mergeable-string-pool-tls.ll (+65-64)
  • (modified) llvm/test/CodeGen/PowerPC/mergeable-string-pool.ll (+96-89)
  • (modified) llvm/test/CodeGen/PowerPC/toc-load-sched-bug.ll (+2-2)
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@toc@ha
-; CHECK-NEXT:    addi 3, 3, .L__ModuleStringPool@toc@l
+; CHECK-NEXT:    addis 3, 2, .L_MergedGlobals@toc@ha
+; CHECK-NEXT:    addi 3, 3, .L_MergedGlobals@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@toc@ha
-; CHECK-NEXT:    addi 3, 3, .L__ModuleStringPool@toc@l
-; CHECK-NEXT:    addi 3, 3, 7
+; CHECK-NEXT:    addis 3, 2, .L_MergedGlobals@toc@ha
+; CHECK-NEXT:    addi 3, 3, .L_MergedGlobals@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@toc@ha
-; CHECK-NEXT:    addi 3, 3, .L__ModuleStringPool@toc@l
-; CHECK-NEXT:    addi 3, 3, 53
+; CHECK-NEXT:    addis 3, 2, .L_MergedGlobals@toc@ha
+; CHECK-NEXT:    addi 3, 3, .L_MergedGlobals@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@toc@ha
-; CHECK-P7-NEXT:    addi 3, 3, .L__ModuleStringPool@toc@l
+; CHECK-P7-NEXT:    addis 3, 2, .L_MergedGlobals@toc@ha
+; CHECK-P7-NEXT:    addi 3, 3, .L_MergedGlobals@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@toc@ha
-; CHECK-P7-NEXT:    addi 3, 3, .L__ModuleStringPool@toc@l
-; CHECK-P7-NEXT:    addi 3, 3, 7
+; CHECK-P7-NEXT:    addis 3, 2, .L_MergedGlobals@toc@ha
+; CHECK-P7-NEXT:    addi 3, 3, .L_MergedGlobals@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@toc@ha
-; CHECK-P7-NEXT:    addi 3, 3, .L__ModuleStringPool@toc@l
-; CHECK-P7-NEXT:    addi 3, 3, 53
+; CHECK-P7-NEXT:    addis 3, 2, .L_MergedGlobals@toc@ha
+; CHECK-P7-NEXT:    addi 3, 3, .L_MergedGlobals@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@toc@ha
+; PWR9-NEXT:    addis 3, 2, .L_MergedGlobals@toc@ha
 ; PWR9-NEXT:    li 4, 4
-; PWR9-NEXT:    addi 3, 3, a@toc@l
+; PWR9-NEXT:    addi 3, 3, .L_MergedGlobals@toc@l
 ; PWR9-NEXT:    lxv 34, 0(3)
-; PWR9-NEXT:    addis 3, 2, y@toc@ha
 ; PWR9-NEXT:    mtctr 4
-; PWR9-NEXT:    addis 4, 2, x@toc@ha
-; PWR9-NEXT:    addi 3, 3, y@toc@l
-; PWR9-NEXT:    addi 4, 4, x@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@toc@ha
-; PWR8-NEXT:    addi 3, 3, a@toc@l
-; PWR8-NEXT:    std 27, 72(1) # 8-byte Folded Spill
-; PWR8-NEXT:    lxvd2x 0, 0, 3
-; PWR8-NEXT:    addis 3, 2, y@toc@ha
-; PWR8-NEXT:    addi 3, 3, y@toc@l
-; PWR8-NEXT:    addi 28, 3, -16
-; PWR8-NEXT:    addis 3, 2, x@toc@ha
-; PWR8-NEXT:    addi 3, 3, x@toc@l
-; PWR8-NEXT:    addi 3, 3, -16
+; PWR8-NEXT:    addis 3, 2, .L_MergedGlobals@toc@ha
+; PWR8-NEXT:    li 29, 4
+; PWR8-NEXT:    addi 30, 3, .L_MergedGlobals@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@toc@ha
-; PWR9-NEXT:    addi 4, 4, y@toc@l
-; PWR9-NEXT:    addi 4, 4, -16
+; PWR9-NEXT:    addis 4, 2, .L_MergedGlobals@toc@ha
+; PWR9-NEXT:    addi 4, 4, .L_MergedGlobals@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@toc@ha
+; PWR8-NEXT:    addis 3, 2, .L_MergedGlobals@toc@ha
 ; PWR8-NEXT:    li 29, 4
 ; PWR8-NEXT:    std 0, 80(1)
-; PWR8-NEXT:    addi 3, 3, y@toc@l
-; PWR8-NEXT:    addi 28, 3, -16
+; PWR8-NEXT:    addi 3, 3, .L_MergedGlobals@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@toc@ha
-; PWR9-NEXT:    addi 4, 4, x@toc@l
-; PWR9-NEXT:    addi 4, 4, -16
+; PWR9-NEXT:    addis 4, 2, .L_MergedGlobals@toc@ha
+; PWR9-NEXT:    addi 4, 4, .L_MergedGlobals@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@toc@ha
+; PWR8-NEXT:    addis 3, 2, .L_MergedGlobals@toc@ha
 ; PWR8-NEXT:    li 29, 4
 ; PWR8-NEXT:    std 0, 80(1)
-; PWR8-NEXT:    addi 3, 3, x@toc@l
-; PWR8-NEXT:    addi 28, 3, -16
+; PWR8-NEXT:    addi 28, 3, .L_MergedGlobals@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@toc@ha
+; CHECK-GEN-ISEL-TRUE-NEXT:    addis r3, r2, .L_MergedGlobals@toc@ha
+; CHECK-GEN-ISEL-TRUE-NEXT:    addi r5, r3, .L_MergedGlobals@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@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@toc@ha
+; CHECK-NEXT:    addis r3, r2, .L_MergedGlobals@toc@ha
+; CHECK-NEXT:    addi r5, r3, .L_MergedGlobals@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@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@toc@ha
-; CHECK:       addi 26, 4, .L__ModuleStringPool@toc@l
+; CHECK:       addis 4, 2, .L_MergedGlobals@toc@ha
+; CHECK:       addi 26, 4, .L_MergedGlobals@toc@l
 ; CHECK:       .LBB0_2: # %for.cond
-; CHECK-NOT:   addis {{[0-9]+}}, 2, .L__ModuleStringPool@toc@ha
+; CHECK-NOT:   addis {{[0-9]+}}, 2, .L_MergedGlobals@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@toc@ha
-; LINUX64BE-NEXT:    li r4, 0
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals@toc@ha
 ; LINUX64BE-NEXT:    std r0, 128(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool@toc@l
-; LINUX64BE-NEXT:    ori r4, r4, 35612
-; LINUX64BE-NEXT:    add r3, r3, r4
+; LINUX64BE-NEXT:    addi r3, r3, .L_MergedGlobals@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@toc@ha
-; LINUX64LE-NEXT:    li r4, 0
-; LINUX64LE-NEXT:    std r0, 48(r1)
-; LINUX64LE-NEXT:    addi r3, r3, .L__ModuleStringPool@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@toc@ha
+; LINUX64LE-NEXT:     std r0, 48(r1)
+; LINUX64LE-NEXT:     addi r3, r3, .L_MergedGlobals@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@toc@ha
-; LINUX64BE-NEXT:    li r4, 0
+; LINUX64BE-NEXT:    addis r3, r2, .L_MergedGlobals@toc@ha
+; LINUX64BE-NEXT:    li r4, 24
 ; LINUX64BE-NEXT:    std r0, 160(r1)
-; LINUX64BE-NEXT:    addi r3, r3, .L__ModuleStringPool@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@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:
 ; LINUX6...
[truncated]

Copy link

github-actions bot commented Nov 4, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@stefanp-synopsys stefanp-synopsys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor nits.
LGTM.

: (TM->getTargetTriple().isOSLinux() &&
getOptLevel() != CodeGenOptLevel::None))
addPass(createPPCMergeStringPoolPass());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't use this pass anymore you can probably just delete the pass source code as well. You can do it in this patch or in another patch if you prefer that.

@@ -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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
Maybe we can flatten this if statement.

auto *I = dyn_cast<Instruction>(CurrentUser);
if (!I)
  continue;
  <rest of code...>

if (!I)
continue;
// Do not merge globals in exception pads.
if (I->isEHPad())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already handled in

if (!Pad->isEHPad())
? All code for globals that cannot be merged based on uses should be kept in there.

@syzaara syzaara requested a review from nikic November 7, 2024 16:10
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, happy to see the custom pass go away...

Comment on lines +636 to 639
auto *II = dyn_cast<IntrinsicInst>(Pad);
if (!Pad->isEHPad() &&
!(II && II->getIntrinsicID() == Intrinsic::eh_typeid_for))
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto *II = dyn_cast<IntrinsicInst>(Pad);
if (!Pad->isEHPad() &&
!(II && II->getIntrinsicID() == Intrinsic::eh_typeid_for))
continue;
if (!Pad->isEHPad())
continue;
if (auto *II = dyn_cast<IntrinsicInst>(Pad))
if (II->getIntrinsicID() == Intrinsic::eh_typeid_for))
continue;

nit: I'd separate the two ifs here.

Copy link
Contributor Author

@syzaara syzaara Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't split the if statements this way since we want to continue if its neither an EHPad instruction or an Intrinsic::eh_typeid_for instruction.

Alternate could be:

      if (!Pad->isEHPad()) {
        auto *II = dyn_cast<IntrinsicInst>(Pad);
        if (!II)
          continue;
        if (II->getIntrinsicID() != Intrinsic::eh_typeid_for)
          continue;
      }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I completely misread the code here. I think your original version was already the best one then.

continue;

// Keep globals used by landingpads and catchpads.
// Keep globals used by landingpads, catchpads,
// or instrinsics that require a plain global.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// or instrinsics that require a plain global.
// or intrinsics that require a plain global.

@@ -1,52 +0,0 @@
# RUN: llc -run-pass=ppc-merge-strings -mcpu=pwr8 -mtriple powerpc64le-unknown-linux-gnu \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this already covered by other tests? Can GlobalMerge not run on this? I guess this question applies to the other test that was deleted, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mir tests deleted were specific to the string pooling pass. They don't apply to global-merge and hence were removed.

@syzaara syzaara merged commit aaa37d6 into llvm:main Nov 12, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants