Skip to content

Commit ccddd13

Browse files
authored
Enable aggressive constant merge in GlobalMerge for AIX (#113956)
Enable merging all constants without looking at use in GlobalMerge by default to replace PPCMergeStringPool pass on AIX.
1 parent 221cbae commit ccddd13

12 files changed

+214
-180
lines changed

llvm/include/llvm/CodeGen/GlobalMerge.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ struct GlobalMergeOptions {
3030
bool MergeExternal = true;
3131
/// Whether we should merge constant global variables.
3232
bool MergeConstantGlobals = false;
33+
/// Whether we should merge constant global variables aggressively without
34+
/// looking at use.
35+
bool MergeConstAggressive = false;
3336
/// Whether we should try to optimize for size only.
3437
/// Currently, this applies a dead simple heuristic: only consider globals
3538
/// used in minsize functions for merging.

llvm/include/llvm/CodeGen/Passes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ namespace llvm {
480480
Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset,
481481
bool OnlyOptimizeForSize = false,
482482
bool MergeExternalByDefault = false,
483-
bool MergeConstantByDefault = false);
483+
bool MergeConstantByDefault = false,
484+
bool MergeConstAggressiveByDefault = false);
484485

485486
/// This pass splits the stack into a safe stack and an unsafe stack to
486487
/// protect against stack-based overflow vulnerabilities.

llvm/lib/CodeGen/GlobalMerge.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,13 @@ class GlobalMerge : public FunctionPass {
202202

203203
explicit GlobalMerge(const TargetMachine *TM, unsigned MaximalOffset,
204204
bool OnlyOptimizeForSize, bool MergeExternalGlobals,
205-
bool MergeConstantGlobals)
205+
bool MergeConstantGlobals, bool MergeConstAggressive)
206206
: FunctionPass(ID), TM(TM) {
207207
Opt.MaxOffset = MaximalOffset;
208208
Opt.SizeOnly = OnlyOptimizeForSize;
209209
Opt.MergeExternal = MergeExternalGlobals;
210210
Opt.MergeConstantGlobals = MergeConstantGlobals;
211+
Opt.MergeConstAggressive = MergeConstAggressive;
211212
initializeGlobalMergePass(*PassRegistry::getPassRegistry());
212213
}
213214

@@ -268,7 +269,7 @@ bool GlobalMergeImpl::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
268269
});
269270

