[llvm] [CorrelatedValuePropagation] Fold calls to UCMP/SCMP when we know that ranges of operands do not overlap (PR #97235)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 1 00:50:10 PDT 2024
================
@@ -0,0 +1,118 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=correlated-propagation -S | FileCheck %s
+
+; If nothing is known we can't change anything
+define i8 @ucmp_0(i32 %x, i32 %y) {
+ %1 = call i8 @llvm.ucmp(i32 %x, i32 %y)
+ ret i8 %1
+}
+
+define i8 @scmp_0(i32 %x, i32 %y) {
+ %1 = call i8 @llvm.scmp(i32 %x, i32 %y)
+ ret i8 %1
+}
+
+; If we know that range of LHS < range of RHS then return -1
+define i8 @ucmp_1(i32 %x, i32 %y) {
+ ; X is within [4, 8)
+ %cond1 = icmp uge i32 %x, 4
+ call void @llvm.assume(i1 %cond1)
+ %cond2 = icmp ult i32 %x, 8
+ call void @llvm.assume(i1 %cond2)
+ ; Y is within [8, +INF)
+ %cond3 = icmp uge i32 %y, 8
+ call void @llvm.assume(i1 %cond3)
+
+ %1 = call i8 @llvm.ucmp(i32 %x, i32 %y)
+ ret i8 %1
+}
+
+define i8 @scmp_1(i32 %x, i32 %y) {
+ ; X is within [-5, 3)
+ %cond1 = icmp sge i32 %x, -5
+ call void @llvm.assume(i1 %cond1)
+ %cond2 = icmp slt i32 %x, 3
+ call void @llvm.assume(i1 %cond2)
+ ; Y is within [3, +INF)
----------------
nikic wrote:
```suggestion
; Y is within [3, SIGNED_MAX]
```
I wouldn't use `INF` in this context, which implies floating point numbers.
https://github.com/llvm/llvm-project/pull/97235
More information about the llvm-commits
mailing list