[llvm] MIPS: Support isLegalICmpImmediate and isLegalAddImmediate (PR #133400)

YunQiang Su via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 28 02:32:40 PDT 2025


https://github.com/wzssyqa created https://github.com/llvm/llvm-project/pull/133400

Set it to true only if isInt<16>.
By default implemention defines them to true always. For most cases, MIPS uses 16bit IMM, and for microMIPS, ICMP and ADDiu have 16bit IMM flavor.

>From 7da0eb79ae10fb05cd5189fe929e4ded46b775b6 Mon Sep 17 00:00:00 2001
From: YunQiang Su <yunqiang at isrc.iscas.ac.cn>
Date: Fri, 28 Mar 2025 17:28:54 +0800
Subject: [PATCH] MIPS: Support isLegalICmpImmediate and isLegalAddImmediate

Set it to true only if isInt<16>.
By default implemention defines them to true always.
For most cases, MIPS uses 16bit IMM, and for microMIPS,
ICMP and ADDiu have 16bit IMM flavor.
---
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 8 ++++++++
 llvm/lib/Target/Mips/MipsISelLowering.h   | 3 +++
 2 files changed, 11 insertions(+)

diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index bd65431b475d0..fa8a4704730cf 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4474,6 +4474,14 @@ bool MipsTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT,
   return Imm.isZero();
 }
 
+bool MipsTargetLowering::isLegalICmpImmediate(int64_t Imm) const {
+  return isInt<16>(Imm);
+}
+
+bool MipsTargetLowering::isLegalAddImmediate(int64_t Imm) const {
+  return isInt<16>(Imm);
+}
+
 unsigned MipsTargetLowering::getJumpTableEncoding() const {
   if (!isPositionIndependent())
     return MachineJumpTableInfo::EK_BlockAddress;
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.h b/llvm/lib/Target/Mips/MipsISelLowering.h
index 5bd7b09ded45b..9885ab894d6f2 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.h
+++ b/llvm/lib/Target/Mips/MipsISelLowering.h
@@ -706,6 +706,9 @@ class TargetRegisterClass;
     bool isFPImmLegal(const APFloat &Imm, EVT VT,
                       bool ForCodeSize) const override;
 
+    bool isLegalICmpImmediate(int64_t Imm) const override;
+    bool isLegalAddImmediate(int64_t Imm) const override;
+
     unsigned getJumpTableEncoding() const override;
     SDValue getPICJumpTableRelocBase(SDValue Table,
                                      SelectionDAG &DAG) const override;



More information about the llvm-commits mailing list