[llvm] [Mips] Add the missing judgment when processing function handleMFLOSlot (PR #121463)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 23:34:09 PST 2025


https://github.com/yingopq updated https://github.com/llvm/llvm-project/pull/121463

>From c3b71ce25a6dab59abd7e1096382f3001dc2d22e Mon Sep 17 00:00:00 2001
From: Ying Huang <ying.huang at oss.cipunited.com>
Date: Thu, 2 Jan 2025 04:50:05 -0500
Subject: [PATCH] [Mips] Add the missing judgment when processing function
 handleMFLOSlot

In function handleMFLOSlot, we may get a variable LastInstInFunction
with a value of true from function getNextMachineInstr and IInSlot may
be null which would trigger an assert.
So we need to skip this case.

Fix #118223.
---
 llvm/lib/Target/Mips/MipsBranchExpansion.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/lib/Target/Mips/MipsBranchExpansion.cpp b/llvm/lib/Target/Mips/MipsBranchExpansion.cpp
index 80f3f1ec8090e0..eb7f3f8792bfbb 100644
--- a/llvm/lib/Target/Mips/MipsBranchExpansion.cpp
+++ b/llvm/lib/Target/Mips/MipsBranchExpansion.cpp
@@ -767,6 +767,8 @@ bool MipsBranchExpansion::handleMFLOSlot(Pred Predicate, Safe SafeInSlot) {
         std::pair<Iter, bool> Res = getNextMachineInstr(std::next(I), &*FI);
         LastInstInFunction |= Res.second;
         IInSlot = Res.first;
+        if (LastInstInFunction)
+          continue;
         if (!SafeInSlot(*IInSlot, *I)) {
           Changed = true;
           TII->insertNop(*(I->getParent()), std::next(I), I->getDebugLoc())



More information about the llvm-commits mailing list