270271
// If we want to just blindly group all globals together, do so.
271-
if (!GlobalMergeGroupByUse || (GlobalMergeAllConst && isConst)) {
272+
if (!GlobalMergeGroupByUse || (Opt.MergeConstAggressive && isConst)) {
272273
BitVector AllGlobals(Globals.size());
273274
AllGlobals.set();
274275
return doMerge(Globals, AllGlobals, M, isConst, AddrSpace);
@@ -758,10 +759,14 @@ bool GlobalMergeImpl::run(Module &M) {
758759
Pass *llvm::createGlobalMergePass(const TargetMachine *TM, unsigned Offset,
759760
bool OnlyOptimizeForSize,
760761
bool MergeExternalByDefault,
761-
bool MergeConstantByDefault) {
762+
bool MergeConstantByDefault,
763+
bool MergeConstAggressiveByDefault) {
762764
bool MergeExternal = (EnableGlobalMergeOnExternal == cl::BOU_UNSET) ?
763765
MergeExternalByDefault : (EnableGlobalMergeOnExternal == cl::BOU_TRUE);
764766
bool MergeConstant = EnableGlobalMergeOnConst || MergeConstantByDefault;
767+
bool MergeConstAggressive = GlobalMergeAllConst.getNumOccurrences() > 0
768+
? GlobalMergeAllConst
769+
: MergeConstAggressiveByDefault;
765770
return new GlobalMerge(TM, Offset, OnlyOptimizeForSize, MergeExternal,
766-
MergeConstant);
771+
MergeConstant, MergeConstAggressive);
767772
}

llvm/lib/Target/PowerPC/PPCTargetMachine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,13 @@ bool PPCPassConfig::addPreISel() {
505505
? EnableGlobalMerge
506506
: (TM->getTargetTriple().isOSAIX() &&
507507
getOptLevel() != CodeGenOptLevel::None))
508-
addPass(
509-
createGlobalMergePass(TM, GlobalMergeMaxOffset, false, false, true));
508+
addPass(createGlobalMergePass(TM, GlobalMergeMaxOffset, false, false, true,
509+
true));
510510

511-
if (MergeStringPool && getOptLevel() != CodeGenOptLevel::None)
511+
if ((MergeStringPool.getNumOccurrences() > 0)
512+
? MergeStringPool
513+
: (TM->getTargetTriple().isOSLinux() &&
514+
getOptLevel() != CodeGenOptLevel::None))
512515
addPass(createPPCMergeStringPoolPass());
513516

514517
if (!DisableInstrFormPrep && getOptLevel() != CodeGenOptLevel::None)

llvm/test/CodeGen/PowerPC/O3-pipeline.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@
7070
; CHECK-NEXT: CodeGen Prepare
7171
; CHECK-NEXT: Dominator Tree Construction
7272
; CHECK-NEXT: Exception handling preparation
73-
; CHECK-NEXT: PPC Merge String Pool
74-
; CHECK-NEXT: FunctionPass Manager
75-
; CHECK-NEXT: Dominator Tree Construction
7673
; CHECK-NEXT: Natural Loop Information
7774
; CHECK-NEXT: Scalar Evolution Analysis
7875
; CHECK-NEXT: Prepare loop for ppc preferred instruction forms

llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-const.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
; This file tests the codegen of mergeable const in AIX assembly.
22
; This file also tests mergeable const in XCOFF object file generation.
33
; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec -mtriple powerpc-ibm-aix-xcoff \
4-
; RUN: -data-sections=false -xcoff-traceback-table=false < %s | \
4+
; RUN: -global-merge-all-const=false -data-sections=false -xcoff-traceback-table=false < %s | \
55
; RUN: FileCheck --check-prefixes=CHECK,CHECK32 %s
66
; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec -mtriple powerpc64-ibm-aix-xcoff \
7-
; RUN: -xcoff-traceback-table=false -data-sections=false < %s | \
7+
; RUN: -global-merge-all-const=false -xcoff-traceback-table=false -data-sections=false < %s | \
88
; RUN: FileCheck --check-prefixes=CHECK,CHECK64 %s
99
; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec -mtriple powerpc-ibm-aix-xcoff \
10-
; RUN: -xcoff-traceback-table=false -data-sections=false -filetype=obj -o %t.o < %s
10+
; RUN: -global-merge-all-const=false -xcoff-traceback-table=false -data-sections=false -filetype=obj -o %t.o < %s
1111
; RUN: llvm-objdump -D %t.o | FileCheck --check-prefix=CHECKOBJ %s
1212
; RUN: llvm-readobj -s %t.o | FileCheck --check-prefix=CHECKSYM %s
1313

llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
; tests for XCOFF object files.
55

66
; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec -xcoff-traceback-table=false \
7-
; RUN: -mtriple powerpc-ibm-aix-xcoff -data-sections=false -ppc-merge-string-pool=false < %s | FileCheck %s
7+
; RUN: -mtriple powerpc-ibm-aix-xcoff -data-sections=false -ppc-merge-string-pool=false \
8+
; RUN: -global-merge-all-const=false < %s | FileCheck %s
89
; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec -xcoff-traceback-table=false \
9-
; RUN: -mtriple powerpc64-ibm-aix-xcoff -data-sections=false -ppc-merge-string-pool=false < %s | FileCheck %s
10+
; RUN: -mtriple powerpc64-ibm-aix-xcoff -data-sections=false -ppc-merge-string-pool=false \
11+
; RUN: -global-merge-all-const=false < %s | FileCheck %s
1012

1113
; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec -mtriple powerpc-ibm-aix-xcoff \
12-
; RUN: -xcoff-traceback-table=false -data-sections=false -ppc-merge-string-pool=false -filetype=obj -o %t.o < %s
14+
; RUN: -xcoff-traceback-table=false -data-sections=false -ppc-merge-string-pool=false \
15+
; RUN: -global-merge-all-const=false -filetype=obj -o %t.o < %s
1316
; RUN: llvm-objdump -D %t.o | FileCheck --check-prefix=CHECKOBJ %s
1417

1518
@magic16 = private unnamed_addr constant [4 x i16] [i16 264, i16 272, i16 213, i16 0], align 2

llvm/test/CodeGen/PowerPC/aix-xcoff-used-with-stringpool.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
;; Test that the string pooling pass does not pool globals that are
22
;; in llvm.used or in llvm.compiler.used.
33

4-
; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc-ibm-aix-xcoff -data-sections=false < %s | \
4+
; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc-ibm-aix-xcoff \
5+
; RUN: -ppc-merge-string-pool=true -global-merge-all-const=false -data-sections=false < %s | \
56
; RUN: FileCheck %s
67

7-
; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc64-ibm-aix-xcoff -data-sections=false < %s | \
8+
; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc64-ibm-aix-xcoff \
9+
; RUN: -ppc-merge-string-pool=true -global-merge-all-const=false -data-sections=false < %s | \
810
; RUN: FileCheck %s
911

1012
@keep_this = internal constant [5 x i8] c"keep1", align 1

llvm/test/CodeGen/PowerPC/merge-private.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
22
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr8 \
3-
; RUN: -ppc-asm-full-reg-names -ppc-global-merge=true < %s | FileCheck %s \
3+
; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s \
44
; RUN: --check-prefix=AIX64
55
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr8 \
6-
; RUN: -ppc-asm-full-reg-names -ppc-global-merge=true < %s | FileCheck %s \
6+
; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s \
77
; RUN: --check-prefix=AIX32
88
; RUN: llc -verify-machineinstrs -mtriple powerpc64le-unknown-linux -mcpu=pwr8 \
99
; RUN: -ppc-asm-full-reg-names -ppc-global-merge=true < %s | FileCheck %s \

0 commit comments

Comments
 (0)