From 9d7134fbc570d8ce3218a69c56562aabda7a6be1 Mon Sep 17 00:00:00 2001 From: miguelraz Date: Thu, 29 Feb 2024 20:01:20 -0600 Subject: [PATCH 01/42] 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 f56d4ed28f285..ceffd33cdc54f 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -11976,6 +11976,98 @@ Example: = icmp ule i16 -4, 5 ; yields: result=false = icmp sge i16 4, 5 ; yields: result=false +.. _i_sthreecmp: + +'``sthreecmp``' Instruction +^^^^^^^^^^^^^^^^^^^^^^ + +Syntax: +""""""" + +:: + + = sthreecmp , ; yields i2 or :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 ` 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 + + = sthreecmp 4, 5 ; yields: result=-1 + = sthreecmp 2, 2 ; yields: result=0 + = sthreecmp -2, -1 ; yields: result=1 + +.. _i_uthreecmp: + +'``uthreecmp``' Instruction +^^^^^^^^^^^^^^^^^^^^^^ + +Syntax: +""""""" + +:: + + = uthreecmp , ; yields i2 or :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 ` 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 + + = uthreecmp 4, 5 ; yields: result=-1 + = uthreecmp 2, 2 ; yields: result=0 + = uthreecmp 9, 0 ; yields: result=1 + .. _i_fcmp: '``fcmp``' Instruction From 57ec729bd308d43adaedb7e095541991f4377111 Mon Sep 17 00:00:00 2001 From: miguelraz Date: Thu, 29 Feb 2024 20:49:59 -0600 Subject: [PATCH 02/42] 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 0f13d25eb30eb..15df2e7b76577 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 Date: Thu, 29 Feb 2024 20:50:37 -0600 Subject: [PATCH 03/42] 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 ceffd33cdc54f..5eae1015bffb1 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 Date: Fri, 1 Mar 2024 23:24:56 -0600 Subject: [PATCH 04/42] 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 5eae1015bffb1..62bcf825da5df 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -11976,98 +11976,6 @@ Example: = icmp ule i16 -4, 5 ; yields: result=false = icmp sge i16 4, 5 ; yields: result=false -.. _i_sthreecmp: - -'``sthreecmp``' Instruction -^^^^^^^^^^^^^^^^^^^^^^ - -Syntax: -""""""" - -:: - - = sthreecmp , ; yields i2 or :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 ` 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 - - = sthreecmp 4, 5 ; yields: result=-1 - = sthreecmp 2, 2 ; yields: result=0 - = sthreecmp -2, -1 ; yields: result=1 - -.. _i_uthreecmp: - -'``uthreecmp``' Instruction -^^^^^^^^^^^^^^^^^^^^^^ - -Syntax: -""""""" - -:: - - = uthreecmp , ; yields i2 or :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 ` 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 - - = uthreecmp 4, 5 ; yields: result=-1 - = uthreecmp 2, 2 ; yields: result=0 - = 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 Date: Fri, 1 Mar 2024 23:26:53 -0600 Subject: [PATCH 05/42] 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 15df2e7b76577..856f5545be016 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 Date: Sat, 2 Mar 2024 07:20:30 -0600 Subject: [PATCH 06/42] 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 9e0abe7a16df9..05f5e16a498e8 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 Date: Sat, 9 Mar 2024 20:47:07 -0600 Subject: [PATCH 07/42] 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 62bcf825da5df..ff600c0dfe35b 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 Date: Sun, 10 Mar 2024 09:46:05 -0600 Subject: [PATCH 08/42] 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 856f5545be016..9f437375e64bd 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 05f5e16a498e8..9e0abe7a16df9 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 Date: Sun, 10 Mar 2024 13:51:29 -0600 Subject: [PATCH 09/42] 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 9f437375e64bd..f1249f052d9db 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 Date: Mon, 11 Mar 2024 00:10:14 -0600 Subject: [PATCH 10/42] 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 e0de179e57146..de828664b4964 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(InfoArg)) From a4fe31d6e6f0a4595b4863bd7e3e5c96094871ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Raz=20Guzm=C3=A1n=20Macedo?= Date: Mon, 11 Mar 2024 10:12:15 -0600 Subject: [PATCH 11/42] Update llvm/lib/IR/Verifier.cpp Co-authored-by: Nikita Popov --- 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 de828664b4964..98b5748ad81a8 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 Date: Mon, 11 Mar 2024 10:40:17 -0600 Subject: [PATCH 12/42] 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 ff600c0dfe35b..249a1dd012f5a 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 Date: Mon, 11 Mar 2024 10:47:41 -0600 Subject: [PATCH 13/42] 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 98b5748ad81a8..8aa02402e2c41 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 Date: Mon, 11 Mar 2024 10:49:20 -0600 Subject: [PATCH 14/42] 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 8aa02402e2c41..73b357b6ad4c9 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?= Date: Mon, 11 Mar 2024 15:27:46 -0600 Subject: [PATCH 15/42] Update llvm/docs/LangRef.rst Co-authored-by: Nikita Popov --- 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 249a1dd012f5a..baf74d77e9cc5 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?= Date: Mon, 11 Mar 2024 15:27:56 -0600 Subject: [PATCH 16/42] Update llvm/docs/LangRef.rst Co-authored-by: Nikita Popov --- 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 baf74d77e9cc5..d74b54e66bfd5 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?= Date: Mon, 11 Mar 2024 15:28:14 -0600 Subject: [PATCH 17/42] Update llvm/docs/LangRef.rst Co-authored-by: Nikita Popov --- 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 d74b54e66bfd5..7f39864c473a9 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?= Date: Mon, 11 Mar 2024 15:28:38 -0600 Subject: [PATCH 18/42] Update llvm/lib/IR/Verifier.cpp Co-authored-by: Nikita Popov --- 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 73b357b6ad4c9..065d9eff0a549 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?= Date: Mon, 11 Mar 2024 15:29:52 -0600 Subject: [PATCH 19/42] Update llvm/lib/IR/Verifier.cpp Co-authored-by: Nikita Popov --- 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 065d9eff0a549..196d95badffb8 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 Date: Mon, 11 Mar 2024 18:32:19 -0600 Subject: [PATCH 20/42] 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 196d95badffb8..0eaa7f827c6fa 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 Date: Mon, 11 Mar 2024 18:35:37 -0600 Subject: [PATCH 21/42] 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 0eaa7f827c6fa..9fc7c50cdf03a 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(SrcTy)->getElementCount(); + auto destVecLen = cast(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 Date: Mon, 11 Mar 2024 19:23:46 -0600 Subject: [PATCH 22/42] 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 9fc7c50cdf03a..1fe462162a7ad 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(SrcTy)->getElementCount(); auto destVecLen = cast(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 0000000000000..da8903a451a18 --- /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 Date: Mon, 11 Mar 2024 19:26:32 -0600 Subject: [PATCH 23/42] 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 da8903a451a18..a26f302ce5c61 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 Date: Mon, 11 Mar 2024 21:06:08 -0600 Subject: [PATCH 24/42] 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 7f39864c473a9..3f59abdc118ee 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 Date: Mon, 11 Mar 2024 21:07:07 -0600 Subject: [PATCH 25/42] 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 3f59abdc118ee..c485703497fae 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?= Date: Tue, 12 Mar 2024 12:38:15 -0600 Subject: [PATCH 26/42] Update llvm/docs/LangRef.rst Co-authored-by: scottmcm --- 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 c485703497fae..1313d58d53420 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?= Date: Tue, 12 Mar 2024 12:38:24 -0600 Subject: [PATCH 27/42] Update llvm/docs/LangRef.rst Co-authored-by: scottmcm --- 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 1313d58d53420..a65503f77032f 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?= Date: Thu, 14 Mar 2024 09:29:42 -0600 Subject: [PATCH 28/42] Update llvm/docs/LangRef.rst Co-authored-by: Nikita Popov --- 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 a65503f77032f..b62de807dcd95 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?= Date: Thu, 14 Mar 2024 09:29:53 -0600 Subject: [PATCH 29/42] Update llvm/docs/LangRef.rst Co-authored-by: Nikita Popov --- 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 b62de807dcd95..d28f450b1aa42 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?= Date: Thu, 14 Mar 2024 09:42:31 -0600 Subject: [PATCH 30/42] Update llvm/lib/IR/Verifier.cpp Co-authored-by: Nikita Popov --- 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 1fe462162a7ad..76382e902a711 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 Date: Thu, 14 Mar 2024 09:47:01 -0600 Subject: [PATCH 31/42] 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 76382e902a711..d0ea5bb3ed860 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(SrcTy)->getElementCount(); - auto destVecLen = cast(DestTy)->getElementCount(); - Check(srcVecLen == destVecLen, + if (IsDestTypeVector) { + auto SrcVecLen = cast(SrcTy)->getElementCount(); + auto DestVecLen = cast(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 a26f302ce5c61..aaf8be178dc27 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?= Date: Thu, 14 Mar 2024 10:08:13 -0600 Subject: [PATCH 32/42] Update llvm/test/Verifier/intrinsic-cmp.ll Co-authored-by: Nikita Popov --- 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 aaf8be178dc27..c85fed3919fea 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 Date: Thu, 14 Mar 2024 10:14:05 -0600 Subject: [PATCH 33/42] 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 c85fed3919fea..381201b8d6e65 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 Date: Thu, 14 Mar 2024 10:27:20 -0600 Subject: [PATCH 34/42] 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 381201b8d6e65..8fd395b27a8fd 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 Date: Thu, 14 Mar 2024 10:34:56 -0600 Subject: [PATCH 35/42] 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 d0ea5bb3ed860..e47472a30e24e 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(SrcTy)->getElementCount(); auto DestVecLen = cast(DestTy)->getElementCount(); From f09c3e4e4ad25d19d875eabf5192a301ea05395a Mon Sep 17 00:00:00 2001 From: miguelraz Date: Thu, 14 Mar 2024 10:39:57 -0600 Subject: [PATCH 36/42] 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 e47472a30e24e..596f02e67e481 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(SrcTy)->getElementCount(); auto DestVecLen = cast(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 Date: Thu, 14 Mar 2024 10:45:30 -0600 Subject: [PATCH 37/42] 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 596f02e67e481..54f28e208c141 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(SrcTy)->getElementCount(); auto DestVecLen = cast(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 9aaab2cd5580716d3aa469c94717d5790996ef5b Mon Sep 17 00:00:00 2001 From: miguelraz Date: Thu, 14 Mar 2024 10:46:39 -0600 Subject: [PATCH 38/42] 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 54f28e208c141..7eaa229d6a68a 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -5250,7 +5250,10 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) { if (IsDestTypeVector) { auto SrcVecLen = cast(SrcTy)->getElementCount(); auto DestVecLen = cast(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 800599684f10af7094da10c90e78e3e3a0645ab6 Mon Sep 17 00:00:00 2001 From: miguelraz Date: Fri, 15 Mar 2024 08:46:55 -0600 Subject: [PATCH 39/42] 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 8fd395b27a8fd..3b233f69a25c5 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 4caa63ec0a72fdf1e03eecd977795a065ef2f72c Mon Sep 17 00:00:00 2001 From: miguelraz Date: Fri, 15 Mar 2024 10:43:55 -0600 Subject: [PATCH 40/42] 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 7eaa229d6a68a..8aa2e7a9fc994 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -5245,13 +5245,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(SrcTy)->getElementCount(); auto DestVecLen = cast(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 b0918f6e7e1833223fbe114b3b5d978aaafef740 Mon Sep 17 00:00:00 2001 From: miguelraz Date: Fri, 15 Mar 2024 10:46:52 -0600 Subject: [PATCH 41/42] 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 3b233f69a25c5..2224a5c5eba38 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 74c9bb3e311d5c8dc8df61d7653d1b282230a8c9 Mon Sep 17 00:00:00 2001 From: miguelraz Date: Fri, 15 Mar 2024 10:51:31 -0600 Subject: [PATCH 42/42] 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 8aa2e7a9fc994..66a081ecbf210 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -5245,7 +5245,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(SrcTy)->getElementCount();