[llvm] 90a52f4 - [LoongArch] Pass OptLevel to LoongArchDAGToDAGISel correctly
Weining Lu via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 7 00:35:15 PDT 2025
Author: Weining Lu
Date: 2025-06-07T15:33:58+08:00
New Revision: 90a52f4942961a5c32afc69d69470c6b7e5bcb8a
URL: https://github.com/llvm/llvm-project/commit/90a52f4942961a5c32afc69d69470c6b7e5bcb8a
DIFF: https://github.com/llvm/llvm-project/commit/90a52f4942961a5c32afc69d69470c6b7e5bcb8a.diff
LOG: [LoongArch] Pass OptLevel to LoongArchDAGToDAGISel correctly
Like many other targets did. And see RISCV for similar fix.
Fix https://github.com/llvm/llvm-project/issues/143239
Added:
Modified:
llvm/lib/Target/LoongArch/LoongArch.h
llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
llvm/test/CodeGen/LoongArch/O0-pipeline.ll
llvm/test/CodeGen/LoongArch/isel-optnone.ll
llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/LoongArch/LoongArch.h b/llvm/lib/Target/LoongArch/LoongArch.h
index b9dc7822893ee..e5b3083348792 100644
--- a/llvm/lib/Target/LoongArch/LoongArch.h
+++ b/llvm/lib/Target/LoongArch/LoongArch.h
@@ -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();
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
index 7c1f55a26c919..71d0263fe3760 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
@@ -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)
@@ -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);
}
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
index e94f249c14be2..1eed877dcef16 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
+++ b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
@@ -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>();
@@ -93,7 +94,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
diff --git a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
index 0c8cb14f1ad30..d63e5a2b50e84 100644
--- a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
@@ -189,7 +189,7 @@ void LoongArchPassConfig::addCodeGenPrepare() {
}
bool LoongArchPassConfig::addInstSelector() {
- addPass(createLoongArchISelDag(getLoongArchTargetMachine()));
+ addPass(createLoongArchISelDag(getLoongArchTargetMachine(), getOptLevel()));
return false;
}
diff --git a/llvm/test/CodeGen/LoongArch/O0-pipeline.ll b/llvm/test/CodeGen/LoongArch/O0-pipeline.ll
index d16cb1c15870b..9006b5c8d6fe1 100644
--- a/llvm/test/CodeGen/LoongArch/O0-pipeline.ll
+++ b/llvm/test/CodeGen/LoongArch/O0-pipeline.ll
@@ -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
diff --git a/llvm/test/CodeGen/LoongArch/isel-optnone.ll b/llvm/test/CodeGen/LoongArch/isel-optnone.ll
index d44f1405d0c18..4d2528a3148ac 100644
--- a/llvm/test/CodeGen/LoongArch/isel-optnone.ll
+++ b/llvm/test/CodeGen/LoongArch/isel-optnone.ll
@@ -2,11 +2,8 @@
; RUN: llc %s -O0 -mtriple=loongarch64 -o /dev/null -debug-only=isel 2>&1 | FileCheck %s
define void @fooOptnone() #0 {
-; CHECK: Changing optimization level for Function fooOptnone
-; CHECK: Before: -O2 ; After: -O0
-
-; CHECK: Restoring optimization level for Function fooOptnone
-; CHECK: Before: -O0 ; After: -O2
+; CHECK-NOT: Changing optimization level for Function fooOptnone
+; CHECK-NOT: Restoring optimization level for Function fooOptnone
ret void
}
diff --git a/llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll b/llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll
index 08534e307e4e0..c1b1c1f7568bb 100644
--- a/llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll
+++ b/llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll
@@ -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
More information about the llvm-commits
mailing list