Skip to content

Enable aggressive constant merge in GlobalMerge for AIX #113956

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 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/CodeGen/GlobalMerge.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ struct GlobalMergeOptions {
bool MergeExternal = true;
/// Whether we should merge constant global variables.
bool MergeConstantGlobals = false;
/// Whether we should merge constant global variables aggressively without
/// looking at use.
bool MergeConstAggressive = false;
/// Whether we should try to optimize for size only.
/// Currently, this applies a dead simple heuristic: only consider globals
/// used in minsize functions for merging.
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/CodeGen/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ namespace llvm {
Pass *createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset,
bool OnlyOptimizeForSize = false,
bool MergeExternalByDefault = false,
bool MergeConstantByDefault = false);
bool MergeConstantByDefault = false,
bool MergeConstAggressiveByDefault = false);

/// This pass splits the stack into a safe stack and an unsafe stack to
/// protect against stack-based overflow vulnerabilities.
Expand Down
13 changes: 9 additions & 4 deletions llvm/lib/CodeGen/GlobalMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,13 @@ class GlobalMerge : public FunctionPass {

explicit GlobalMerge(const TargetMachine *TM, unsigned MaximalOffset,
bool OnlyOptimizeForSize, bool MergeExternalGlobals,
bool MergeConstantGlobals)
bool MergeConstantGlobals, bool MergeConstAggressive)
: FunctionPass(ID), TM(TM) {
Opt.MaxOffset = MaximalOffset;
Opt.SizeOnly = OnlyOptimizeForSize;
Opt.MergeExternal = MergeExternalGlobals;
Opt.MergeConstantGlobals = MergeConstantGlobals;
Opt.MergeConstAggressive = MergeConstAggressive;
initializeGlobalMergePass(*PassRegistry::getPassRegistry());
}

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

// If we want to just blindly group all globals together, do so.
if (!GlobalMergeGroupByUse || (GlobalMergeAllConst && isConst)) {
if (!GlobalMergeGroupByUse || (Opt.MergeConstAggressive && isConst)) {
BitVector AllGlobals(Globals.size());
AllGlobals.set();
return doMerge(Globals, AllGlobals, M, isConst, AddrSpace);
Expand Down Expand Up @@ -758,10 +759,14 @@ bool GlobalMergeImpl::run(Module &M) {
Pass *llvm::createGlobalMergePass(const TargetMachine *TM, unsigned Offset,
bool OnlyOptimizeForSize,
bool MergeExternalByDefault,
bool MergeConstantByDefault) {
bool MergeConstantByDefault,
bool MergeConstAggressiveByDefault) {
bool MergeExternal = (EnableGlobalMergeOnExternal == cl::BOU_UNSET) ?
MergeExternalByDefault : (EnableGlobalMergeOnExternal == cl::BOU_TRUE);
bool MergeConstant = EnableGlobalMergeOnConst || MergeConstantByDefault;
bool MergeConstAggressive = GlobalMergeAllConst.getNumOccurrences() > 0
? GlobalMergeAllConst
: MergeConstAggressiveByDefault;
return new GlobalMerge(TM, Offset, OnlyOptimizeForSize, MergeExternal,
MergeConstant);
MergeConstant, MergeConstAggressive);
}
9 changes: 6 additions & 3 deletions llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,13 @@ bool PPCPassConfig::addPreISel() {
? EnableGlobalMerge
: (TM->getTargetTriple().isOSAIX() &&
getOptLevel() != CodeGenOptLevel::None))
addPass(
createGlobalMergePass(TM, GlobalMergeMaxOffset, false, false, true));
addPass(createGlobalMergePass(TM, GlobalMergeMaxOffset, false, false, true,
true));

if (MergeStringPool && getOptLevel() != CodeGenOptLevel::None)
if ((MergeStringPool.getNumOccurrences() > 0)
? MergeStringPool
: (TM->getTargetTriple().isOSLinux() &&
getOptLevel() != CodeGenOptLevel::None))
addPass(createPPCMergeStringPoolPass());

if (!DisableInstrFormPrep && getOptLevel() != CodeGenOptLevel::None)
Expand Down
3 changes: 0 additions & 3 deletions llvm/test/CodeGen/PowerPC/O3-pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@
; CHECK-NEXT: CodeGen Prepare
; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Exception handling preparation
; CHECK-NEXT: PPC Merge String Pool
; CHECK-NEXT: FunctionPass Manager
; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Natural Loop Information
; CHECK-NEXT: Scalar Evolution Analysis
; CHECK-NEXT: Prepare loop for ppc preferred instruction forms
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-const.ll
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
; This file tests the codegen of mergeable const in AIX assembly.
; This file also tests mergeable const in XCOFF object file generation.
; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec -mtriple powerpc-ibm-aix-xcoff \
; RUN: -data-sections=false -xcoff-traceback-table=false < %s | \
; RUN: -global-merge-all-const=false -data-sections=false -xcoff-traceback-table=false < %s | \
; RUN: FileCheck --check-prefixes=CHECK,CHECK32 %s
; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec -mtriple powerpc64-ibm-aix-xcoff \
; RUN: -xcoff-traceback-table=false -data-sections=false < %s | \
; RUN: -global-merge-all-const=false -xcoff-traceback-table=false -data-sections=false < %s | \
; RUN: FileCheck --check-prefixes=CHECK,CHECK64 %s
; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mattr=-altivec -mtriple powerpc-ibm-aix-xcoff \
; RUN: -xcoff-traceback-table=false -data-sections=false -filetype=obj -o %t.o < %s
; RUN: -global-merge-all-const=false -xcoff-traceback-table=false -data-sections=false -filetype=obj -o %t.o < %s
; RUN: llvm-objdump -D %t.o | FileCheck --check-prefix=CHECKOBJ %s
; RUN: llvm-readobj -s %t.o | FileCheck --check-prefix=CHECKSYM %s

Expand Down
9 changes: 6 additions & 3 deletions llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
; tests for XCOFF object files.

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

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

@magic16 = private unnamed_addr constant [4 x i16] [i16 264, i16 272, i16 213, i16 0], align 2
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-xcoff-used-with-stringpool.ll
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
;; Test that the string pooling pass does not pool globals that are
;; in llvm.used or in llvm.compiler.used.

; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc-ibm-aix-xcoff -data-sections=false < %s | \
; 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: FileCheck %s

; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc64-ibm-aix-xcoff -data-sections=false < %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: FileCheck %s

@keep_this = internal constant [5 x i8] c"keep1", align 1
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/merge-private.ll
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -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=AIX64
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -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=AIX32
; RUN: llc -verify-machineinstrs -mtriple powerpc64le-unknown-linux -mcpu=pwr8 \
; RUN: -ppc-asm-full-reg-names -ppc-global-merge=true < %s | FileCheck %s \
Expand Down
Loading
Loading