Skip to content
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
7 changes: 6 additions & 1 deletion llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ static cl::opt<bool>
cl::desc("Enable the loop data prefetch pass"),
cl::init(false));

static cl::opt<bool>
EnableMergeBaseOffset("loongarch-enable-merge-offset",
cl::desc("Enable the merge base offset pass"),
cl::init(true), cl::Hidden);

static Reloc::Model getEffectiveRelocModel(const Triple &TT,
std::optional<Reloc::Model> RM) {
return RM.value_or(Reloc::Static);
Expand Down Expand Up @@ -214,7 +219,7 @@ void LoongArchPassConfig::addMachineSSAOptimization() {

void LoongArchPassConfig::addPreRegAlloc() {
addPass(createLoongArchPreRAExpandPseudoPass());
if (TM->getOptLevel() != CodeGenOptLevel::None)
if (TM->getOptLevel() != CodeGenOptLevel::None && EnableMergeBaseOffset)
addPass(createLoongArchMergeBaseOffsetOptPass());
}

Expand Down
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/LoongArch/merge-offset-option.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc --mtriple=loongarch64 -mattr=+d --relocation-model=static -O1 \
; RUN: < %s | FileCheck %s --check-prefix=MERGE
; RUN: llc --mtriple=loongarch64 -mattr=+d --relocation-model=static -O1 \
; RUN: --loongarch-enable-merge-offset=false < %s | FileCheck %s --check-prefix=NO_MERGE

@g = dso_local global i32 zeroinitializer, align 4

define void @foo() nounwind {
; MERGE-LABEL: foo:
; MERGE: # %bb.0:
; MERGE-NEXT: pcalau12i $a0, %pc_hi20(g)
; MERGE-NEXT: ld.w $zero, $a0, %pc_lo12(g)
; MERGE-NEXT: ret
;
; NO_MERGE-LABEL: foo:
; NO_MERGE: # %bb.0:
; NO_MERGE-NEXT: pcalau12i $a0, %pc_hi20(g)
; NO_MERGE-NEXT: addi.d $a0, $a0, %pc_lo12(g)
; NO_MERGE-NEXT: ld.w $zero, $a0, 0
; NO_MERGE-NEXT: ret
%v = load volatile i32, ptr @g
ret void
}