[PATCH] D129178: [RISCV] Enable the GlobalMerge pass for RISC-V
Alex Bradbury via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 25 06:28:43 PDT 2022
asb updated this revision to Diff 447306.
asb edited the summary of this revision.
asb added a comment.
Change this patch so it follows-on from the newly split D130481 <https://reviews.llvm.org/D130481> (which adds support for GlobalMerge). This allows us to separately review and merge basic support vs changes to the default pass pipeline.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129178/new/
https://reviews.llvm.org/D129178
Files:
llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
llvm/test/CodeGen/RISCV/O3-pipeline.ll
llvm/test/CodeGen/RISCV/global-merge-minsize.ll
Index: llvm/test/CodeGen/RISCV/global-merge-minsize.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/global-merge-minsize.ll
@@ -0,0 +1,43 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
+; RUN: | FileCheck %s
+; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
+; RUN: | FileCheck %s
+
+ at eg1 = dso_local global i32 0, align 4
+ at eg2 = dso_local global i32 0, align 4
+ at eg3 = dso_local global i32 0, align 4
+ at eg4 = dso_local global i32 0, align 4
+
+; Demonstrate that at the default optimisation level, global merging takes
+; place for globals referenced in minsize functions but not others.
+
+define void @f1(i32 %a) nounwind {
+; CHECK-LABEL: f1:
+; CHECK: # %bb.0:
+; CHECK-NEXT: lui a1, %hi(eg1)
+; CHECK-NEXT: sw a0, %lo(eg1)(a1)
+; CHECK-NEXT: lui a1, %hi(eg2)
+; CHECK-NEXT: sw a0, %lo(eg2)(a1)
+; CHECK-NEXT: ret
+ store i32 %a, ptr @eg1, align 4
+ store i32 %a, ptr @eg2, align 4
+ ret void
+}
+
+; TODO: It would be better for code size to alter the first store below by
+; first fully materialising .L_MergedGlobals in a1 and then storing to it with
+; a 0 offset.
+
+define void @f2(i32 %a) nounwind minsize optsize {
+; CHECK-LABEL: f2:
+; CHECK: # %bb.0:
+; CHECK-NEXT: lui a1, %hi(.L_MergedGlobals)
+; CHECK-NEXT: sw a0, %lo(.L_MergedGlobals)(a1)
+; CHECK-NEXT: addi a1, a1, %lo(.L_MergedGlobals)
+; CHECK-NEXT: sw a0, 4(a1)
+; CHECK-NEXT: ret
+ store i32 %a, ptr @eg3, align 4
+ store i32 %a, ptr @eg4, align 4
+ ret void
+}
Index: llvm/test/CodeGen/RISCV/O3-pipeline.ll
===================================================================
--- llvm/test/CodeGen/RISCV/O3-pipeline.ll
+++ llvm/test/CodeGen/RISCV/O3-pipeline.ll
@@ -63,6 +63,7 @@
; CHECK-NEXT: Exception handling preparation
; CHECK-NEXT: A No-Op Barrier Pass
; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT: Merge internal globals
; CHECK-NEXT: Safe Stack instrumentation pass
; CHECK-NEXT: Insert stack protectors
; CHECK-NEXT: Module Verifier
Index: llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -210,9 +210,13 @@
addPass(createBarrierNoopPass());
}
- if (EnableGlobalMerge == cl::BOU_TRUE) {
- addPass(createGlobalMergePass(TM, /* MaxOffset */ 2047,
- /* OnlyOptimizeForSize */ false,
+ if ((TM->getOptLevel() != CodeGenOpt::None &&
+ EnableGlobalMerge == cl::BOU_UNSET) ||
+ EnableGlobalMerge == cl::BOU_TRUE) {
+ bool OnlyOptimizeForSize = (TM->getOptLevel() < CodeGenOpt::Aggressive) &&
+ (EnableGlobalMerge == cl::BOU_UNSET);
+
+ addPass(createGlobalMergePass(TM, /* MaxOffset */ 2047, OnlyOptimizeForSize,
/* MergeExternalByDefault */ true));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129178.447306.patch
Type: text/x-patch
Size: 3098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220725/a61935bc/attachment.bin>
More information about the llvm-commits
mailing list