[llvm] [SCEV] BECount to zero if `((-C + (C smax %x)) /u %x), C > 0` holds (PR #104580)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 02:40:50 PDT 2024
================
@@ -0,0 +1,96 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; RUN: opt -disable-output -passes="print<scalar-evolution>" < %s 2>&1 | FileCheck %s
+
+define i32 @test(i32 %x) {
+; CHECK-LABEL: 'test'
+; CHECK-NEXT: Classifying expressions for: @test
+; CHECK-NEXT: %smax = tail call i32 @llvm.smax.i32(i32 %x, i32 1)
+; CHECK-NEXT: --> (1 smax %x) U: [1,-2147483648) S: [1,-2147483648)
+; CHECK-NEXT: %add = add nsw i32 %smax, -1
+; CHECK-NEXT: --> (-1 + (1 smax %x))<nsw> U: [0,2147483647) S: [0,2147483647)
+; CHECK-NEXT: %udiv = udiv i32 %add, %x
+; CHECK-NEXT: --> 0 U: [0,1) S: [0,1)
+; CHECK-NEXT: Determining loop execution counts for: @test
+;
+entry:
+ %smax = tail call i32 @llvm.smax.i32(i32 %x, i32 1)
+ %add = add nsw i32 %smax, -1
+ %udiv = udiv i32 %add, %x
+ ret i32 %udiv
+}
+
+; Non-1 constant: (-2 + (2 smax %x)) /u %x
+define i32 @test1(i32 %x) {
+; CHECK-LABEL: 'test1'
+; CHECK-NEXT: Classifying expressions for: @test1
+; CHECK-NEXT: %smax = tail call i32 @llvm.smax.i32(i32 %x, i32 2)
+; CHECK-NEXT: --> (2 smax %x) U: [2,-2147483648) S: [2,-2147483648)
+; CHECK-NEXT: %add = add nsw i32 %smax, -2
+; CHECK-NEXT: --> (-2 + (2 smax %x))<nsw> U: [0,2147483646) S: [0,2147483646)
+; CHECK-NEXT: %udiv = udiv i32 %add, %x
+; CHECK-NEXT: --> 0 U: [0,1) S: [0,1)
+; CHECK-NEXT: Determining loop execution counts for: @test1
+;
+entry:
+ %smax = tail call i32 @llvm.smax.i32(i32 %x, i32 2)
+ %add = add nsw i32 %smax, -2
+ %udiv = udiv i32 %add, %x
+ ret i32 %udiv
+}
+
+; Negative test, constants mismatch: (-3 + (2 smax %x)) /u %x
+define i32 @test2(i32 %x) {
----------------
nikic wrote:
```suggestion
define i32 @test_constant_mismatch(i32 %x) {
```
etc. try to give more meaningful names.
https://github.com/llvm/llvm-project/pull/104580
More information about the llvm-commits
mailing list