Skip to content

release/20.x: [LoongArch] Pass OptLevel to LoongArchDAGToDAGISel correctly #144459

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

Open
wants to merge 2 commits into
base: release/20.x
Choose a base branch
from
Open
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: 2 additions & 1 deletion llvm/lib/Target/LoongArch/LoongArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ bool lowerLoongArchMachineOperandToMCOperand(const MachineOperand &MO,

FunctionPass *createLoongArchDeadRegisterDefinitionsPass();
FunctionPass *createLoongArchExpandAtomicPseudoPass();
FunctionPass *createLoongArchISelDag(LoongArchTargetMachine &TM);
FunctionPass *createLoongArchISelDag(LoongArchTargetMachine &TM,
CodeGenOptLevel OptLevel);
FunctionPass *createLoongArchMergeBaseOffsetOptPass();
FunctionPass *createLoongArchOptWInstrsPass();
FunctionPass *createLoongArchPreRAExpandPseudoPass();
Expand Down
10 changes: 6 additions & 4 deletions llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ using namespace llvm;
char LoongArchDAGToDAGISelLegacy::ID;

LoongArchDAGToDAGISelLegacy::LoongArchDAGToDAGISelLegacy(
LoongArchTargetMachine &TM)
: SelectionDAGISelLegacy(ID, std::make_unique<LoongArchDAGToDAGISel>(TM)) {}
LoongArchTargetMachine &TM, CodeGenOptLevel OptLevel)
: SelectionDAGISelLegacy(
ID, std::make_unique<LoongArchDAGToDAGISel>(TM, OptLevel)) {}

INITIALIZE_PASS(LoongArchDAGToDAGISelLegacy, DEBUG_TYPE, PASS_NAME, false,
false)
Expand Down Expand Up @@ -456,6 +457,7 @@ bool LoongArchDAGToDAGISel::selectVSplatUimmPow2(SDValue N,

// This pass converts a legalized DAG into a LoongArch-specific DAG, ready
// for instruction scheduling.
FunctionPass *llvm::createLoongArchISelDag(LoongArchTargetMachine &TM) {
return new LoongArchDAGToDAGISelLegacy(TM);
FunctionPass *llvm::createLoongArchISelDag(LoongArchTargetMachine &TM,
CodeGenOptLevel OptLevel) {
return new LoongArchDAGToDAGISelLegacy(TM, OptLevel);
}
8 changes: 5 additions & 3 deletions llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class LoongArchDAGToDAGISel : public SelectionDAGISel {
public:
LoongArchDAGToDAGISel() = delete;

explicit LoongArchDAGToDAGISel(LoongArchTargetMachine &TM)
: SelectionDAGISel(TM) {}
explicit LoongArchDAGToDAGISel(LoongArchTargetMachine &TM,
CodeGenOptLevel OptLevel)
: SelectionDAGISel(TM, OptLevel) {}

bool runOnMachineFunction(MachineFunction &MF) override {
Subtarget = &MF.getSubtarget<LoongArchSubtarget>();
Expand Down Expand Up @@ -71,7 +72,8 @@ class LoongArchDAGToDAGISel : public SelectionDAGISel {
class LoongArchDAGToDAGISelLegacy : public SelectionDAGISelLegacy {
public:
static char ID;
explicit LoongArchDAGToDAGISelLegacy(LoongArchTargetMachine &TM);
explicit LoongArchDAGToDAGISelLegacy(LoongArchTargetMachine &TM,
CodeGenOptLevel OptLevel);
};

} // end namespace llvm
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void LoongArchPassConfig::addCodeGenPrepare() {
}

bool LoongArchPassConfig::addInstSelector() {
addPass(createLoongArchISelDag(getLoongArchTargetMachine()));
addPass(createLoongArchISelDag(getLoongArchTargetMachine(), getOptLevel()));

return false;
}
Expand Down
8 changes: 0 additions & 8 deletions llvm/test/CodeGen/LoongArch/O0-pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@
; CHECK-NEXT: Safe Stack instrumentation pass
; CHECK-NEXT: Insert stack protectors
; CHECK-NEXT: Module Verifier
; CHECK-NEXT: Dominator Tree Construction
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
; CHECK-NEXT: Function Alias Analysis Results
; CHECK-NEXT: Natural Loop Information
; CHECK-NEXT: Post-Dominator Tree Construction
; CHECK-NEXT: Branch Probability Analysis
; CHECK-NEXT: Assignment Tracking Analysis
; CHECK-NEXT: Lazy Branch Probability Analysis
; CHECK-NEXT: Lazy Block Frequency Analysis
; CHECK-NEXT: LoongArch DAG->DAG Pattern Instruction Selection
; CHECK-NEXT: Finalize ISel and expand pseudo-instructions
; CHECK-NEXT: Local Stack Slot Allocation
Expand Down
10 changes: 10 additions & 0 deletions llvm/test/CodeGen/LoongArch/isel-optnone.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; REQUIRES: asserts
; RUN: llc %s -O0 -mtriple=loongarch64 -o /dev/null -debug-only=isel 2>&1 | FileCheck %s

define void @fooOptnone() #0 {
; CHECK-NOT: Changing optimization level for Function fooOptnone
; CHECK-NOT: Restoring optimization level for Function fooOptnone
ret void
}

attributes #0 = { nounwind optnone noinline }
1 change: 1 addition & 0 deletions llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ define dso_local ptr @f(i32 noundef signext %i) "frame-pointer"="all" {
; CHECK-NEXT: b .LBB0_3
; CHECK-NEXT: .LBB0_3: # %if.end
; CHECK-NEXT: ld.d $a0, $fp, -48 # 8-byte Folded Reload
; CHECK-NEXT: addi.w $a0, $a0, 0
; CHECK-NEXT: ori $a1, $zero, 1
; CHECK-NEXT: bne $a0, $a1, .LBB0_6
; CHECK-NEXT: b .LBB0_4
Expand Down
Loading