diff --git a/0082-LoongArch-Precommit-test-case-to-show-bug-in-LoongAr.patch b/0082-LoongArch-Precommit-test-case-to-show-bug-in-LoongAr.patch new file mode 100644 index 0000000000000000000000000000000000000000..dcc3b2df1c67f129f195d40bf9729ade352c3a5c --- /dev/null +++ b/0082-LoongArch-Precommit-test-case-to-show-bug-in-LoongAr.patch @@ -0,0 +1,36 @@ +From c9c67d85e77d22d07e68c19eea4a2ef3b1ea364c Mon Sep 17 00:00:00 2001 +From: Weining Lu +Date: Sat, 7 Jun 2025 15:10:24 +0800 +Subject: [PATCH 1/3] [LoongArch] Precommit test case to show bug in + LoongArchISelDagToDag + +The optimization level should not be restored into O2. + +(cherry picked from commit fcc82cfa9394b2bd4380acdcf0e2854caee5a47a) +--- + llvm/test/CodeGen/LoongArch/isel-optnone.ll | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + create mode 100644 llvm/test/CodeGen/LoongArch/isel-optnone.ll + +diff --git a/llvm/test/CodeGen/LoongArch/isel-optnone.ll b/llvm/test/CodeGen/LoongArch/isel-optnone.ll +new file mode 100644 +index 000000000000..d44f1405d0c1 +--- /dev/null ++++ b/llvm/test/CodeGen/LoongArch/isel-optnone.ll +@@ -0,0 +1,13 @@ ++; REQUIRES: asserts ++; 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 ++ ret void ++} ++ ++attributes #0 = { nounwind optnone noinline } +-- +2.20.1 + diff --git a/0083-LoongArch-Pass-OptLevel-to-LoongArchDAGToDAGISel-cor.patch b/0083-LoongArch-Pass-OptLevel-to-LoongArchDAGToDAGISel-cor.patch new file mode 100644 index 0000000000000000000000000000000000000000..62ee23144657f88880c7b603b6453c0898b2d1eb --- /dev/null +++ b/0083-LoongArch-Pass-OptLevel-to-LoongArchDAGToDAGISel-cor.patch @@ -0,0 +1,131 @@ +From 2dd8460d8a363039e21c48ff65031c3fa1a92c0e Mon Sep 17 00:00:00 2001 +From: Weining Lu +Date: Sat, 7 Jun 2025 11:45:39 +0800 +Subject: [PATCH 2/3] [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 + +(cherry picked from commit 90a52f4942961a5c32afc69d69470c6b7e5bcb8a) +--- + llvm/lib/Target/LoongArch/LoongArch.h | 3 ++- + llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp | 5 +++-- + llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h | 5 +++-- + llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp | 2 +- + llvm/test/CodeGen/LoongArch/O0-pipeline.ll | 8 -------- + llvm/test/CodeGen/LoongArch/isel-optnone.ll | 7 ++----- + llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll | 1 + + 7 files changed, 12 insertions(+), 19 deletions(-) + +diff --git a/llvm/lib/Target/LoongArch/LoongArch.h b/llvm/lib/Target/LoongArch/LoongArch.h +index 09ca089c9115..a2267024a976 100644 +--- a/llvm/lib/Target/LoongArch/LoongArch.h ++++ b/llvm/lib/Target/LoongArch/LoongArch.h +@@ -34,7 +34,8 @@ bool lowerLoongArchMachineOperandToMCOperand(const MachineOperand &MO, + const AsmPrinter &AP); + + FunctionPass *createLoongArchExpandAtomicPseudoPass(); +-FunctionPass *createLoongArchISelDag(LoongArchTargetMachine &TM); ++FunctionPass *createLoongArchISelDag(LoongArchTargetMachine &TM, ++ CodeGenOpt::Level OptLevel); + FunctionPass *createLoongArchPreRAExpandPseudoPass(); + FunctionPass *createLoongArchExpandPseudoPass(); + void initializeLoongArchDAGToDAGISelPass(PassRegistry &); +diff --git a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp +index 01b2f720f902..535405022eda 100644 +--- a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp ++++ b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp +@@ -412,6 +412,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 LoongArchDAGToDAGISel(TM); ++FunctionPass *llvm::createLoongArchISelDag(LoongArchTargetMachine &TM, ++ CodeGenOpt::Level OptLevel) { ++ return new LoongArchDAGToDAGISel(TM, OptLevel); + } +diff --git a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h +index 5e3d6ccc3755..8149e0432126 100644 +--- a/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h ++++ b/llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h +@@ -28,8 +28,9 @@ public: + + LoongArchDAGToDAGISel() = delete; + +- explicit LoongArchDAGToDAGISel(LoongArchTargetMachine &TM) +- : SelectionDAGISel(ID, TM) {} ++ explicit LoongArchDAGToDAGISel(LoongArchTargetMachine &TM, ++ CodeGenOpt::Level OptLevel) ++ : SelectionDAGISel(ID, TM, OptLevel) {} + + bool runOnMachineFunction(MachineFunction &MF) override { + Subtarget = &MF.getSubtarget(); +diff --git a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp +index 0efc5e6ebb99..c683902331d9 100644 +--- a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp ++++ b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp +@@ -167,7 +167,7 @@ void LoongArchPassConfig::addIRPasses() { + } + + 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 84d235d78eb9..9786390687d6 100644 +--- a/llvm/test/CodeGen/LoongArch/O0-pipeline.ll ++++ b/llvm/test/CodeGen/LoongArch/O0-pipeline.ll +@@ -35,15 +35,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 d44f1405d0c1..4d2528a3148a 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 092da5aba2d9..ff242c2a0f98 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 +-- +2.20.1 + diff --git a/0084-LoongArch-Fix-test-cases-after-2dd8460d8a36.patch b/0084-LoongArch-Fix-test-cases-after-2dd8460d8a36.patch new file mode 100644 index 0000000000000000000000000000000000000000..ba66cf14dfdf4a0832e604ab6e1463d885bcab61 --- /dev/null +++ b/0084-LoongArch-Fix-test-cases-after-2dd8460d8a36.patch @@ -0,0 +1,60 @@ +From aeaf23493c46e94773dcc47c8df52ceaea5bfa36 Mon Sep 17 00:00:00 2001 +From: chenli +Date: Tue, 10 Jun 2025 09:44:02 +0800 +Subject: [PATCH 3/3] [LoongArch] Fix test cases after 2dd8460d8a36 + +--- + llvm/test/CodeGen/LoongArch/shrinkwrap.ll | 4 +--- + llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll | 12 ++++++------ + 2 files changed, 7 insertions(+), 9 deletions(-) + +diff --git a/llvm/test/CodeGen/LoongArch/shrinkwrap.ll b/llvm/test/CodeGen/LoongArch/shrinkwrap.ll +index 5f15dd2e7eaf..0323b56080f8 100644 +--- a/llvm/test/CodeGen/LoongArch/shrinkwrap.ll ++++ b/llvm/test/CodeGen/LoongArch/shrinkwrap.ll +@@ -9,7 +9,6 @@ define void @eliminate_restore(i32 %n) nounwind { + ; NOSHRINKW: # %bb.0: + ; NOSHRINKW-NEXT: addi.d $sp, $sp, -16 + ; NOSHRINKW-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill +-; NOSHRINKW-NEXT: # kill: def $r5 killed $r4 + ; NOSHRINKW-NEXT: addi.w $a1, $a0, 0 + ; NOSHRINKW-NEXT: ori $a0, $zero, 32 + ; NOSHRINKW-NEXT: bltu $a0, $a1, .LBB0_2 +@@ -52,9 +51,8 @@ define void @conditional_alloca(i32 %n) nounwind { + ; NOSHRINKW-NEXT: st.d $ra, $sp, 24 # 8-byte Folded Spill + ; NOSHRINKW-NEXT: st.d $fp, $sp, 16 # 8-byte Folded Spill + ; NOSHRINKW-NEXT: addi.d $fp, $sp, 32 +-; NOSHRINKW-NEXT: move $a1, $a0 +-; NOSHRINKW-NEXT: st.d $a1, $fp, -24 # 8-byte Folded Spill + ; NOSHRINKW-NEXT: addi.w $a1, $a0, 0 ++; NOSHRINKW-NEXT: st.d $a0, $fp, -24 # 8-byte Folded Spill + ; NOSHRINKW-NEXT: ori $a0, $zero, 32 + ; NOSHRINKW-NEXT: bltu $a0, $a1, .LBB1_2 + ; NOSHRINKW-NEXT: b .LBB1_1 +diff --git a/llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll b/llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll +index ff242c2a0f98..6fba703018f0 100644 +--- a/llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll ++++ b/llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll +@@ -19,13 +19,13 @@ define dso_local ptr @f(i32 noundef signext %i) "frame-pointer"="all" { + ; CHECK-NEXT: addi.d $fp, $sp, 48 + ; CHECK-NEXT: .cfi_def_cfa 22, 0 + ; CHECK-NEXT: st.d $ra, $fp, -40 # 8-byte Folded Spill +-; CHECK-NEXT: move $a1, $a0 ++; CHECK-NEXT: # kill: def $r5 killed $r4 ++; CHECK-NEXT: st.w $a0, $fp, -28 + ; CHECK-NEXT: pcalau12i $a0, %pc_hi20(calls) +-; CHECK-NEXT: addi.d $a3, $a0, %pc_lo12(calls) +-; CHECK-NEXT: ld.w $a0, $a3, 0 +-; CHECK-NEXT: addi.d $a2, $a0, 1 +-; CHECK-NEXT: st.w $a2, $a3, 0 +-; CHECK-NEXT: st.w $a1, $fp, -28 ++; CHECK-NEXT: addi.d $a2, $a0, %pc_lo12(calls) ++; CHECK-NEXT: ld.w $a0, $a2, 0 ++; CHECK-NEXT: addi.d $a1, $a0, 1 ++; CHECK-NEXT: st.w $a1, $a2, 0 + ; CHECK-NEXT: bnez $a0, .LBB0_2 + ; CHECK-NEXT: b .LBB0_1 + ; CHECK-NEXT: .LBB0_1: # %if.then +-- +2.20.1 + diff --git a/llvm.spec b/llvm.spec index 98f46f77b4c2746ec8e318575b445321e5696c2b..098e8d8cae072a972643c82fda64c1650d42e65c 100644 --- a/llvm.spec +++ b/llvm.spec @@ -1,4 +1,4 @@ -%define anolis_release 6 +%define anolis_release 7 %global toolchain clang @@ -149,6 +149,9 @@ Patch78: 0078-LoongArch-Support-march-la64v1.0-and-march-la64v1.1-.patch Patch79: 0079-LoongArch-Support-la664-100068.patch Patch80: 0080-LoongArch-Remove-experimental-auto-vec-feature.-1000.patch Patch81: 0081-LoongArch-Delete-R_LARCH_DELETE-and-R_LARCH_CFA-relo.patch +Patch82: 0082-LoongArch-Precommit-test-case-to-show-bug-in-LoongAr.patch +Patch83: 0083-LoongArch-Pass-OptLevel-to-LoongArchDAGToDAGISel-cor.patch +Patch84: 0084-LoongArch-Fix-test-cases-after-2dd8460d8a36.patch BuildRequires: gcc gcc-c++ clang cmake ninja-build zlib-devel libffi-devel BuildRequires: libxml2-devel ncurses-devel python3-psutil python3-sphinx @@ -575,6 +578,9 @@ fi %endif %changelog +* Thu Jun 12 2025 Chen Li - 17.0.6-7 +- LoongArch Backport: Pass OptLevel to LoongArchDAGToDAGISel correctly + * Fri Jun 6 2025 Anmeng Zhang - 17.0.6-6 - fix build error for riscv64