[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Pass OptLevel to LoongArchDAGToDAGISel correctly (PR #144459)

2025-07-07 Thread via llvm-branch-commits

leecheechen wrote:

Fixed a crash caused by incorrectly passing OptLevel to LoongArchDAGToDAGISel.

https://github.com/llvm/llvm-project/pull/144459
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Pass OptLevel to LoongArchDAGToDAGISel correctly (PR #144459)

2025-06-16 Thread Lu Weining via llvm-branch-commits

https://github.com/SixWeining approved this pull request.


https://github.com/llvm/llvm-project/pull/144459
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Pass OptLevel to LoongArchDAGToDAGISel correctly (PR #144459)

2025-06-16 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-loongarch

Author: None (llvmbot)


Changes

Backport fcc82cf 90a52f4

Requested by: @leecheechen

---
Full diff: https://github.com/llvm/llvm-project/pull/144459.diff


7 Files Affected:

- (modified) llvm/lib/Target/LoongArch/LoongArch.h (+2-1) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp (+6-4) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h (+5-3) 
- (modified) llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp (+1-1) 
- (modified) llvm/test/CodeGen/LoongArch/O0-pipeline.ll (-8) 
- (added) llvm/test/CodeGen/LoongArch/isel-optnone.ll (+10) 
- (modified) llvm/test/CodeGen/LoongArch/spill-ra-without-kill.ll (+1) 


``diff
diff --git a/llvm/lib/Target/LoongArch/LoongArch.h 
b/llvm/lib/Target/LoongArch/LoongArch.h
index db60523738880..6635c57ff0476 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 cb0fb9bc9c7f9..7169cdc9a2bf9 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(TM)) 
{}
+LoongArchTargetMachine &TM, CodeGenOptLevel OptLevel)
+: SelectionDAGISelLegacy(
+  ID, std::make_unique(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 8a7eba418d804..2e6bc9951e9e7 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();
@@ -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
diff --git a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp 
b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
index 62b08be5435cd..27f97b2cebb0c 100644
--- a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
@@ -188,7 +188,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 24bd4c75a9821..73d0bda895de0 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 (s

[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Pass OptLevel to LoongArchDAGToDAGISel correctly (PR #144459)

2025-06-16 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/144459

Backport fcc82cf 90a52f4

Requested by: @leecheechen

>From 1443f5093fda88e3fe91159e3029fd3c9f15f178 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Sat, 7 Jun 2025 15:10:24 +0800
Subject: [PATCH 1/2] [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 0..d44f1405d0c18
--- /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 }

>From 75b652d4766c5444b8bdb35f63f61d0a38543fd3 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Sat, 7 Jun 2025 11:45:39 +0800
Subject: [PATCH 2/2] [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  | 10 ++
 llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h|  8 +---
 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, 17 insertions(+), 22 deletions(-)

diff --git a/llvm/lib/Target/LoongArch/LoongArch.h 
b/llvm/lib/Target/LoongArch/LoongArch.h
index db60523738880..6635c57ff0476 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 cb0fb9bc9c7f9..7169cdc9a2bf9 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(TM)) 
{}
+LoongArchTargetMachine &TM, CodeGenOptLevel OptLevel)
+: SelectionDAGISelLegacy(
+  ID, std::make_unique(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 8a7eba418d804..2e6bc9951e9e7 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

[llvm-branch-commits] [llvm] release/20.x: [LoongArch] Pass OptLevel to LoongArchDAGToDAGISel correctly (PR #144459)

2025-06-16 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/144459
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits