[llvm] add scmp and ucmp to SelectionDAG.cpp (PR #84681)

Miguel Raz Guzmán Macedo via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 19:39:19 PDT 2024


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

>From 1361e6cb8735079e6991c70a9a0d855d407ab00b 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/49] 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 ecedd3a32c7b36..a8db7722d222d9 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -11996,6 +11996,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 4fa4ebea7839e5ae6c8a17a76d53e5f2188ef0f7 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/49] 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 144298fd7c0162..aeb0f7d182c163 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -2150,7 +2150,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 0c82ff2ece2c425d5af831d7c334fc111e29abe9 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/49] 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 a8db7722d222d9..f5a1c17b6751f4 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -12064,7 +12064,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 d6c2c1f584acb5d8f8d26789b8f5a8c42c686eae 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/49] 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 f5a1c17b6751f4..94dc664d9407d3 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -11996,98 +11996,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
@@ -14666,6 +14574,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 b23515efe4cee229e22c439746a4a673cebcf11e 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/49] 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 aeb0f7d182c163..a13c7c74f4bbe6 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1528,6 +1528,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 -------------------------===//
 //
@@ -2150,14 +2156,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 1136f1488eaafb2b7af83da99a9cbbb5ccd92e5e 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/49] 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 6c6897d83a256e..a579e8522fb7bc 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 e3e2ebfe2028733950a3f1ea186da05e9fd0b4ba 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/49] 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 94dc664d9407d3..1a3bdf1ec9cd26 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14574,21 +14574,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:
 """""""""
@@ -14603,21 +14603,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 d3fbc96c48b2575390f1fa4fdf7fad8aa71957b7 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/49] 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 a13c7c74f4bbe6..c873b26ce8ec4a 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1528,10 +1528,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 a579e8522fb7bc..6c6897d83a256e 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 31341f2ed24c9fec22d2f20765490ccf9260b7b4 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/49] 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 c873b26ce8ec4a..091f9b38107989 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1529,10 +1529,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 3e503f1cff8fbc0905db1c5b406b420a682c8eeb 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/49] 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 2b9dc745d7bfc5..32ede7876d1fc1 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5265,6 +5265,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 f1e2586dcf0a93696792b87fdb0216587ff1ebf7 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 11/49] 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 1a3bdf1ec9cd26..ea09744e6ab145 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14587,8 +14587,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:
 """""""""
@@ -14616,8 +14616,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 ec576e233f115250aade6057a27d5a9637772731 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 12/49] 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 32ede7876d1fc1..9a64733139e919 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5275,7 +5275,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 ba58a4eaee6a8324fe5ae7956e20d4e3d905946e 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/49] 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 9a64733139e919..a290b2b451da42 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5276,9 +5276,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 475c2aef6599897028ed49b3bfa659cbc7685684 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/49] 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 a290b2b451da42..d207f0af84cf6b 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5271,8 +5271,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 0c558f1ee24a412cf78621a01aa2397042e5b064 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/49] 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 ea09744e6ab145..6bcd7260352a08 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14599,7 +14599,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 b673ca11ea42a9f114a08c54cea06c70c81503b7 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/49] 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 6bcd7260352a08..817237ce45e0e0 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14628,7 +14628,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 5d0707d521ad3e9056dcf725277810157fbfd194 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/49] 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 817237ce45e0e0..d424447dfcca7a 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14593,8 +14593,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 a7bb3a7be2bbed8f2436c3b0181311a6905d6421 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/49] 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 d207f0af84cf6b..e2c68060bfd7da 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5271,7 +5271,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 d2ed755b9db30084f0af00286e4e10a98c450f38 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/49] 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 e2c68060bfd7da..b79cea47f0b7df 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5275,7 +5275,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 f4a57b0f0bf22f8c9086859470ad97e3f3951462 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/49] 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 b79cea47f0b7df..71b9a7bd0a658b 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5267,7 +5267,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 18b12bac03ad0244e7454174f5006e3fac6dcd16 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/49] 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 71b9a7bd0a658b..9eca17bf054d72 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5276,7 +5276,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 44308f630303c9797f8486b556d17c01acc7bf15 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/49] 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 9eca17bf054d72..54ad465827b3cb 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5270,7 +5270,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,
@@ -5279,7 +5279,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 b219c409708ae270860823dcdfa7c7d7f6d24d4c 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/49] 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 09bf47025f3b0d988c16f8d3fed0cf61b07dc13d 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/49] 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 d424447dfcca7a..ded8a1f4e4c9cd 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14601,7 +14601,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:
 
