[llvm] [LangRef][IR] Add 3-way compare intrinsics llvm.scmp/llvm.ucmp (PR #83227)

Miguel Raz Guzmán Macedo via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 14 09:46:18 PDT 2024


https://github.com/miguelraz updated https://github.com/llvm/llvm-project/pull/83227

>From 9d7134fbc570d8ce3218a69c56562aabda7a6be1 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Thu, 29 Feb 2024 20:01:20 -0600
Subject: [PATCH 01/37] add sthreecmp and uthreecmp intrinsics to LangRef

---
 llvm/docs/LangRef.rst | 92 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index f56d4ed28f2855..ceffd33cdc54f5 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -11976,6 +11976,98 @@ Example:
       <result> = icmp ule i16 -4, 5        ; yields: result=false
       <result> = icmp sge i16  4, 5        ; yields: result=false
 
+.. _i_sthreecmp:
+
+'``sthreecmp``' Instruction
+^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+
+::
+
+      <result> = sthreecmp <op1>, <op2>  ; yields i2 or <N x i2>:result
+
+Overview:
+"""""""""
+
+The '``sthreecmp``' instruction returns an integer value or a vector of
+integer values based on comparison of its two integer, integer vector,
+pointer, or pointer vector operands.
+
+Arguments:
+""""""""""
+
+The '``sthreecmp``' instruction takes two signed integer operands.
+
+Semantics:
+""""""""""
+If the operands are equal, it returns 0. If ``op1`` is less than ``op2``,
+it returns -1, and if ``op1`` is greater than ``op2``, it returns 1.
+It is also known as the '``<=>``' spaceship operator.
+
+If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
+are compared as if they were integers.
+
+If the operands are integer vectors, then they are compared element by
+element. The result is an ``i2`` vector with the same number of elements
+as the values being compared. Otherwise, the result is an ``i2``.
+
+Example:
+""""""""
+
+.. code-block:: text
+
+      <result> = sthreecmp 4, 5          ; yields: result=-1
+      <result> = sthreecmp 2, 2          ; yields: result=0
+      <result> = sthreecmp -2, -1        ; yields: result=1
+
+.. _i_uthreecmp:
+
+'``uthreecmp``' Instruction
+^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+
+::
+
+      <result> = uthreecmp <op1>, <op2>  ; yields i2 or <N x i2>:result
+
+Overview:
+"""""""""
+
+The '``uthreecmp``' instruction returns an integer value or a vector of
+integer values based on comparison of its two integer, integer vector,
+pointer, or pointer vector operands.
+
+Arguments:
+""""""""""
+
+The '``uthreecmp``' instruction takes two signed integer operands.
+
+Semantics:
+""""""""""
+If the operands are equal, it returns 0. If ``op1`` is less than ``op2``,
+it returns -1, and if ``op1`` is greater than ``op2``, it returns 1.
+It is also known as the '``<=>``' spaceship operator.
+
+If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
+are compared as if they were integers.
+
+If the operands are integer vectors, then they are compared element by
+element. The result is an ``i2`` vector with the same number of elements
+as the values being compared. Otherwise, the result is an ``i2``.
+
+Example:
+""""""""
+
+.. code-block:: text
+
+      <result> = uthreecmp 4, 5          ; yields: result=-1
+      <result> = uthreecmp 2, 2          ; yields: result=0
+      <result> = uthreecmp 9, 0          ; yields: result=1
+
 .. _i_fcmp:
 
 '``fcmp``' Instruction

>From 57ec729bd308d43adaedb7e095541991f4377111 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Thu, 29 Feb 2024 20:49:59 -0600
Subject: [PATCH 02/37] add tablegen for sthreecmp and usthreecmp intrinsics

---
 llvm/include/llvm/IR/Intrinsics.td | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 0f13d25eb30ebf..15df2e7b76577e 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -2136,7 +2136,14 @@ let IntrProperties = [IntrNoMem, IntrNoSync, IntrWillReturn] in {
                                llvm_metadata_ty,
                                LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
                                llvm_i32_ty]>;
-
+  def int_vp_sthreecmp : DefaultAttrsIntrinsic<[ LLVMScalarOrSameVectorWidth<0, llvm_i8_ty> ],
+                             [LLVMMatchType<0>,
+                              LLVMMatchType<0>],
+                              [IntrSpeculatable]>;
+  def int_vp_uthreecmp : DefaultAttrsIntrinsic<[ LLVMScalarOrSameVectorWidth<0, llvm_i8_ty>],
+                             [LLVMMatchType<0>,
+                              LLVMMatchType<0>],
+                              [IntrSpeculatable]>;
   // Reductions
   def int_vp_reduce_fadd : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
                              [ LLVMVectorElementType<0>,

>From 34c0531ef62460e17c9e96e964f51d5017581680 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Thu, 29 Feb 2024 20:50:37 -0600
Subject: [PATCH 03/37] typo fix unsigned integer for uthreecmp

---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index ceffd33cdc54f5..5eae1015bffb18 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -12044,7 +12044,7 @@ pointer, or pointer vector operands.
 Arguments:
 """"""""""
 
-The '``uthreecmp``' instruction takes two signed integer operands.
+The '``uthreecmp``' instruction takes two unsigned integer operands.
 
 Semantics:
 """"""""""

>From fc62757c2e096a7daa95c49371b067af5fe70f91 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Fri, 1 Mar 2024 23:24:56 -0600
Subject: [PATCH 04/37] add sthreecmp and uthreecmp intrinsics modeled after
 llvm.smax

---
 llvm/docs/LangRef.rst | 149 ++++++++++++++++--------------------------
 1 file changed, 57 insertions(+), 92 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 5eae1015bffb18..62bcf825da5df2 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -11976,98 +11976,6 @@ Example:
       <result> = icmp ule i16 -4, 5        ; yields: result=false
       <result> = icmp sge i16  4, 5        ; yields: result=false
 
-.. _i_sthreecmp:
-
-'``sthreecmp``' Instruction
-^^^^^^^^^^^^^^^^^^^^^^
-
-Syntax:
-"""""""
-
-::
-
-      <result> = sthreecmp <op1>, <op2>  ; yields i2 or <N x i2>:result
-
-Overview:
-"""""""""
-
-The '``sthreecmp``' instruction returns an integer value or a vector of
-integer values based on comparison of its two integer, integer vector,
-pointer, or pointer vector operands.
-
-Arguments:
-""""""""""
-
-The '``sthreecmp``' instruction takes two signed integer operands.
-
-Semantics:
-""""""""""
-If the operands are equal, it returns 0. If ``op1`` is less than ``op2``,
-it returns -1, and if ``op1`` is greater than ``op2``, it returns 1.
-It is also known as the '``<=>``' spaceship operator.
-
-If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
-are compared as if they were integers.
-
-If the operands are integer vectors, then they are compared element by
-element. The result is an ``i2`` vector with the same number of elements
-as the values being compared. Otherwise, the result is an ``i2``.
-
-Example:
-""""""""
-
-.. code-block:: text
-
-      <result> = sthreecmp 4, 5          ; yields: result=-1
-      <result> = sthreecmp 2, 2          ; yields: result=0
-      <result> = sthreecmp -2, -1        ; yields: result=1
-
-.. _i_uthreecmp:
-
-'``uthreecmp``' Instruction
-^^^^^^^^^^^^^^^^^^^^^^
-
-Syntax:
-"""""""
-
-::
-
-      <result> = uthreecmp <op1>, <op2>  ; yields i2 or <N x i2>:result
-
-Overview:
-"""""""""
-
-The '``uthreecmp``' instruction returns an integer value or a vector of
-integer values based on comparison of its two integer, integer vector,
-pointer, or pointer vector operands.
-
-Arguments:
-""""""""""
-
-The '``uthreecmp``' instruction takes two unsigned integer operands.
-
-Semantics:
-""""""""""
-If the operands are equal, it returns 0. If ``op1`` is less than ``op2``,
-it returns -1, and if ``op1`` is greater than ``op2``, it returns 1.
-It is also known as the '``<=>``' spaceship operator.
-
-If the operands are :ref:`pointer <t_pointer>` typed, the pointer values
-are compared as if they were integers.
-
-If the operands are integer vectors, then they are compared element by
-element. The result is an ``i2`` vector with the same number of elements
-as the values being compared. Otherwise, the result is an ``i2``.
-
-Example:
-""""""""
-
-.. code-block:: text
-
-      <result> = uthreecmp 4, 5          ; yields: result=-1
-      <result> = uthreecmp 2, 2          ; yields: result=0
-      <result> = uthreecmp 9, 0          ; yields: result=1
-
 .. _i_fcmp:
 
 '``fcmp``' Instruction
@@ -14623,6 +14531,63 @@ The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
 integer element type. The argument types must match each other, and the return
 type must match the argument type.
 
+.. _int_sthreecmp:
+
+'``llvm.sthreecmp.*``' Intrinsic
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+
+This is an overloaded intrinsic. You can use ``@llvm.sthreecmp`` on any
+integer bit width or any vector of integer elements.
+
+::
+
+      declare i32 @llvm.sthreecmp.i32(i32 %a, i32 %b)
+      declare <4 x i32> @llvm.sthreecmp.v4i32(<4 x i32> %a, <4 x i32> %b)
+
+Overview:
+"""""""""
+
+Return ``-1`` if ``%a`` is less than ``%b``, ``0`` if they are equal, and 
+``1`` if ``%a`` is greater than ``%b``. Vector intrinsics operate on a per-element basis. 
+
+Arguments:
+""""""""""
+
+The arguments (``%a`` and ``%b``) may be of any signed integer type or a vector with
+integer element type. The argument types must match each other, and the return
+type must be at least as wide as ``i2``, to uphold the ``-1`` return value.
+
+.. _int_uthreecmp:
+
+'``llvm.uthreecmp.*``' Intrinsic
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+
+This is an overloaded intrinsic. You can use ``@llvm.sthreecmp`` on any
+integer bit width or any vector of integer elements.
+
+::
+
+      declare i2 @llvm.uthreecmp.i32(i32 %a, i32 %b)
+      declare <4 x i32> @llvm.uthreecmp.v4i32(<4 x i32> %a, <4 x i32> %b)
+
+Overview:
+"""""""""
+
+Return ``-1`` if ``%a`` is less than ``%b``, ``0`` if they are equal, and 
+``1`` if ``%a`` is greater than ``%b``. Vector intrinsics operate on a per-element basis. 
+
+Arguments:
+""""""""""
+
+The arguments (``%a`` and ``%b``) may be of any unsigned integer type or a vector with
+integer element type. The argument types must match each other, and the return
+type must be at least as wide as ``i2``, to uphold the ``-1`` return value.
 
 .. _int_memcpy:
 

>From a8ee07885770f8a23c898944dff6e26f189ea341 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Fri, 1 Mar 2024 23:26:53 -0600
Subject: [PATCH 05/37] add int_sthreecmp and int_uthreecmp based on int_smin

---
 llvm/include/llvm/IR/Intrinsics.td | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 15df2e7b76577e..856f5545be0165 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1526,6 +1526,12 @@ def int_umax : DefaultAttrsIntrinsic<
 def int_umin : DefaultAttrsIntrinsic<
     [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
     [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
+def int_sthreecmp : DefaultAttrsIntrinsic<
+    [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
+    [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
+def int_uthreecmp : DefaultAttrsIntrinsic<
+    [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
+    [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
 
 //===------------------------- Memory Use Markers -------------------------===//
 //
@@ -2136,14 +2142,7 @@ let IntrProperties = [IntrNoMem, IntrNoSync, IntrWillReturn] in {
                                llvm_metadata_ty,
                                LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
                                llvm_i32_ty]>;
-  def int_vp_sthreecmp : DefaultAttrsIntrinsic<[ LLVMScalarOrSameVectorWidth<0, llvm_i8_ty> ],
-                             [LLVMMatchType<0>,
-                              LLVMMatchType<0>],
-                              [IntrSpeculatable]>;
-  def int_vp_uthreecmp : DefaultAttrsIntrinsic<[ LLVMScalarOrSameVectorWidth<0, llvm_i8_ty>],
-                             [LLVMMatchType<0>,
-                              LLVMMatchType<0>],
-                              [IntrSpeculatable]>;
+
   // Reductions
   def int_vp_reduce_fadd : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
                              [ LLVMVectorElementType<0>,

>From ef5bd69d570699af2b376ba4c7b0b6fe171cea6a Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Sat, 2 Mar 2024 07:20:30 -0600
Subject: [PATCH 06/37] add [u]sthreecmp to ValueTrackingTest.cpp

---
 llvm/unittests/Analysis/ValueTrackingTest.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 9e0abe7a16df98..05f5e16a498e89 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -891,6 +891,8 @@ TEST(ValueTracking, propagatesPoison) {
       {true, "call i32 @llvm.smin.i32(i32 %x, i32 %y)", 0},
       {true, "call i32 @llvm.umax.i32(i32 %x, i32 %y)", 0},
       {true, "call i32 @llvm.umin.i32(i32 %x, i32 %y)", 0},
+      {true, "call i32 @llvm.sthreecmp.i32(i32 %x, i32 %y)", 0},
+      {true, "call i32 @llvm.uthreecmp.i32(i32 %x, i32 %y)", 0},
       {true, "call i32 @llvm.bitreverse.i32(i32 %x)", 0},
       {true, "call i32 @llvm.bswap.i32(i32 %x)", 0},
       {false, "call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %shamt)", 0},

>From 2ba679d624e1929ca3c0368f364816ea9275ba31 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Sat, 9 Mar 2024 20:47:07 -0600
Subject: [PATCH 07/37] call three way cmp intrinsic [u]scmp in LangRef

---
 llvm/docs/LangRef.rst | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 62bcf825da5df2..ff600c0dfe35b3 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14531,21 +14531,21 @@ The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
 integer element type. The argument types must match each other, and the return
 type must match the argument type.
 
-.. _int_sthreecmp:
+.. _int_scmp:
 
-'``llvm.sthreecmp.*``' Intrinsic
+'``llvm.scmp.*``' Intrinsic
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 Syntax:
 """""""
 
-This is an overloaded intrinsic. You can use ``@llvm.sthreecmp`` on any
+This is an overloaded intrinsic. You can use ``@llvm.scmp`` on any
 integer bit width or any vector of integer elements.
 
 ::
 
-      declare i32 @llvm.sthreecmp.i32(i32 %a, i32 %b)
-      declare <4 x i32> @llvm.sthreecmp.v4i32(<4 x i32> %a, <4 x i32> %b)
+      declare i32 @llvm.scmp.i32(i32 %a, i32 %b)
+      declare <4 x i32> @llvm.scmp.v4i32(<4 x i32> %a, <4 x i32> %b)
 
 Overview:
 """""""""
@@ -14560,21 +14560,21 @@ The arguments (``%a`` and ``%b``) may be of any signed integer type or a vector
 integer element type. The argument types must match each other, and the return
 type must be at least as wide as ``i2``, to uphold the ``-1`` return value.
 
-.. _int_uthreecmp:
+.. _int_ucmp:
 
-'``llvm.uthreecmp.*``' Intrinsic
+'``llvm.ucmp.*``' Intrinsic
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 Syntax:
 """""""
 
-This is an overloaded intrinsic. You can use ``@llvm.sthreecmp`` on any
+This is an overloaded intrinsic. You can use ``@llvm.ucmp`` on any
 integer bit width or any vector of integer elements.
 
 ::
 
-      declare i2 @llvm.uthreecmp.i32(i32 %a, i32 %b)
-      declare <4 x i32> @llvm.uthreecmp.v4i32(<4 x i32> %a, <4 x i32> %b)
+      declare i2 @llvm.ucmp.i32(i32 %a, i32 %b)
+      declare <4 x i32> @llvm.ucmp.v4i32(<4 x i32> %a, <4 x i32> %b)
 
 Overview:
 """""""""

>From c605cdf4f48921b8b8a3b3611e5cb62f3e2c3e01 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Sun, 10 Mar 2024 09:46:05 -0600
Subject: [PATCH 08/37] only add minimum stuff to LangRef and Intrinsics.td for
 s/ucmp

---
 llvm/include/llvm/IR/Intrinsics.td            | 4 ++--
 llvm/unittests/Analysis/ValueTrackingTest.cpp | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 856f5545be0165..9f437375e64bd4 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1526,10 +1526,10 @@ def int_umax : DefaultAttrsIntrinsic<
 def int_umin : DefaultAttrsIntrinsic<
     [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
     [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
-def int_sthreecmp : DefaultAttrsIntrinsic<
+def int_scmp : DefaultAttrsIntrinsic<
     [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
     [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
-def int_uthreecmp : DefaultAttrsIntrinsic<
+def int_ucmp : DefaultAttrsIntrinsic<
     [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
     [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
 
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 05f5e16a498e89..9e0abe7a16df98 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -891,8 +891,6 @@ TEST(ValueTracking, propagatesPoison) {
       {true, "call i32 @llvm.smin.i32(i32 %x, i32 %y)", 0},
       {true, "call i32 @llvm.umax.i32(i32 %x, i32 %y)", 0},
       {true, "call i32 @llvm.umin.i32(i32 %x, i32 %y)", 0},
-      {true, "call i32 @llvm.sthreecmp.i32(i32 %x, i32 %y)", 0},
-      {true, "call i32 @llvm.uthreecmp.i32(i32 %x, i32 %y)", 0},
       {true, "call i32 @llvm.bitreverse.i32(i32 %x)", 0},
       {true, "call i32 @llvm.bswap.i32(i32 %x)", 0},
       {false, "call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %shamt)", 0},

>From 294822f9ef7b775a72a499b828a17a192566c8a2 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Sun, 10 Mar 2024 13:51:29 -0600
Subject: [PATCH 09/37] add u/scmp result type overload over a fixed type in
 Intrinsics.td

---
 llvm/include/llvm/IR/Intrinsics.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 9f437375e64bd4..f1249f052d9dbe 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1527,10 +1527,10 @@ def int_umin : DefaultAttrsIntrinsic<
     [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
     [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
 def int_scmp : DefaultAttrsIntrinsic<
-    [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
+    [llvm_anyint_ty], [llvm_anyint_ty, LLVMMatchType<1>],
     [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
 def int_ucmp : DefaultAttrsIntrinsic<
-    [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
+    [llvm_anyint_ty], [llvm_anyint_ty, LLVMMatchType<1>],
     [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
 
 //===------------------------- Memory Use Markers -------------------------===//

>From 7651b2ea9cbfb278f2bb68ce5040eb33753d99ba Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 00:10:14 -0600
Subject: [PATCH 10/37] add VisitIntrinsicCall cases for Intrinsic::ucmp/scmp

---
 llvm/lib/IR/Verifier.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index e0de179e57146f..de828664b4964c 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5235,6 +5235,25 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     }
     break;
   }
+  case Intrinsic::ucmp:
+  case Intrinsic::scmp: {
+
+    Type *SrcTy = Call.getOperand(0)->getType();
+    Type *DestTy = Call.getType();
+
+    Check(SrcTy->isIntOrIntVectorTy(), "[u]scmp only operates on integers", Call);
+    Check(DestTy->isIntOrIntVectorTy(), "[u]scmp only produces integers", Call);
+    Check(DestTy->getScalarSizeInBits() >= 2, "DestTy must be at least 2 bits wide", Call);
+
+    auto isDestTypeVector = DestTy->isVectorTy();
+    if (isDestTypeVector) {
+      Check(SrcTy->isVectorTy() == isDestTypeVector,
+        "[u]scmp source and destination must both be a vector or neither", Call);
+      Check(SrcTy->getArrayNumElements() == DestTy->getArrayNumElements(),
+        "the return type the first arg type must have the same number of elements", Call);
+    }
+    break;
+  }
   case Intrinsic::coro_id: {
     auto *InfoArg = Call.getArgOperand(3)->stripPointerCasts();
     if (isa<ConstantPointerNull>(InfoArg))

>From a4fe31d6e6f0a4595b4863bd7e3e5c96094871ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 10:12:15 -0600
Subject: [PATCH 11/37] Update llvm/lib/IR/Verifier.cpp

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/lib/IR/Verifier.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index de828664b4964c..98b5748ad81a83 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5245,7 +5245,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     Check(DestTy->isIntOrIntVectorTy(), "[u]scmp only produces integers", Call);
     Check(DestTy->getScalarSizeInBits() >= 2, "DestTy must be at least 2 bits wide", Call);
 
-    auto isDestTypeVector = DestTy->isVectorTy();
+    bool isDestTypeVector = DestTy->isVectorTy();
     if (isDestTypeVector) {
       Check(SrcTy->isVectorTy() == isDestTypeVector,
         "[u]scmp source and destination must both be a vector or neither", Call);

>From cdf4abf5980491f23f5c41de060645c7392f94b7 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 10:40:17 -0600
Subject: [PATCH 12/37] add proper type overloads for llvm.ucmp.i2.i32 and
 llvm.scmp.i2.i32 in LangRef

---
 llvm/docs/LangRef.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index ff600c0dfe35b3..249a1dd012f5ae 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14544,8 +14544,8 @@ integer bit width or any vector of integer elements.
 
 ::
 
-      declare i32 @llvm.scmp.i32(i32 %a, i32 %b)
-      declare <4 x i32> @llvm.scmp.v4i32(<4 x i32> %a, <4 x i32> %b)
+      declare i2 @llvm.scmp.i2.i32(i32 %a, i32 %b)
+      declare <4 x i32> @llvm.scmp.i32.v4i32(<4 x i32> %a, <4 x i32> %b)
 
 Overview:
 """""""""
@@ -14573,8 +14573,8 @@ integer bit width or any vector of integer elements.
 
 ::
 
-      declare i2 @llvm.ucmp.i32(i32 %a, i32 %b)
-      declare <4 x i32> @llvm.ucmp.v4i32(<4 x i32> %a, <4 x i32> %b)
+      declare i2 @llvm.ucmp.i2.i32(i32 %a, i32 %b)
+      declare <4 x i32> @llvm.ucmp.i32.v4i32(<4 x i32> %a, <4 x i32> %b)
 
 Overview:
 """""""""

>From ae6910fee7ceb582eb52ba94bc3812171dd33f51 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 10:47:41 -0600
Subject: [PATCH 13/37] move isVector check above else to catch dest as scalar
 but src as vector

---
 llvm/lib/IR/Verifier.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 98b5748ad81a83..8aa02402e2c416 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5246,9 +5246,9 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     Check(DestTy->getScalarSizeInBits() >= 2, "DestTy must be at least 2 bits wide", Call);
 
     bool isDestTypeVector = DestTy->isVectorTy();
-    if (isDestTypeVector) {
-      Check(SrcTy->isVectorTy() == isDestTypeVector,
+    Check(SrcTy->isVectorTy() == isDestTypeVector,
         "[u]scmp source and destination must both be a vector or neither", Call);
+    if (isDestTypeVector) {
       Check(SrcTy->getArrayNumElements() == DestTy->getArrayNumElements(),
         "the return type the first arg type must have the same number of elements", Call);
     }

>From d68cf0df3a4cf87b62db5b8cdd62d05fdf8c82ca Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 10:49:20 -0600
Subject: [PATCH 14/37] omit checks done by Intrinsics.td on u/scmp operating
 on int-likes

---
 llvm/lib/IR/Verifier.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 8aa02402e2c416..73b357b6ad4c93 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5241,8 +5241,6 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     Type *SrcTy = Call.getOperand(0)->getType();
     Type *DestTy = Call.getType();
 
-    Check(SrcTy->isIntOrIntVectorTy(), "[u]scmp only operates on integers", Call);
-    Check(DestTy->isIntOrIntVectorTy(), "[u]scmp only produces integers", Call);
     Check(DestTy->getScalarSizeInBits() >= 2, "DestTy must be at least 2 bits wide", Call);
 
     bool isDestTypeVector = DestTy->isVectorTy();

>From 7b3cfee2cdd6909f722fa2f44f49da5a0dadfc52 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 15:27:46 -0600
Subject: [PATCH 15/37] Update llvm/docs/LangRef.rst

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 249a1dd012f5ae..baf74d77e9cc54 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14556,7 +14556,7 @@ Return ``-1`` if ``%a`` is less than ``%b``, ``0`` if they are equal, and
 Arguments:
 """"""""""
 
-The arguments (``%a`` and ``%b``) may be of any signed integer type or a vector with
+The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
 integer element type. The argument types must match each other, and the return
 type must be at least as wide as ``i2``, to uphold the ``-1`` return value.
 

>From 3a0ee32dfb09a2801bd21740c757c699001c5203 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 15:27:56 -0600
Subject: [PATCH 16/37] Update llvm/docs/LangRef.rst

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index baf74d77e9cc54..d74b54e66bfd57 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14585,7 +14585,7 @@ Return ``-1`` if ``%a`` is less than ``%b``, ``0`` if they are equal, and
 Arguments:
 """"""""""
 
-The arguments (``%a`` and ``%b``) may be of any unsigned integer type or a vector with
+The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
 integer element type. The argument types must match each other, and the return
 type must be at least as wide as ``i2``, to uphold the ``-1`` return value.
 

>From 343daf4c956e1ce0c48265b710192eaea1e0f4d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 15:28:14 -0600
Subject: [PATCH 17/37] Update llvm/docs/LangRef.rst

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/docs/LangRef.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index d74b54e66bfd57..7f39864c473a94 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14550,8 +14550,8 @@ integer bit width or any vector of integer elements.
 Overview:
 """""""""
 
-Return ``-1`` if ``%a`` is less than ``%b``, ``0`` if they are equal, and 
-``1`` if ``%a`` is greater than ``%b``. Vector intrinsics operate on a per-element basis. 
+Return ``-1`` if ``%a`` is signed less than ``%b``, ``0`` if they are equal, and 
+``1`` if ``%a`` is signed greater than ``%b``. Vector intrinsics operate on a per-element basis. 
 
 Arguments:
 """"""""""

>From 4cd70d6fcb17c46b5d352c76888b2b2fe364a572 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 15:28:38 -0600
Subject: [PATCH 18/37] Update llvm/lib/IR/Verifier.cpp

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/lib/IR/Verifier.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 73b357b6ad4c93..065d9eff0a549e 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5241,7 +5241,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     Type *SrcTy = Call.getOperand(0)->getType();
     Type *DestTy = Call.getType();
 
-    Check(DestTy->getScalarSizeInBits() >= 2, "DestTy must be at least 2 bits wide", Call);
+    Check(DestTy->getScalarSizeInBits() >= 2, "Result type must be at least 2 bits wide", Call);
 
     bool isDestTypeVector = DestTy->isVectorTy();
     Check(SrcTy->isVectorTy() == isDestTypeVector,

>From c8b5e025905d80fa57781add29aad045011f0871 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 15:29:52 -0600
Subject: [PATCH 19/37] Update llvm/lib/IR/Verifier.cpp

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/lib/IR/Verifier.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 065d9eff0a549e..196d95badffb86 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5245,7 +5245,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
 
     bool isDestTypeVector = DestTy->isVectorTy();
     Check(SrcTy->isVectorTy() == isDestTypeVector,
-        "[u]scmp source and destination must both be a vector or neither", Call);
+        "[us]cmp source and destination must both be a vector or neither", Call);
     if (isDestTypeVector) {
       Check(SrcTy->getArrayNumElements() == DestTy->getArrayNumElements(),
         "the return type the first arg type must have the same number of elements", Call);

>From a86c4a039692ac48f57bcb6ca0c243f047df0010 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 18:32:19 -0600
Subject: [PATCH 20/37] delete stray newline

---
 llvm/lib/IR/Verifier.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 196d95badffb86..0eaa7f827c6fa6 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5237,7 +5237,6 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
   }
   case Intrinsic::ucmp:
   case Intrinsic::scmp: {
-
     Type *SrcTy = Call.getOperand(0)->getType();
     Type *DestTy = Call.getType();
 

>From f8879885d19729c9a8c316baa2fe15755a0570f8 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 18:35:37 -0600
Subject: [PATCH 21/37] cast to vectors (not arrays!) in scmp Check

---
 llvm/lib/IR/Verifier.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 0eaa7f827c6fa6..9fc7c50cdf03ad 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5246,7 +5246,9 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     Check(SrcTy->isVectorTy() == isDestTypeVector,
         "[us]cmp source and destination must both be a vector or neither", Call);
     if (isDestTypeVector) {
-      Check(SrcTy->getArrayNumElements() == DestTy->getArrayNumElements(),
+      auto srcVecLen = cast<VectorType>(SrcTy)->getElementCount();
+      auto destVecLen = cast<VectorType>(DestTy)->getElementCount();
+      Check(srcVecLen == destVecLen,
         "the return type the first arg type must have the same number of elements", Call);
     }
     break;

>From d6d0a27b7270c8466830c5a9e9ef1038a6817d82 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 19:23:46 -0600
Subject: [PATCH 22/37] add Filecheck tests for Verifier.cpp u/scmp intrinsics

---
 llvm/lib/IR/Verifier.cpp            |  4 ++--
 llvm/test/Verifier/intrinsic-cmp.ll | 23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/Verifier/intrinsic-cmp.ll

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 9fc7c50cdf03ad..1fe462162a7ad4 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5240,7 +5240,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     Type *SrcTy = Call.getOperand(0)->getType();
     Type *DestTy = Call.getType();
 
-    Check(DestTy->getScalarSizeInBits() >= 2, "Result type must be at least 2 bits wide", Call);
+    Check(DestTy->getScalarSizeInBits() >= 2, "result type must be at least 2 bits wide", Call);
 
     bool isDestTypeVector = DestTy->isVectorTy();
     Check(SrcTy->isVectorTy() == isDestTypeVector,
@@ -5249,7 +5249,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
       auto srcVecLen = cast<VectorType>(SrcTy)->getElementCount();
       auto destVecLen = cast<VectorType>(DestTy)->getElementCount();
       Check(srcVecLen == destVecLen,
-        "the return type the first arg type must have the same number of elements", Call);
+        "return type and first arg type must have the same number of elements", Call);
     }
     break;
   }
diff --git a/llvm/test/Verifier/intrinsic-cmp.ll b/llvm/test/Verifier/intrinsic-cmp.ll
new file mode 100644
index 00000000000000..da8903a451a18a
--- /dev/null
+++ b/llvm/test/Verifier/intrinsic-cmp.ll
@@ -0,0 +1,23 @@
+; RUN: not opt -S -passes=verify 2>&1 < %s | FileCheck %s
+
+
+define @matching_vector_lens(<4 x i32> %arg1, <4 x i32> %arg2) {
+	; CHECK-LABEL: cmp_vector_lens_match
+	; CHECK: return type and first arg type must have the same number of elements
+	%res = call <8 x i32> @llvm.scmp.v8i32.v4i32(<4 x i32> %arg1, <4 x i32> %arg2)
+}
+
+define @result_len_is_at_least_2(i32 %arg1, i32 %arg2) {
+	; CHECK-LABEL: cmp_result_len_is_at_least_2bits_wide
+	; CHECK: result type must be at least 2 bits wide
+	%res2 = call i1 @llvm.scmp.i1.i32(i32 %arg1, i32 %arg2)
+}
+
+define @both_args_are_vecs_or_neither(<4 x i32> %arg1, i32 %arg2) {
+	; CHECK-LABEL: cmp_sources_and_dest_types_ranks_match
+	; CHECK: [us]cmp source and destination must both be a vector or neither
+	@res3 = call i2 @llvm.scmp.i2.v4i32(<4 x i32> %arg1, i32 %arg2)
+	; CHECK: [us]cmp source and destination must both be a vector or neither
+	@res4 = call <4 x i32> @llvm.scmp.v4i32.i32(<4 x i32> %arg2, i32 %arg2)
+	; CHECK: [us]cmp source and destination must both be a vector or neither
+}
\ No newline at end of file

>From 4f91e5158e5067c62ec5ed97f06cf5039201a8fc Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 19:26:32 -0600
Subject: [PATCH 23/37] delete last unneded CHECK

---
 llvm/test/Verifier/intrinsic-cmp.ll | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/test/Verifier/intrinsic-cmp.ll b/llvm/test/Verifier/intrinsic-cmp.ll
index da8903a451a18a..a26f302ce5c615 100644
--- a/llvm/test/Verifier/intrinsic-cmp.ll
+++ b/llvm/test/Verifier/intrinsic-cmp.ll
@@ -19,5 +19,4 @@ define @both_args_are_vecs_or_neither(<4 x i32> %arg1, i32 %arg2) {
 	@res3 = call i2 @llvm.scmp.i2.v4i32(<4 x i32> %arg1, i32 %arg2)
 	; CHECK: [us]cmp source and destination must both be a vector or neither
 	@res4 = call <4 x i32> @llvm.scmp.v4i32.i32(<4 x i32> %arg2, i32 %arg2)
-	; CHECK: [us]cmp source and destination must both be a vector or neither
 }
\ No newline at end of file

>From 38e94c590648d9953be747ac2cdf9a4e5bb1ed9d Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 21:06:08 -0600
Subject: [PATCH 24/37] make return value length more simple on scmp and ucmp

---
 llvm/docs/LangRef.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 7f39864c473a94..3f59abdc118ee5 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14558,7 +14558,7 @@ Arguments:
 
 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
 integer element type. The argument types must match each other, and the return
-type must be at least as wide as ``i2``, to uphold the ``-1`` return value.
+type must be at least as wide as ``i2``, to hold the three possible return values.
 
 .. _int_ucmp:
 
@@ -14587,7 +14587,7 @@ Arguments:
 
 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
 integer element type. The argument types must match each other, and the return
-type must be at least as wide as ``i2``, to uphold the ``-1`` return value.
+type must be at least as wide as ``i2``, to uphold the three possible return values.
 
 .. _int_memcpy:
 

>From 915ead2b9cc1f5c26202629fbfe201ec0a7da88c Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Mon, 11 Mar 2024 21:07:07 -0600
Subject: [PATCH 25/37] make return value length more simple on scmp and ucmp

---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 3f59abdc118ee5..c485703497fae7 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14587,7 +14587,7 @@ Arguments:
 
 The arguments (``%a`` and ``%b``) may be of any integer type or a vector with
 integer element type. The argument types must match each other, and the return
-type must be at least as wide as ``i2``, to uphold the three possible return values.
+type must be at least as wide as ``i2``, to hold the three possible return values.
 
 .. _int_memcpy:
 

>From 266894c0f7707859aa742801f578d3062e43c9d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Tue, 12 Mar 2024 12:38:15 -0600
Subject: [PATCH 26/37] Update llvm/docs/LangRef.rst

Co-authored-by: scottmcm <scottmcm at users.noreply.github.com>
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index c485703497fae7..1313d58d53420e 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14545,7 +14545,7 @@ integer bit width or any vector of integer elements.
 ::
 
       declare i2 @llvm.scmp.i2.i32(i32 %a, i32 %b)
-      declare <4 x i32> @llvm.scmp.i32.v4i32(<4 x i32> %a, <4 x i32> %b)
+      declare <4 x i32> @llvm.scmp.v4i32.v4i32(<4 x i32> %a, <4 x i32> %b)
 
 Overview:
 """""""""

>From 0d988d51d82d8adee2d67d6fb0c072d16a2d22ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Tue, 12 Mar 2024 12:38:24 -0600
Subject: [PATCH 27/37] Update llvm/docs/LangRef.rst

Co-authored-by: scottmcm <scottmcm at users.noreply.github.com>
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 1313d58d53420e..a65503f77032f5 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14574,7 +14574,7 @@ integer bit width or any vector of integer elements.
 ::
 
       declare i2 @llvm.ucmp.i2.i32(i32 %a, i32 %b)
-      declare <4 x i32> @llvm.ucmp.i32.v4i32(<4 x i32> %a, <4 x i32> %b)
+      declare <4 x i32> @llvm.ucmp.v4i32.v4i32(<4 x i32> %a, <4 x i32> %b)
 
 Overview:
 """""""""

>From 045d3856eb8bbba4e85a6be30256e51d7eb6d9cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 09:29:42 -0600
Subject: [PATCH 28/37] Update llvm/docs/LangRef.rst

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index a65503f77032f5..b62de807dcd95f 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14579,7 +14579,7 @@ integer bit width or any vector of integer elements.
 Overview:
 """""""""
 
-Return ``-1`` if ``%a`` is less than ``%b``, ``0`` if they are equal, and 
+Return ``-1`` if ``%a`` is unsigned less than ``%b``, ``0`` if they are equal, and 
 ``1`` if ``%a`` is greater than ``%b``. Vector intrinsics operate on a per-element basis. 
 
 Arguments:

>From 45ccd007647492b31b3e245b97658bab25342b83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 09:29:53 -0600
Subject: [PATCH 29/37] Update llvm/docs/LangRef.rst

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index b62de807dcd95f..d28f450b1aa42a 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14580,7 +14580,7 @@ Overview:
 """""""""
 
 Return ``-1`` if ``%a`` is unsigned less than ``%b``, ``0`` if they are equal, and 
-``1`` if ``%a`` is greater than ``%b``. Vector intrinsics operate on a per-element basis. 
+``1`` if ``%a`` is unsigned greater than ``%b``. Vector intrinsics operate on a per-element basis. 
 
 Arguments:
 """"""""""

>From 2666817da1e74d886e82df79ff03e7a5c63a1f3b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 09:42:31 -0600
Subject: [PATCH 30/37] Update llvm/lib/IR/Verifier.cpp

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/lib/IR/Verifier.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 1fe462162a7ad4..76382e902a7113 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5242,7 +5242,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
 
     Check(DestTy->getScalarSizeInBits() >= 2, "result type must be at least 2 bits wide", Call);
 
-    bool isDestTypeVector = DestTy->isVectorTy();
+    bool IsDestTypeVector = DestTy->isVectorTy();
     Check(SrcTy->isVectorTy() == isDestTypeVector,
         "[us]cmp source and destination must both be a vector or neither", Call);
     if (isDestTypeVector) {

>From fbfdea37437efab2c51489ca848d5f0b8a324a80 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 09:47:01 -0600
Subject: [PATCH 31/37] fix CodingStandards for var casenames and 4 spaces not
 tabs in FileCheck tests

---
 llvm/lib/IR/Verifier.cpp            | 10 ++++----
 llvm/test/Verifier/intrinsic-cmp.ll | 37 +++++++++++++++++------------
 2 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 76382e902a7113..d0ea5bb3ed8609 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5243,12 +5243,12 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     Check(DestTy->getScalarSizeInBits() >= 2, "result type must be at least 2 bits wide", Call);
 
     bool IsDestTypeVector = DestTy->isVectorTy();
-    Check(SrcTy->isVectorTy() == isDestTypeVector,
+    Check(SrcTy->isVectorTy() == IsDestTypeVector,
         "[us]cmp source and destination must both be a vector or neither", Call);
-    if (isDestTypeVector) {
-      auto srcVecLen = cast<VectorType>(SrcTy)->getElementCount();
-      auto destVecLen = cast<VectorType>(DestTy)->getElementCount();
-      Check(srcVecLen == destVecLen,
+    if (IsDestTypeVector) {
+      auto SrcVecLen = cast<VectorType>(SrcTy)->getElementCount();
+      auto DestVecLen = cast<VectorType>(DestTy)->getElementCount();
+      Check(SrcVecLen == DestVecLen,
         "return type and first arg type must have the same number of elements", Call);
     }
     break;
diff --git a/llvm/test/Verifier/intrinsic-cmp.ll b/llvm/test/Verifier/intrinsic-cmp.ll
index a26f302ce5c615..aaf8be178dc278 100644
--- a/llvm/test/Verifier/intrinsic-cmp.ll
+++ b/llvm/test/Verifier/intrinsic-cmp.ll
@@ -1,22 +1,29 @@
 ; RUN: not opt -S -passes=verify 2>&1 < %s | FileCheck %s
 
 
-define @matching_vector_lens(<4 x i32> %arg1, <4 x i32> %arg2) {
-	; CHECK-LABEL: cmp_vector_lens_match
-	; CHECK: return type and first arg type must have the same number of elements
-	%res = call <8 x i32> @llvm.scmp.v8i32.v4i32(<4 x i32> %arg1, <4 x i32> %arg2)
+declare void @matching_vector_lens.v4i32.v4i32(<4 x i32>, <4 x i32>)
+define void @matching_vector_lens(<4 x i32> %arg1, <4 x i32> %arg2) {
+    ; CHECK-LABEL: cmp_vector_lens_match
+    ; CHECK: return type and first arg type must have the same number of elements
+    %res = call <8 x i32> @llvm.scmp.v8i32.v4i32(<4 x i32> %arg1, <4 x i32> %arg2)
+    return void
 }
 
-define @result_len_is_at_least_2(i32 %arg1, i32 %arg2) {
-	; CHECK-LABEL: cmp_result_len_is_at_least_2bits_wide
-	; CHECK: result type must be at least 2 bits wide
-	%res2 = call i1 @llvm.scmp.i1.i32(i32 %arg1, i32 %arg2)
+declare void @result_len_is_at_least_2.i32.i32(i32, i32)
+define void @result_len_is_at_least_2(i32 %arg1, i32 %arg2) {
+    ; CHECK-LABEL: cmp_result_len_is_at_least_2bits_wide
+    ; CHECK: result type must be at least 2 bits wide
+    %res2 = call i1 @llvm.scmp.i1.i32(i32 %arg1, i32 %arg2)
+    return void
+}
+
+declare void @both_args_are_vecs_or_neither.v4i32.i32(<4 x i32>, i32)
+define void @both_args_are_vecs_or_neither(<4 x i32> %arg1, i32 %arg2) {
+    ; CHECK-LABEL: cmp_sources_and_dest_types_ranks_match
+    ; CHECK: [us]cmp source and destination must both be a vector or neither
+    @res3 = call i2 @llvm.scmp.i2.v4i32(<4 x i32> %arg1, i32 %arg2)
+    ; CHECK: [us]cmp source and destination must both be a vector or neither
+    @res4 = call <4 x i32> @llvm.scmp.v4i32.i32(<4 x i32> %arg2, i32 %arg2)
+    return void
 }
 
-define @both_args_are_vecs_or_neither(<4 x i32> %arg1, i32 %arg2) {
-	; CHECK-LABEL: cmp_sources_and_dest_types_ranks_match
-	; CHECK: [us]cmp source and destination must both be a vector or neither
-	@res3 = call i2 @llvm.scmp.i2.v4i32(<4 x i32> %arg1, i32 %arg2)
-	; CHECK: [us]cmp source and destination must both be a vector or neither
-	@res4 = call <4 x i32> @llvm.scmp.v4i32.i32(<4 x i32> %arg2, i32 %arg2)
-}
\ No newline at end of file

>From 04c220b3e4c9877cbb576ddfb2562181911d32b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?=
 <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 10:08:13 -0600
Subject: [PATCH 32/37] Update llvm/test/Verifier/intrinsic-cmp.ll

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/test/Verifier/intrinsic-cmp.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/Verifier/intrinsic-cmp.ll b/llvm/test/Verifier/intrinsic-cmp.ll
index aaf8be178dc278..c85fed3919fea6 100644
--- a/llvm/test/Verifier/intrinsic-cmp.ll
+++ b/llvm/test/Verifier/intrinsic-cmp.ll
@@ -6,7 +6,7 @@ define void @matching_vector_lens(<4 x i32> %arg1, <4 x i32> %arg2) {
     ; CHECK-LABEL: cmp_vector_lens_match
     ; CHECK: return type and first arg type must have the same number of elements
     %res = call <8 x i32> @llvm.scmp.v8i32.v4i32(<4 x i32> %arg1, <4 x i32> %arg2)
-    return void
+    ret void
 }
 
 declare void @result_len_is_at_least_2.i32.i32(i32, i32)

>From 0f5d306534674cb60d662d11ca49078201d24ddd Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 10:14:05 -0600
Subject: [PATCH 33/37] align to 2 spaces

---
 llvm/test/Verifier/intrinsic-cmp.ll | 31 +++++++++++++----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/llvm/test/Verifier/intrinsic-cmp.ll b/llvm/test/Verifier/intrinsic-cmp.ll
index c85fed3919fea6..381201b8d6e656 100644
--- a/llvm/test/Verifier/intrinsic-cmp.ll
+++ b/llvm/test/Verifier/intrinsic-cmp.ll
@@ -1,29 +1,26 @@
 ; RUN: not opt -S -passes=verify 2>&1 < %s | FileCheck %s
 
 
-declare void @matching_vector_lens.v4i32.v4i32(<4 x i32>, <4 x i32>)
 define void @matching_vector_lens(<4 x i32> %arg1, <4 x i32> %arg2) {
-    ; CHECK-LABEL: cmp_vector_lens_match
-    ; CHECK: return type and first arg type must have the same number of elements
-    %res = call <8 x i32> @llvm.scmp.v8i32.v4i32(<4 x i32> %arg1, <4 x i32> %arg2)
-    ret void
+  ; CHECK-LABEL: cmp_vector_lens_match
+  ; CHECK: return type and first arg type must have the same number of elements
+  %res = call <8 x i32> @llvm.scmp.v8i32.v4i32(<4 x i32> %arg1, <4 x i32> %arg2)
+  ret void
 }
 
-declare void @result_len_is_at_least_2.i32.i32(i32, i32)
 define void @result_len_is_at_least_2(i32 %arg1, i32 %arg2) {
-    ; CHECK-LABEL: cmp_result_len_is_at_least_2bits_wide
-    ; CHECK: result type must be at least 2 bits wide
-    %res2 = call i1 @llvm.scmp.i1.i32(i32 %arg1, i32 %arg2)
-    return void
+  ; CHECK-LABEL: cmp_result_len_is_at_least_2bits_wide
+  ; CHECK: result type must be at least 2 bits wide
+  %res2 = call i1 @llvm.scmp.i1.i32(i32 %arg1, i32 %arg2)
+  ret void
 }
 
-declare void @both_args_are_vecs_or_neither.v4i32.i32(<4 x i32>, i32)
 define void @both_args_are_vecs_or_neither(<4 x i32> %arg1, i32 %arg2) {
-    ; CHECK-LABEL: cmp_sources_and_dest_types_ranks_match
-    ; CHECK: [us]cmp source and destination must both be a vector or neither
-    @res3 = call i2 @llvm.scmp.i2.v4i32(<4 x i32> %arg1, i32 %arg2)
-    ; CHECK: [us]cmp source and destination must both be a vector or neither
-    @res4 = call <4 x i32> @llvm.scmp.v4i32.i32(<4 x i32> %arg2, i32 %arg2)
-    return void
+  ; CHECK-LABEL: cmp_sources_and_dest_types_ranks_match
+  ; CHECK: [us]cmp source and destination must both be a vector or neither
+  @res3 = call i2 @llvm.scmp.i2.v4i32(<4 x i32> %arg1, i32 %arg2)
+  ; CHECK: [us]cmp source and destination must both be a vector or neither
+  @res4 = call <4 x i32> @llvm.scmp.v4i32.i32(<4 x i32> %arg2, i32 %arg2)
+  ret void
 }
 

>From d5e71467780f70596fd7bf81e2790c76acc1f6b7 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 10:27:20 -0600
Subject: [PATCH 34/37] fixup unit tests for scmp intrinsic

---
 llvm/test/Verifier/intrinsic-cmp.ll | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/test/Verifier/intrinsic-cmp.ll b/llvm/test/Verifier/intrinsic-cmp.ll
index 381201b8d6e656..8fd395b27a8fdc 100644
--- a/llvm/test/Verifier/intrinsic-cmp.ll
+++ b/llvm/test/Verifier/intrinsic-cmp.ll
@@ -18,9 +18,9 @@ define void @result_len_is_at_least_2(i32 %arg1, i32 %arg2) {
 define void @both_args_are_vecs_or_neither(<4 x i32> %arg1, i32 %arg2) {
   ; CHECK-LABEL: cmp_sources_and_dest_types_ranks_match
   ; CHECK: [us]cmp source and destination must both be a vector or neither
-  @res3 = call i2 @llvm.scmp.i2.v4i32(<4 x i32> %arg1, i32 %arg2)
+  %res3 = call i2 @llvm.scmp.i2.v4i32(<4 x i32> %arg1, <4 x i32> %arg1)
   ; CHECK: [us]cmp source and destination must both be a vector or neither
-  @res4 = call <4 x i32> @llvm.scmp.v4i32.i32(<4 x i32> %arg2, i32 %arg2)
+  %res4 = call <4 x i32> @llvm.scmp.v4i32.i32(i32 %arg2, i32 %arg2)
   ret void
 }
 

>From 94c853d9e4992eac7fa24430eeeb19d0512c2db1 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 10:34:56 -0600
Subject: [PATCH 35/37] appease the formatting gods

---
 llvm/lib/IR/Verifier.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index d0ea5bb3ed8609..e47472a30e24ee 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5240,11 +5240,13 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     Type *SrcTy = Call.getOperand(0)->getType();
     Type *DestTy = Call.getType();
 
-    Check(DestTy->getScalarSizeInBits() >= 2, "result type must be at least 2 bits wide", Call);
+    Check(DestTy->getScalarSizeInBits() >= 2,
+          "result type must be at least 2 bits wide", Call);
 
     bool IsDestTypeVector = DestTy->isVectorTy();
     Check(SrcTy->isVectorTy() == IsDestTypeVector,
-        "[us]cmp source and destination must both be a vector or neither", Call);
+          "[us]cmp source and destination must both be a vector or neither",
+          Call);
     if (IsDestTypeVector) {
       auto SrcVecLen = cast<VectorType>(SrcTy)->getElementCount();
       auto DestVecLen = cast<VectorType>(DestTy)->getElementCount();

>From f09c3e4e4ad25d19d875eabf5192a301ea05395a Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 10:39:57 -0600
Subject: [PATCH 36/37] appease the formatting gods, again

---
 llvm/lib/IR/Verifier.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index e47472a30e24ee..596f02e67e4817 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5250,8 +5250,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     if (IsDestTypeVector) {
       auto SrcVecLen = cast<VectorType>(SrcTy)->getElementCount();
       auto DestVecLen = cast<VectorType>(DestTy)->getElementCount();
-      Check(SrcVecLen == DestVecLen,
-        "return type and first arg type must have the same number of elements", Call);
+      Check(SrcVecLen == DestVecLen, "return type and first arg type must have the same number of elements", Call);
     }
     break;
   }

>From a85ae26a2a645f332ac5bf0693acf78edad5f3e2 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 10:45:30 -0600
Subject: [PATCH 37/37] appease the formatting gods, again, again

---
 llvm/lib/IR/Verifier.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 596f02e67e4817..54f28e208c141f 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5250,7 +5250,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
     if (IsDestTypeVector) {
       auto SrcVecLen = cast<VectorType>(SrcTy)->getElementCount();
       auto DestVecLen = cast<VectorType>(DestTy)->getElementCount();
-      Check(SrcVecLen == DestVecLen, "return type and first arg type must have the same number of elements", Call);
+      Check(SrcVecLen == DestVecLen, "return type and first arg type must have the same number of " "elements", Call);
     }
     break;
   }



More information about the llvm-commits mailing list