[llvm] ffec315 - [InstSimplify] Provide information about the range of possible values that `ucmp`/`scmp` can return (#96410)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 23 21:01:49 PDT 2024
Author: Poseydon42
Date: 2024-06-24T12:01:46+08:00
New Revision: ffec31566c0acc341a3953ffc9b015f702c138ec
URL: https://github.com/llvm/llvm-project/commit/ffec31566c0acc341a3953ffc9b015f702c138ec
DIFF: https://github.com/llvm/llvm-project/commit/ffec31566c0acc341a3953ffc9b015f702c138ec.diff
LOG: [InstSimplify] Provide information about the range of possible values that `ucmp`/`scmp` can return (#96410)
This makes it possible to fold dumb comparisons like `ucmp(x, y) == 7`.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstSimplify/uscmp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 0df061923f625..777b2792a1ed2 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -9393,6 +9393,10 @@ static ConstantRange getRangeForIntrinsic(const IntrinsicInst &II) {
if (!II.getParent() || !II.getFunction())
break;
return getVScaleRange(II.getFunction(), Width);
+ case Intrinsic::scmp:
+ case Intrinsic::ucmp:
+ return ConstantRange::getNonEmpty(APInt::getAllOnes(Width),
+ APInt(Width, 2));
default:
break;
}
diff --git a/llvm/test/Transforms/InstSimplify/uscmp.ll b/llvm/test/Transforms/InstSimplify/uscmp.ll
index db96aa39192d6..47720060acb52 100644
--- a/llvm/test/Transforms/InstSimplify/uscmp.ll
+++ b/llvm/test/Transforms/InstSimplify/uscmp.ll
@@ -229,6 +229,26 @@ define <4 x i8> @ucmp_with_addition_vec(<4 x i32> %x) {
ret <4 x i8> %2
}
+define i1 @scmp_eq_4(i32 %x, i32 %y) {
+; CHECK-LABEL: define i1 @scmp_eq_4(
+; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
+; CHECK-NEXT: ret i1 false
+;
+ %1 = call i8 @llvm.scmp(i32 %x, i32 %y)
+ %2 = icmp eq i8 %1, 4
+ ret i1 %2
+}
+
+define i1 @ucmp_ne_negative_2(i32 %x, i32 %y) {
+; CHECK-LABEL: define i1 @ucmp_ne_negative_2(
+; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
+; CHECK-NEXT: ret i1 true
+;
+ %1 = call i8 @llvm.ucmp(i32 %x, i32 %y)
+ %2 = icmp ne i8 %1, -2
+ ret i1 %2
+}
+
; Negative case: mismatched signedness of predicates
define i8 @scmp_known_ugt(i32 %x, i32 %y) {
; CHECK-LABEL: define i8 @scmp_known_ugt(
More information about the llvm-commits
mailing list