@@ -14630,7 +14630,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 ca67268de4aef86fdb0b8f066ad302375884efdb 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/49] 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 ded8a1f4e4c9cd..315e81ede2de38 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14630,7 +14630,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 ca1d41249ab23422a9f308fd8f2caeb74722ff18 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/49] 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 315e81ede2de38..95f0a10d4886a6 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14588,7 +14588,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 7ddf56be972a861a24f94a0b8b70a11859aae154 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/49] 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 95f0a10d4886a6..1e9b24e60483e7 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14617,7 +14617,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 54b32cc0034477f39220ae1570ff89387bfaca7c 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/49] 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 1e9b24e60483e7..b77db8da63f501 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14622,7 +14622,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 331cae36dfe2b1731230e19fcc7ec05c710003ba 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/49] 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 b77db8da63f501..e07b642285b3e6 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -14623,7 +14623,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 6210d0c15dd055722368301ad52d7b30106ee925 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/49] 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 54ad465827b3cb..f0e89351bca9fd 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5272,7 +5272,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 497567df7a08bf45f0d813e16f5c96aeadbfb206 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/49] 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 f0e89351bca9fd..43b70bf32930fa 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5273,12 +5273,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 ffbdeb030655a15c43a1891c54d7e27a4d7e3ec3 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/49] 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 c79576376d90d1d561c18e6c57350c89746ad5a0 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/49] 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 08835b53bcc35c85668536e3ec0094ed21401177 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/49] 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 96b8bab7637b58bee3c64e233daef7098520e9ce 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/49] 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 43b70bf32930fa..f4b0cc3049f65c 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5270,11 +5270,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 40dba1462293b500025aecc833355c2557ceee4e 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/49] 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 f4b0cc3049f65c..fd52164056fe01 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5280,8 +5280,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 0cc31dc8a8222e6b0fabecc3e716e1d1ca85c7cb 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/49] 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 fd52164056fe01..849a33f50b0031 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5280,7 +5280,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 41d39f385b1cf3ec68a4c8e3e316f747a6d09c92 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Thu, 14 Mar 2024 10:46:39 -0600
Subject: [PATCH 38/49] appease the formatting gods, again, again, again

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

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 849a33f50b0031..2d14577d78f45e 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5280,7 +5280,10 @@ 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 b5015dccc58ed359546c18578711d4efb3d13204 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Fri, 15 Mar 2024 08:46:55 -0600
Subject: [PATCH 39/49] appease the FileCheck gods \o/

---
 llvm/test/Verifier/intrinsic-cmp.ll | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/llvm/test/Verifier/intrinsic-cmp.ll b/llvm/test/Verifier/intrinsic-cmp.ll
index 8fd395b27a8fdc..3b233f69a25c56 100644
--- a/llvm/test/Verifier/intrinsic-cmp.ll
+++ b/llvm/test/Verifier/intrinsic-cmp.ll
@@ -1,22 +1,18 @@
 ; RUN: not opt -S -passes=verify 2>&1 < %s | FileCheck %s
 
-
 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
 }
 
-define void @result_len_is_at_least_2(i32 %arg1, i32 %arg2) {
-  ; CHECK-LABEL: cmp_result_len_is_at_least_2bits_wide
+define void @result_len_is_at_least_2bits_wide(i32 %arg1, i32 %arg2) {
   ; CHECK: result type must be at least 2 bits wide
   %res2 = call i1 @llvm.scmp.i1.i32(i32 %arg1, i32 %arg2)
   ret void
 }
 
 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, <4 x i32> %arg1)
   ; CHECK: [us]cmp source and destination must both be a vector or neither

>From 1b0d354fc8725d135db5cc78ec2b351b9e460d23 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Fri, 15 Mar 2024 10:43:55 -0600
Subject: [PATCH 40/49] phrasing nits for error messages

---
 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 2d14577d78f45e..76eda36c22b395 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5275,13 +5275,13 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
 
     bool IsDestTypeVector = DestTy->isVectorTy();
     Check(SrcTy->isVectorTy() == IsDestTypeVector,
-          "[us]cmp source and destination must both be a vector or neither",
+          "ucmp/scmp argument and result types must both be either vector or scalar types",
           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 "
+            "return type and arguments must have the same number of "
             "elements",
             Call);
     }

>From 979b2cf76731ec0ebcefbc443b181a5239373e2e Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Fri, 15 Mar 2024 10:46:52 -0600
Subject: [PATCH 41/49] update FileCheck unit tests with most recent errors

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

