[llvm] [LoongArch] Implement getJumpTableIndex to allow splitting jump table edges (PR #228550)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 09:04:12 PDT 2026


================
@@ -374,6 +374,98 @@ bool LoongArchInstrInfo::isAsCheapAsAMove(const MachineInstr &MI) const {
   return MI.isAsCheapAsAMove();
 }
 
+// Return the index of the jump table whose address
+// (or an entry loaded from it) is held in Reg, or -1.
+static int getJumpTableIndexFromReg(const MachineRegisterInfo &MRI,
+                                    Register Reg) {
+  if (!Reg.isVirtual())
+    return -1;
+  const MachineInstr *MI = MRI.getUniqueVRegDef(Reg);
+  if (!MI)
+    return -1;
+
+  switch (MI->getOpcode()) {
+  case LoongArch::ADDI_D:
+  case LoongArch::ADDI_W:
+  case LoongArch::PseudoLA_PCREL:
+    for (const MachineOperand &MO : MI->operands())
+      if (MO.isJTI())
+        return MO.getIndex();
+    return -1;
+  case LoongArch::LDX_D:
+  case LoongArch::LDX_W:
+    return getJumpTableIndexFromReg(MRI, MI->getOperand(1).getReg());
----------------
lrzlin wrote:

Done.

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


More information about the llvm-commits mailing list