[llvm] [Mips] Restrict microMIPS GP load folding to word loads (PR #228881)

Jiaxun Yang via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 05:41:32 PDT 2026


https://github.com/FlyGoat created https://github.com/llvm/llvm-project/pull/228881

Only LW has a GP-relative variant, so restrict the folding to LW_MM and
LW_MMR6.

Assisted-by: OpenAI Codex # Testcases


Validation: `git diff --check` passes. Tests were not rerun for this cherry-pick.


>From 6467c10e9cdb41e26cfe3d1374436c5254459a4f Mon Sep 17 00:00:00 2001
From: Jiaxun Yang <jiaxun.yang at flygoat.com>
Date: Sun, 4 Oct 2026 12:23:42 +0100
Subject: [PATCH] [Mips] Restrict microMIPS GP load folding to word loads

Only LW has a GP-relative variant, so restrict the folding to LW_MM and
LW_MMR6.

Assisted-by: OpenAI Codex # Testcases
---
 llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index 48163a54f4837..18cb00b9fd28b 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -2135,7 +2135,7 @@ bool MipsAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
   }
 
   if (inMicroMipsMode()) {
-    if (MCID.mayLoad() && Opcode != Mips::LWP_MM) {
+    if (Opcode == Mips::LW_MM || Opcode == Mips::LW_MMR6) {
       // Try to create 16-bit GP relative load instruction.
       for (unsigned i = 0; i < MCID.getNumOperands(); i++) {
         const MCOperandInfo &OpInfo = MCID.operands()[i];



More information about the llvm-commits mailing list