diff --git a/llvm/test/Verifier/intrinsic-cmp.ll b/llvm/test/Verifier/intrinsic-cmp.ll
index 3b233f69a25c56..2224a5c5eba385 100644
--- a/llvm/test/Verifier/intrinsic-cmp.ll
+++ b/llvm/test/Verifier/intrinsic-cmp.ll
@@ -1,7 +1,7 @@
 ; RUN: not opt -S -passes=verify 2>&1 < %s | FileCheck %s
 
 define void @matching_vector_lens(<4 x i32> %arg1, <4 x i32> %arg2) {
-  ; CHECK: return type and first arg type must have the same number of elements
+  ; CHECK: return type and arguments 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
 }
@@ -13,9 +13,9 @@ define void @result_len_is_at_least_2bits_wide(i32 %arg1, i32 %arg2) {
 }
 
 define void @both_args_are_vecs_or_neither(<4 x i32> %arg1, i32 %arg2) {
-  ; CHECK: [us]cmp source and destination must both be a vector or neither
+  ; CHECK: ucmp/scmp argument and result types must both be either vector or scalar types
   %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
+  ; CHECK: ucmp/scmp argument and result types must both be either vector or scalar types
   %res4 = call <4 x i32> @llvm.scmp.v4i32.i32(i32 %arg2, i32 %arg2)
   ret void
 }

