Skip to content

Commit cac0635

Browse files
authored
[LoongArch] Add option for merge base offset pass
Add `loongarch-enable-merge-offset` option to allow disabling the `MergeBaseOffset` pass when using optimization. Reviewers: SixWeining, heiher Reviewed By: SixWeining, heiher Pull Request: #161063
1 parent 12f42e5 commit cac0635

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ static cl::opt<bool>
5757
cl::desc("Enable the loop data prefetch pass"),
5858
cl::init(false));
5959

60+
static cl::opt<bool>
61+
EnableMergeBaseOffset("loongarch-enable-merge-offset",
62+
cl::desc("Enable the merge base offset pass"),
63+
cl::init(true), cl::Hidden);
64+
6065
static Reloc::Model getEffectiveRelocModel(const Triple &TT,
6166
std::optional<Reloc::Model> RM) {
6267
return RM.value_or(Reloc::Static);
@@ -214,7 +219,7 @@ void LoongArchPassConfig::addMachineSSAOptimization() {
214219

215220
void LoongArchPassConfig::addPreRegAlloc() {
216221
addPass(createLoongArchPreRAExpandPseudoPass());
217-
if (TM->getOptLevel() != CodeGenOptLevel::None)
222+
if (TM->getOptLevel() != CodeGenOptLevel::None && EnableMergeBaseOffset)
218223
addPass(createLoongArchMergeBaseOffsetOptPass());
219224
}
220225

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc --mtriple=loongarch64 -mattr=+d --relocation-model=static -O1 \
3+
; RUN: < %s | FileCheck %s --check-prefix=MERGE
4+
; RUN: llc --mtriple=loongarch64 -mattr=+d --relocation-model=static -O1 \
5+
; RUN: --loongarch-enable-merge-offset=false < %s | FileCheck %s --check-prefix=NO_MERGE
6+
7+
@g = dso_local global i32 zeroinitializer, align 4
8+
9+
define void @foo() nounwind {
10+
; MERGE-LABEL: foo:
11+
; MERGE: # %bb.0:
12+
; MERGE-NEXT: pcalau12i $a0, %pc_hi20(g)
13+
; MERGE-NEXT: ld.w $zero, $a0, %pc_lo12(g)
14+
; MERGE-NEXT: ret
15+
;
16+
; NO_MERGE-LABEL: foo:
17+
; NO_MERGE: # %bb.0:
18+
; NO_MERGE-NEXT: pcalau12i $a0, %pc_hi20(g)
19+
; NO_MERGE-NEXT: addi.d $a0, $a0, %pc_lo12(g)
20+
; NO_MERGE-NEXT: ld.w $zero, $a0, 0
21+
; NO_MERGE-NEXT: ret
22+
%v = load volatile i32, ptr @g
23+
ret void
24+
}

0 commit comments

Comments
 (0)