[llvm] [Mips] Did not put fake_use into delay slot (PR #201537)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 02:13:11 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-mips

Author: yingopq

<details>
<summary>Changes</summary>

Fix #<!-- -->198835.

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


2 Files Affected:

- (modified) llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp (+9-8) 
- (added) llvm/test/CodeGen/Mips/fake-use.ll (+15) 


``````````diff
diff --git a/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp b/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp
index bcfaa7cd2ed2d..7d7dac22520ea 100644
--- a/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp
+++ b/llvm/lib/Target/Mips/MipsDelaySlotFiller.cpp
@@ -854,10 +854,17 @@ bool MipsDelaySlotFiller::searchRange(MachineBasicBlock &MBB, IterTy Begin,
     IterTy CurrI = I;
     ++I;
     LLVM_DEBUG(dbgs() << DEBUG_TYPE ": checking instruction: "; CurrI->dump());
-    // Skip debug value.
+
+    if (terminateSearch(*CurrI)) {
+      LLVM_DEBUG(dbgs() << DEBUG_TYPE ": should terminate search: ";
+                 CurrI->dump());
+      break;
+    }
+    // Skip debug and pseudo instructions.
     // Instruction TargetOpcode::JUMP_TABLE_DEBUG_INFO is only used to note
     // jump table debug info.
-    if (CurrI->isDebugInstr() || CurrI->isJumpTableDebugInfo()) {
+    if (CurrI->isDebugInstr() || CurrI->isJumpTableDebugInfo() ||
+        CurrI->isMetaInstruction()) {
       LLVM_DEBUG(dbgs() << DEBUG_TYPE ": ignoring debug instruction: ";
                  CurrI->dump());
       continue;
@@ -871,12 +878,6 @@ bool MipsDelaySlotFiller::searchRange(MachineBasicBlock &MBB, IterTy Begin,
       continue;
     }
 
-    if (terminateSearch(*CurrI)) {
-      LLVM_DEBUG(dbgs() << DEBUG_TYPE ": should terminate search: ";
-                 CurrI->dump());
-      break;
-    }
-
     assert((!CurrI->isCall() && !CurrI->isReturn() && !CurrI->isBranch()) &&
            "Cannot put calls, returns or branches in delay slot.");
 
diff --git a/llvm/test/CodeGen/Mips/fake-use.ll b/llvm/test/CodeGen/Mips/fake-use.ll
new file mode 100644
index 0000000000000..c8c7f83624314
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/fake-use.ll
@@ -0,0 +1,15 @@
+; RUN: llc -verify-machineinstrs -mtriple=mipsel-linux-gnu -mcpu=mips32r2 %s -o - | FileCheck %s
+
+define void @fake_use(ptr %aaaa) {
+; CHECK-LABEL: fake_use:
+; CHECK:       # %bb.0:    # %entry
+; CHECK-NEXT:              # fake_use: $a0 
+; CHECK-NEXT:    jr $ra 
+; CHECK-NEXT:    nop
+entry:
+  notail call void (...) @llvm.fake.use(ptr %aaaa)
+  ret void
+}
+
+declare void @llvm.fake.use(...)
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/201537


More information about the llvm-commits mailing list