>From dd61f631e97f7674c305e63d8337ee687dac610a Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Fri, 15 Mar 2024 10:51:31 -0600
Subject: [PATCH 42/49] freakin' formatting gods

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

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 76eda36c22b395..62dde2e6ad4243 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5275,7 +5275,8 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
 
     bool IsDestTypeVector = DestTy->isVectorTy();
     Check(SrcTy->isVectorTy() == IsDestTypeVector,
-          "ucmp/scmp argument and result types must both be either vector or scalar types",
+          "ucmp/scmp argument and result types must both be either vector or "
+          "scalar types",
           Call);
     if (IsDestTypeVector) {
       auto SrcVecLen = cast<VectorType>(SrcTy)->getElementCount();

>From f17f652ac087a41dcd04b06f78f820e7ae80a07c Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas <alexandros.lamprineas at arm.com>
Date: Fri, 1 Mar 2024 10:57:53 +0000
Subject: [PATCH 43/49] [clang] Remove unused lambda capture. (#83550)

Fixes the `sanitizer-x86_64-linux-android` buildbot.

>From 6274092fe4c894a35dca8fb8e7136d709477faef Mon Sep 17 00:00:00 2001
From: AtariDreams <83477269+AtariDreams at users.noreply.github.com>
Date: Fri, 8 Mar 2024 08:43:45 -0500
Subject: [PATCH 44/49] [Hexagon] Use LiveRegUnits (#84112)


>From 416d5bb31ff6e3dd3f44fe061f0441cf7f7badb0 Mon Sep 17 00:00:00 2001
From: Amy Huang <akhuang at google.com>
Date: Wed, 13 Mar 2024 15:17:11 -0700
Subject: [PATCH 45/49] =?UTF-8?q?Unrevert=20"[Clang][C++23]=20Implement=20?=
 =?UTF-8?q?P2448R2:=20Relaxing=20some=20constexpr=20re=E2=80=A6=20(#85140)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Unrevert commit
https://github.com/llvm/llvm-project/commit/2f67dfb012038678dd0b873394a55bd5c937f843
as there were already dependent changes in the codebase that now fail.

>From f0fe7b1439b19520ab07e6080e53b5741db779c0 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Sun, 10 Mar 2024 09:51:29 -0600
Subject: [PATCH 46/49] first changes for ValueTrackingTest.cpp and
 SelectionDAG for s/ucmp

---
 llvm/include/llvm/CodeGen/ISDOpcodes.h        | 5 +++++
 llvm/include/llvm/CodeGen/TargetLowering.h    | 4 ++++
 llvm/unittests/Analysis/ValueTrackingTest.cpp | 2 ++
 3 files changed, 11 insertions(+)

diff --git a/llvm/include/llvm/CodeGen/ISDOpcodes.h b/llvm/include/llvm/CodeGen/ISDOpcodes.h
index 49d51a27e3c0f6..287919fca14905 100644
--- a/llvm/include/llvm/CodeGen/ISDOpcodes.h
+++ b/llvm/include/llvm/CodeGen/ISDOpcodes.h
@@ -676,6 +676,11 @@ enum NodeType {
   UMIN,
   UMAX,
 
+  /// [US]CMP - Three way integer comparison - returns -1, 0, or 1 if
+  /// Op1 < Op2, Op1 == Op2, Op1 > Op2, respectively.
+  SCMP,
+  UCMP,
+
   /// Bitwise operators - logical and, logical or, logical xor.
   AND,
   OR,
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 2f164a460db843..0786fc798f5748 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -5314,6 +5314,10 @@ class TargetLowering : public TargetLoweringBase {
   /// method accepts integers as its arguments.
   SDValue expandIntMINMAX(SDNode *Node, SelectionDAG &DAG) const;
 
+  /// Method for building the DAG expansion of ISD::[US]CMP. This
+  /// method accepts integers as its arguments.
+  SDValue expandCMP(SDNode *Node, SelectionDAG &DAG) const;
+
   /// Method for building the DAG expansion of ISD::[US][ADD|SUB]SAT. This
   /// method accepts integers as its arguments.
   SDValue expandAddSubSat(SDNode *Node, SelectionDAG &DAG) const;
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 6c6897d83a256e..b9c570c3ab80f6 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.scmp.i32(i32 %x, i32 %y)", 0},
+      {true, "call i32 @llvm.ucmp.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 346cc9b2f83f90564d37f0a1a1bdec9d5bfbea21 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Sun, 10 Mar 2024 10:14:24 -0600
Subject: [PATCH 47/49] add first attempt at SelectionDAG.cpp for u/scmp

---
 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 19f9354c23da42..6f364fb77c2621 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6750,12 +6750,18 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     if (VT.isVector() && VT.getVectorElementType() == MVT::i1)
       return getNode(ISD::AND, DL, VT, N1, N2);
     break;
-  case ISD::FADD:
-  case ISD::FSUB:
-  case ISD::FMUL:
-  case ISD::FDIV:
-  case ISD::FREM:
-    assert(VT.isFloatingPoint() && "This operator only applies to FP types!");
+  case ISD::UCMP:
+  case ISD::SCMP:
+    assert(VT.isInteger() && "This operator doe snot apply to FP types!");
+    assert(N1.getValueType() == N2.getValueType() && 
+           N1.getValueType() == VT && "Binary operator types must match");
+      break;
+    case ISD::FADD:
+    case ISD::FSUB:
+    case ISD::FMUL:
+    case ISD::FDIV:
+    case ISD::FREM:
+      assert(VT.isFloatingPoint() && "This operator only applies to FP types!");
     assert(N1.getValueType() == N2.getValueType() &&
            N1.getValueType() == VT && "Binary operator types must match!");
     if (SDValue V = simplifyFPBinop(Opcode, N1, N2, Flags))

>From 813a2d1634a6b6c50945b4adedb3ae4c5bdde61e Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Sun, 10 Mar 2024 10:25:53 -0600
Subject: [PATCH 48/49] fix formatting on irrelevant lines

---
 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 6f364fb77c2621..6f668868037f6d 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6756,12 +6756,12 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(N1.getValueType() == N2.getValueType() && 
            N1.getValueType() == VT && "Binary operator types must match");
       break;
-    case ISD::FADD:
-    case ISD::FSUB:
-    case ISD::FMUL:
-    case ISD::FDIV:
-    case ISD::FREM:
-      assert(VT.isFloatingPoint() && "This operator only applies to FP types!");
+  case ISD::FADD:
+  case ISD::FSUB:
+  case ISD::FMUL:
+  case ISD::FDIV:
+  case ISD::FREM:
+    assert(VT.isFloatingPoint() && "This operator only applies to FP types!");
     assert(N1.getValueType() == N2.getValueType() &&
            N1.getValueType() == VT && "Binary operator types must match!");
     if (SDValue V = simplifyFPBinop(Opcode, N1, N2, Flags))

>From cf90dbaf2cf67d9cba5404977fd2f04cb2bebd75 Mon Sep 17 00:00:00 2001
From: miguelraz <miguelraz at ciencias.unam.mx>
Date: Sun, 10 Mar 2024 13:19:20 -0600
Subject: [PATCH 49/49] fix typo in assert

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

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 6f668868037f6d..5b6ac8d1e33189 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6752,7 +6752,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     break;
   case ISD::UCMP:
   case ISD::SCMP:
-    assert(VT.isInteger() && "This operator doe snot apply to FP types!");
+    assert(VT.isInteger() && "This operator does not apply to FP types!");
     assert(N1.getValueType() == N2.getValueType() && 
            N1.getValueType() == VT && "Binary operator types must match");
       break;



More information about the llvm-commits mailing list