[llvm] [SCEV] BECount to zero if `((-C + (C smax %x)) /u %x), C > 0` holds (PR #104580)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 13:22:04 PDT 2024


================
@@ -0,0 +1,52 @@
+; 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
+
+ at g_var = external global i32, align 4
+
+define void @test(i32 %x) {
+; CHECK-LABEL: 'test'
+; CHECK-NEXT:  Classifying expressions for: @test
+; CHECK-NEXT:    %g_var.promoted = load i32, ptr @g_var, align 4
+; CHECK-NEXT:    --> %g_var.promoted U: full-set S: full-set
+; 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:    %iv = phi i32 [ 0, %entry ], [ %iv.next, %for.body ]
+; CHECK-NEXT:    --> {0,+,%x}<nsw><%for.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT:    %val = phi i32 [ %g_var.promoted, %entry ], [ %add.1, %for.body ]
+; CHECK-NEXT:    --> {%g_var.promoted,+,%x}<nsw><%for.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT:    %add.1 = add nsw i32 %val, %x
+; CHECK-NEXT:    --> {(%x + %g_var.promoted),+,%x}<nw><%for.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT:    %iv.next = add nsw i32 %iv, %x
+; CHECK-NEXT:    --> {%x,+,%x}<nsw><%for.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT:  Determining loop execution counts for: @test
+; CHECK-NEXT:  Loop %for.body: Unpredictable backedge-taken count.
+; CHECK-NEXT:  Loop %for.body: Unpredictable constant max backedge-taken count.
+; CHECK-NEXT:  Loop %for.body: Unpredictable symbolic max backedge-taken count.
+;
+entry:
+  %g_var.promoted = load i32, ptr @g_var, align 4
+  %smax = tail call i32 @llvm.smax.i32(i32 %x, i32 1)
+  %add = add nsw i32 %smax, -1
+  %udiv = udiv i32 %add, %x
----------------
antoniofrighetto wrote:

The backedge-count explicitly printed zero when was coupled with LV, but even in that case, not needed.

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


More information about the llvm-commits mailing list