[llvm] 9d02264 - [RISCV] Enable global merging by default (#115495)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 15 05:22:37 PST 2024
Author: Alex Bradbury
Date: 2024-11-15T13:22:34Z
New Revision: 9d02264b03ea9cff356c2f1aecb9606864a671f2
URL: https://github.com/llvm/llvm-project/commit/9d02264b03ea9cff356c2f1aecb9606864a671f2
DIFF: https://github.com/llvm/llvm-project/commit/9d02264b03ea9cff356c2f1aecb9606864a671f2.diff
LOG: [RISCV] Enable global merging by default (#115495)
>From the discussion at the round-table at the RISC-V Summit it was clear
people see cases where global merging would help. So the direction of
enabling it by default and iteratively working to enable it in more
cases or to improve the heuristics seems sensible. This patch tries to
make a minimal step in that direction.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
llvm/test/CodeGen/RISCV/O3-pipeline.ll
llvm/test/CodeGen/RISCV/global-merge-minsize-smalldata-nonzero.ll
llvm/test/CodeGen/RISCV/global-merge-minsize-smalldata-zero.ll
llvm/test/CodeGen/RISCV/global-merge-minsize.ll
llvm/test/CodeGen/RISCV/global-merge-offset.ll
llvm/test/CodeGen/RISCV/global-merge.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
index 079850c1774bea..fa507653264ccd 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -474,7 +474,13 @@ bool RISCVPassConfig::addPreISel() {
addPass(createBarrierNoopPass());
}
- if (EnableGlobalMerge == cl::BOU_TRUE) {
+ if ((TM->getOptLevel() != CodeGenOptLevel::None &&
+ EnableGlobalMerge == cl::BOU_UNSET) ||
+ EnableGlobalMerge == cl::BOU_TRUE) {
+ // FIXME: Like AArch64, we disable extern global merging by default due to
+ // concerns it might regress some workloads. Unlike AArch64, we don't
+ // currently support enabling the pass in an "OnlyOptimizeForSize" mode.
+ // Investigating and addressing both items are TODO.
addPass(createGlobalMergePass(TM, /* MaxOffset */ 2047,
/* OnlyOptimizeForSize */ false,
/* MergeExternalByDefault */
diff --git a/llvm/test/CodeGen/RISCV/O3-pipeline.ll b/llvm/test/CodeGen/RISCV/O3-pipeline.ll
index a74c842c595526..8fd9ae98503665 100644
--- a/llvm/test/CodeGen/RISCV/O3-pipeline.ll
+++ b/llvm/test/CodeGen/RISCV/O3-pipeline.ll
@@ -74,6 +74,7 @@
; CHECK-NEXT: Exception handling preparation
; CHECK-NEXT: A No-Op Barrier Pass
; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT: Merge internal globals
; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
; CHECK-NEXT: Function Alias Analysis Results
diff --git a/llvm/test/CodeGen/RISCV/global-merge-minsize-smalldata-nonzero.ll b/llvm/test/CodeGen/RISCV/global-merge-minsize-smalldata-nonzero.ll
index 39c677ac20b3a5..156a34db827456 100644
--- a/llvm/test/CodeGen/RISCV/global-merge-minsize-smalldata-nonzero.ll
+++ b/llvm/test/CodeGen/RISCV/global-merge-minsize-smalldata-nonzero.ll
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=riscv64 -riscv-enable-global-merge -riscv-force-enable-global-merge-external-globals \
+; RUN: llc -mtriple=riscv64 -riscv-force-enable-global-merge-external-globals \
; RUN: -verify-machineinstrs < %s | FileCheck %s -check-prefix=SMALL-DATA
-; RUN: llc -mtriple=riscv64 -riscv-enable-global-merge -global-merge-min-data-size=0 \
+; RUN: llc -mtriple=riscv64 -global-merge-min-data-size=0 \
; RUN: -riscv-force-enable-global-merge-external-globals -verify-machineinstrs < %s \
; RUN: | FileCheck %s -check-prefix=MINSIZE
diff --git a/llvm/test/CodeGen/RISCV/global-merge-minsize-smalldata-zero.ll b/llvm/test/CodeGen/RISCV/global-merge-minsize-smalldata-zero.ll
index d2b714577db9a8..e41f14d394b7ca 100644
--- a/llvm/test/CodeGen/RISCV/global-merge-minsize-smalldata-zero.ll
+++ b/llvm/test/CodeGen/RISCV/global-merge-minsize-smalldata-zero.ll
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=riscv32 -riscv-enable-global-merge -riscv-force-enable-global-merge-external-globals \
+; RUN: llc -mtriple=riscv32 -riscv-force-enable-global-merge-external-globals \
; RUN: -verify-machineinstrs < %s | FileCheck %s -check-prefix=SMALL-DATA
-; RUN: llc -mtriple=riscv64 -riscv-enable-global-merge -global-merge-min-data-size=5 \
+; RUN: llc -mtriple=riscv64 -global-merge-min-data-size=5 \
; RUN: -riscv-force-enable-global-merge-external-globals -verify-machineinstrs < %s \
; RUN: | FileCheck %s -check-prefix=MINSIZE
diff --git a/llvm/test/CodeGen/RISCV/global-merge-minsize.ll b/llvm/test/CodeGen/RISCV/global-merge-minsize.ll
index 696d163bdcb2c4..1d65d9d1732ba3 100644
--- a/llvm/test/CodeGen/RISCV/global-merge-minsize.ll
+++ b/llvm/test/CodeGen/RISCV/global-merge-minsize.ll
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=riscv32 -riscv-enable-global-merge -riscv-force-enable-global-merge-external-globals \
+; RUN: llc -mtriple=riscv32 -riscv-force-enable-global-merge-external-globals \
; RUN: -verify-machineinstrs < %s | FileCheck %s -check-prefix=RV32
-; RUN: llc -mtriple=riscv32 -riscv-enable-global-merge -global-merge-min-data-size=5 \
+; RUN: llc -mtriple=riscv32 -global-merge-min-data-size=5 \
; RUN: -riscv-force-enable-global-merge-external-globals -verify-machineinstrs < %s | FileCheck %s -check-prefix=RV32-MINSIZE
@ig1 = internal global i32 0, align 4
diff --git a/llvm/test/CodeGen/RISCV/global-merge-offset.ll b/llvm/test/CodeGen/RISCV/global-merge-offset.ll
index 0c0881ddf28737..bb8264ee438545 100644
--- a/llvm/test/CodeGen/RISCV/global-merge-offset.ll
+++ b/llvm/test/CodeGen/RISCV/global-merge-offset.ll
@@ -1,11 +1,11 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: sed 's/ArrSize/100/g' %s | llc -mtriple=riscv32 -riscv-enable-global-merge \
+; RUN: sed 's/ArrSize/100/g' %s | llc -mtriple=riscv32 \
; RUN: -riscv-force-enable-global-merge-external-globals -verify-machineinstrs | FileCheck %s
-; RUN: sed 's/ArrSize/100/g' %s | llc -mtriple=riscv64 -riscv-enable-global-merge \
+; RUN: sed 's/ArrSize/100/g' %s | llc -mtriple=riscv64 \
; RUN: -riscv-force-enable-global-merge-external-globals -verify-machineinstrs | FileCheck %s
-; RUN: sed 's/ArrSize/101/g' %s | llc -mtriple=riscv32 -riscv-enable-global-merge \
+; RUN: sed 's/ArrSize/101/g' %s | llc -mtriple=riscv32 \
; RUN: -riscv-force-enable-global-merge-external-globals -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-TOOBIG
-; RUN: sed 's/ArrSize/101/g' %s | llc -mtriple=riscv64 -riscv-enable-global-merge \
+; RUN: sed 's/ArrSize/101/g' %s | llc -mtriple=riscv64 \
; RUN: -riscv-force-enable-global-merge-external-globals -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-TOOBIG
; This test demonstrates that the MaxOffset is set correctly for RISC-V by
diff --git a/llvm/test/CodeGen/RISCV/global-merge.ll b/llvm/test/CodeGen/RISCV/global-merge.ll
index 9dde032b69f8b1..327a6b54f4be25 100644
--- a/llvm/test/CodeGen/RISCV/global-merge.ll
+++ b/llvm/test/CodeGen/RISCV/global-merge.ll
@@ -1,12 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -mtriple=riscv32 -riscv-enable-global-merge -verify-machineinstrs < %s \
-; RUN: | FileCheck %s
-; RUN: llc -mtriple=riscv64 -riscv-enable-global-merge -verify-machineinstrs < %s \
-; RUN: | FileCheck %s
-; RUN: llc -mtriple=riscv32 -riscv-enable-global-merge \
+; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s | FileCheck %s
+; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s | FileCheck %s
+; RUN: llc -mtriple=riscv32 \
; RUN: -riscv-force-enable-global-merge-external-globals -verify-machineinstrs < %s \
; RUN: | FileCheck -check-prefix=CHECK-WEXTERN %s
-; RUN: llc -mtriple=riscv64 -riscv-enable-global-merge \
+; RUN: llc -mtriple=riscv64 \
; RUN: -riscv-force-enable-global-merge-external-globals -verify-machineinstrs < %s \
; RUN: | FileCheck -check-prefix=CHECK-WEXTERN %s
More information about the llvm-commits
mailing list