[llvm] [Mips][AsmPrinter] Fix for assembler not printing a label (PR #80666)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 04:13:18 PST 2024


https://github.com/urosbericsyrmia updated https://github.com/llvm/llvm-project/pull/80666

>From bcf5396c0684c9c573ee48ff189adfbcb7dc85aa Mon Sep 17 00:00:00 2001
From: Uros Beric <Uros.Beric at Syrmia.com>
Date: Mon, 29 Jan 2024 09:21:53 +0100
Subject: [PATCH 1/3] [Mips] Fix for assembler not printing a label

---
 llvm/lib/Target/Mips/MipsAsmPrinter.cpp     | 17 +++++++++++++++++
 llvm/test/CodeGen/Mips/Fast-ISel/pr40325.ll |  2 +-
 llvm/test/CodeGen/Mips/br_equal_labels.ll   | 14 ++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/Mips/br_equal_labels.ll

diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index 718844bc36ff9..1fd3ae9cd36ca 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -502,6 +502,23 @@ bool MipsAsmPrinter::isBlockOnlyReachableByFallthrough(const MachineBasicBlock*
   if (Pred->empty())
     return true;
 
+  // Check the terminators in the previous block
+  for (const auto &MI : Pred->terminators()) {
+    // If it is not a simple branch, we are in a table somewhere.
+    if (!MI.isBranch() || MI.isIndirectBranch())
+      return false;
+
+    // If we are the operands of one of the branches, this is not a fall
+    // through. Note that targets with delay slots will usually bundle
+    // terminators with the delay slot instruction.
+    for (ConstMIBundleOperands OP(MI); OP.isValid(); ++OP) {
+      if (OP->isJTI())
+        return false;
+      if (OP->isMBB() && OP->getMBB() == MBB)
+        return false;
+    }
+  }
+
   // Otherwise, check the last instruction.
   // Check if the last terminator is an unconditional branch.
   MachineBasicBlock::const_iterator I = Pred->end();
diff --git a/llvm/test/CodeGen/Mips/Fast-ISel/pr40325.ll b/llvm/test/CodeGen/Mips/Fast-ISel/pr40325.ll
index 9e64d7b2fa039..c276515920d52 100644
--- a/llvm/test/CodeGen/Mips/Fast-ISel/pr40325.ll
+++ b/llvm/test/CodeGen/Mips/Fast-ISel/pr40325.ll
@@ -11,7 +11,7 @@ define void @test(i32 %x, ptr %p) nounwind {
 ; CHECK-NEXT:    andi $1, $4, 1
 ; CHECK-NEXT:    bgtz $1, $BB0_1
 ; CHECK-NEXT:    nop
-; CHECK-NEXT:  # %bb.1: # %foo
+; CHECK-NEXT:  $BB0_1: # %foo
 ; CHECK-NEXT:    jr $ra
 ; CHECK-NEXT:    nop
   %y = and i32 %x, 1
diff --git a/llvm/test/CodeGen/Mips/br_equal_labels.ll b/llvm/test/CodeGen/Mips/br_equal_labels.ll
new file mode 100644
index 0000000000000..6ba2a713e5e2a
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/br_equal_labels.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --filetype=asm -march=mips --relocation-model=pic -O0  < %s | FileCheck %s
+
+define void @test(i32 %x) nounwind {
+  %y = icmp eq i32 %x, 1
+  br i1 %y, label %bb1, label %bb1
+
+bb1:
+  ret void
+}
+
+; CHECK:      bgtz	${{[0-9]+}}, $[[BB1:BB[0-9]+_[0-9]+]]
+; CHECK-NEXT: nop
+; CHECK-NEXT: $[[BB1]]:
\ No newline at end of file

>From c1b4fdf31be26f55e9e07cd66efa21357fece985 Mon Sep 17 00:00:00 2001
From: urosbericsyrmia <145460455+urosbericsyrmia at users.noreply.github.com>
Date: Mon, 5 Feb 2024 13:12:35 +0100
Subject: [PATCH 2/3] Update MipsAsmPrinter.cpp

---
 llvm/lib/Target/Mips/MipsAsmPrinter.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index 1fd3ae9cd36ca..74e1cc6ca9ce1 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -502,7 +502,7 @@ bool MipsAsmPrinter::isBlockOnlyReachableByFallthrough(const MachineBasicBlock*
   if (Pred->empty())
     return true;
 
-  // Check the terminators in the previous block
+  // Check the terminators in the previous block.
   for (const auto &MI : Pred->terminators()) {
     // If it is not a simple branch, we are in a table somewhere.
     if (!MI.isBranch() || MI.isIndirectBranch())

>From c3be89b729009ef58dcca27f403a0289d18e87b5 Mon Sep 17 00:00:00 2001
From: urosbericsyrmia <145460455+urosbericsyrmia at users.noreply.github.com>
Date: Mon, 5 Feb 2024 13:13:10 +0100
Subject: [PATCH 3/3] Update br_equal_labels.ll

---
 llvm/test/CodeGen/Mips/br_equal_labels.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/CodeGen/Mips/br_equal_labels.ll b/llvm/test/CodeGen/Mips/br_equal_labels.ll
index 6ba2a713e5e2a..3044ecafe5c34 100644
--- a/llvm/test/CodeGen/Mips/br_equal_labels.ll
+++ b/llvm/test/CodeGen/Mips/br_equal_labels.ll
@@ -11,4 +11,4 @@ bb1:
 
 ; CHECK:      bgtz	${{[0-9]+}}, $[[BB1:BB[0-9]+_[0-9]+]]
 ; CHECK-NEXT: nop
-; CHECK-NEXT: $[[BB1]]:
\ No newline at end of file
+; CHECK-NEXT: $[[BB1]]:



More information about the llvm-commits mailing list