[llvm] [LVI] Learn value ranges from ctpop results (PR #121945)

Stephen Senran Zhang via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 18:05:06 PST 2025


================
@@ -0,0 +1,138 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=correlated-propagation %s | FileCheck %s
+
+declare void @use(i1)
+
+define void @ctpop1(i8 %v) {
+; CHECK-LABEL: define void @ctpop1(
+; CHECK-SAME: i8 [[V:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[RES:%.*]] = call range(i8 0, 9) i8 @llvm.ctpop.i8(i8 [[V]])
+; CHECK-NEXT:    [[C0_0:%.*]] = icmp samesign uge i8 [[RES]], 3
+; CHECK-NEXT:    [[C0_1:%.*]] = icmp samesign ule i8 [[RES]], 7
+; CHECK-NEXT:    [[C0:%.*]] = and i1 [[C0_0]], [[C0_1]]
+; CHECK-NEXT:    br i1 [[C0]], label %[[RANGE_3_8:.*]], label %[[ED:.*]]
+; CHECK:       [[RANGE_3_8]]:
+; CHECK-NEXT:    call void @use(i1 true)
+; CHECK-NEXT:    call void @use(i1 false)
+; CHECK-NEXT:    call void @use(i1 true)
+; CHECK-NEXT:    call void @use(i1 false)
+; CHECK-NEXT:    ret void
+; CHECK:       [[ED]]:
+; CHECK-NEXT:    ret void
+;
+entry:
+  %res = call range(i8 0, 9) i8 @llvm.ctpop.i8(i8 %v)
+  %c0.0 = icmp uge i8 %res, 3
+  %c0.1 = icmp ule i8 %res, 7
+  %c0 = and i1 %c0.0, %c0.1
+  br i1 %c0, label %range.3.8, label %ed
+
+range.3.8:
+  %cmp0 = icmp uge i8 %v, 7
+  call void @use(i1 %cmp0) ; true
+  %cmp1 = icmp ult i8 %v, 7
+  call void @use(i1 %cmp1) ; false
----------------
zsrkmyn wrote:

Ah you're right. I meant to test its lower bound but made the condition wrong. Fixed. Many thanks!

https://github.com/llvm/llvm-project/pull/121945


More information about the llvm-commits mailing list