]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
MIPS: Add support for Allegrex min/max instructions
authorDavid Guillen Fandos <david@davidgf.net>
Fri, 19 Sep 2025 16:48:09 +0000 (18:48 +0200)
committerYunQiang Su <yunqiang@isrc.iscas.ac.cn>
Tue, 2 Dec 2025 01:25:50 +0000 (09:25 +0800)
gcc/ChangeLog:

* config/mips/mips.h (ISA_HAS_MIN_MAX): Defined a new macro.
* config/mips/mips.md (sminsi3): Defined a new instruction.
(smaxsi3): Defined a new instruction.

gcc/testsuite/ChangeLog:

* gcc.target/mips/max-1.c: New test.
* gcc.target/mips/min-1.c: New test.

Signed-off-by: David Guillen Fandos <david@davidgf.net>
gcc/config/mips/mips.h
gcc/config/mips/mips.md
gcc/testsuite/gcc.target/mips/max-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/mips/min-1.c [new file with mode: 0644]

index c320ce2fc110b8c00bbf1d21c267907ef3302296..a78f421484899d1c427fdccb9bcc9c5913048f7c 100644 (file)
@@ -1255,6 +1255,9 @@ struct mips_cpu_info {
                                  || TARGET_SMARTMIPS)                  \
                                 && !TARGET_MIPS16)
 
+/* ISA has the "min" and "max" instructions (signed min/max). */
+#define ISA_HAS_MIN_MAX                (TARGET_ALLEGREX)
+
 /* ISA has the WSBH (word swap bytes within halfwords) instruction.
    64-bit targets also provide DSBH and DSHD.  */
 #define ISA_HAS_WSBH           ((mips_isa_rev >= 2 && !TARGET_MIPS16)  \
index 60448361598956a984d9bfabf3fc6c5cafbcd267..d9aee81895966409410f969a2a34860ffdf773c4 100644 (file)
   DONE;
 })
 
+;; Min and max.
+
+(define_insn "sminsi3"
+  [(set (match_operand:SI 0 "register_operand" "=d")
+        (smin:SI (match_operand:SI 1 "register_operand" "d")
+                 (match_operand:SI 2 "register_operand" "d")))]
+  "ISA_HAS_MIN_MAX"
+  "min\t%0,%1,%2"
+  [(set_attr "type"    "arith")
+   (set_attr "mode"    "SI")])
+
+(define_insn "smaxsi3"
+  [(set (match_operand:SI 0 "register_operand" "=d")
+        (smax:SI (match_operand:SI 1 "register_operand" "d")
+                 (match_operand:SI 2 "register_operand" "d")))]
+  "ISA_HAS_MIN_MAX"
+  "max\t%0,%1,%2"
+  [(set_attr "type"    "arith")
+   (set_attr "mode"    "SI")])
+
+
 (define_expand "speculation_barrier"
   [(unspec_volatile [(const_int 0)] VUNSPEC_SPECULATION_BARRIER)]
   ""
diff --git a/gcc/testsuite/gcc.target/mips/max-1.c b/gcc/testsuite/gcc.target/mips/max-1.c
new file mode 100644 (file)
index 0000000..f3589fc
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-options "-march=allegrex" } */
+
+NOMIPS16 int
+foo_max (int a, int b)
+{
+  return (a > b) ?  a : b;
+}
+
+/* { dg-final { scan-assembler "\tmax\t" } } */
diff --git a/gcc/testsuite/gcc.target/mips/min-1.c b/gcc/testsuite/gcc.target/mips/min-1.c
new file mode 100644 (file)
index 0000000..06b5e91
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-options "-march=allegrex" } */
+
+NOMIPS16 int
+foo_min (int a, int b)
+{
+  return (a < b) ?  a : b;
+}
+
+/* { dg-final { scan-assembler "\tmin\t" } } */