Skip to content

Commit 90a52f4

Browse files
committed
[LoongArch] Pass OptLevel to LoongArchDAGToDAGISel correctly
Like many other targets did. And see RISCV for similar fix. Fix #143239
1 parent fcc82cf commit 90a52f4

File tree

7 files changed

+17
-22
lines changed

7 files changed

+17
-22
lines changed

llvm/lib/Target/LoongArch/LoongArch.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ bool lowerLoongArchMachineOperandToMCOperand(const MachineOperand &MO,
3535

3636
FunctionPass *createLoongArchDeadRegisterDefinitionsPass();
3737
FunctionPass *createLoongArchExpandAtomicPseudoPass();
38-
FunctionPass *createLoongArchISelDag(LoongArchTargetMachine &TM);
38+
FunctionPass *createLoongArchISelDag(LoongArchTargetMachine &TM,
39+
CodeGenOptLevel OptLevel);
3940
FunctionPass *createLoongArchMergeBaseOffsetOptPass();
4041
FunctionPass *createLoongArchOptWInstrsPass();
4142
FunctionPass *createLoongArchPreRAExpandPseudoPass();

llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ using namespace llvm;
2525
char LoongArchDAGToDAGISelLegacy::ID;
2626

2727
LoongArchDAGToDAGISelLegacy::LoongArchDAGToDAGISelLegacy(
28-
LoongArchTargetMachine &TM)
29-
: SelectionDAGISelLegacy(ID, std::make_unique<LoongArchDAGToDAGISel>(TM)) {}
28+
LoongArchTargetMachine &TM, CodeGenOptLevel OptLevel)
29+
: SelectionDAGISelLegacy(
30+
ID, std::make_unique<LoongArchDAGToDAGISel>(TM, OptLevel)) {}
3031

3132
INITIALIZE_PASS(LoongArchDAGToDAGISelLegacy, DEBUG_TYPE, PASS_NAME, false,
3233
false)
@@ -456,6 +457,7 @@ bool LoongArchDAGToDAGISel::selectVSplatUimmPow2(SDValue N,
456457

457458
// This pass converts a legalized DAG into a LoongArch-specific DAG, ready
458459
// for instruction scheduling.
459-
FunctionPass *llvm::createLoongArchISelDag(LoongArchTargetMachine &TM) {
460-
return new LoongArchDAGToDAGISelLegacy(TM);
460+
FunctionPass *llvm::createLoongArchISelDag(LoongArchTargetMachine &TM,
461+
CodeGenOptLevel OptLevel) {
462+
return new LoongArchDAGToDAGISelLegacy(TM, OptLevel);
461463
}

llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class LoongArchDAGToDAGISel : public SelectionDAGISel {
2626
public:
2727
LoongArchDAGToDAGISel() = delete;
2828

29-
explicit LoongArchDAGToDAGISel(LoongArchTargetMachine &TM)
30-
: SelectionDAGISel(TM) {}
29+
explicit LoongArchDAGToDAGISel(LoongArchTargetMachine &TM,
30+
CodeGenOptLevel OptLevel)
31+
: SelectionDAGISel(TM, OptLevel) {}
3132

3233
bool runOnMachineFunction(MachineFunction &MF) override {
3334
Subtarget = &MF.getSubtarget<LoongArchSubtarget>();
@@ -93,7 +94,8 @@ class LoongArchDAGToDAGISel : public SelectionDAGISel {
9394
class LoongArchDAGToDAGISelLegacy : public SelectionDAGISelLegacy {
9495
public:
9596
static char ID;
96-
explicit LoongArchDAGToDAGISelLegacy(LoongArchTargetMachine &TM);
97+
explicit LoongArchDAGToDAGISelLegacy(LoongArchTargetMachine &TM,
98+
CodeGenOptLevel OptLevel);
9799
};
98100

99101
} // end namespace llvm

llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void LoongArchPassConfig::addCodeGenPrepare() {
189189
}
190190

191191
bool LoongArchPassConfig::addInstSelector() {
192-
addPass(createLoongArchISelDag(getLoongArchTargetMachine()));
192+
addPass(createLoongArchISelDag(getLoongArchTargetMachine(), getOptLevel()));
193193

194194
return false;
195195
}

llvm/test/CodeGen/LoongArch/O0-pipeline.ll

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,7 @@
3434
; CHECK-NEXT: Safe Stack instrumentation pass
3535
; CHECK-NEXT: Insert stack protectors
3636
; CHECK-NEXT: Module Verifier
37-
; CHECK-NEXT: Dominator Tree Construction
38-
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
39-
; CHECK-NEXT: Function Alias Analysis Results
40-
; CHECK-NEXT: Natural Loop Information
41-
; CHECK-NEXT: Post-Dominator Tree Construction
42-
; CHECK-NEXT: Branch Probability Analysis
4337
; CHECK-NEXT: Assignment Tracking Analysis
44-
; CHECK-NEXT: Lazy Branch Probability Analysis
45-
; CHECK-NEXT: Lazy Block Frequency Analysis
4638
; CHECK-NEXT: LoongArch DAG->DAG Pattern Instruction Selection
4739
; CHECK-NEXT: Finalize ISel and expand pseudo-instructions
4840
; CHECK-NEXT: Local Stack Slot Allocation

llvm/test/CodeGen/LoongArch/isel-optnone.ll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
; RUN: llc %s -O0 -mtriple=loongarch64 -o /dev/null -debug-only=isel 2>&1 | FileCheck %s
33

44
define void @fooOptnone() #0 {
5-
; CHECK: Changing optimization level for Function fooOptnone
6-
; CHECK: Before: -O2 ; After: -O0
7-
8-
; CHECK: Restoring optimization level for Function fooOptnone
9-
; CHECK: Before: -O0 ; After: -O2
5+
; CHECK-NOT: Changing optimization level for Function fooOptnone
6+
; CHECK-NOT: Restoring optimization level for Function fooOptnone
107
ret void
118
}
129

llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ define dso_local ptr @f(i32 noundef signext %i) "frame-pointer"="all" {
3939
; CHECK-NEXT: b .LBB0_3
4040
; CHECK-NEXT: .LBB0_3: # %if.end
4141
; CHECK-NEXT: ld.d $a0, $fp, -48 # 8-byte Folded Reload
42+
; CHECK-NEXT: addi.w $a0, $a0, 0
4243
; CHECK-NEXT: ori $a1, $zero, 1
4344
; CHECK-NEXT: bne $a0, $a1, .LBB0_6
4445
; CHECK-NEXT: b .LBB0_4

0 commit comments

Comments
 (0)