[llvm] SCEV/test: cover implied-via-addition (PR #123082)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 15 08:28:42 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Ramkumar Ramachandra (artagnon)
<details>
<summary>Changes</summary>
Since cf2e828 (SCEV: regen some tests with UTC) had the side-effect of moving an implied-via-addition test into IndVarSimplify, implication via addition is no longer covered in the SCEV tests. Fix this by writing fresh tests and checking backedge-taken output from SCEV.
---
Full diff: https://github.com/llvm/llvm-project/pull/123082.diff
1 Files Affected:
- (added) llvm/test/Analysis/ScalarEvolution/implied-via-addition.ll (+111)
``````````diff
diff --git a/llvm/test/Analysis/ScalarEvolution/implied-via-addition.ll b/llvm/test/Analysis/ScalarEvolution/implied-via-addition.ll
new file mode 100644
index 00000000000000..cd349e34b679b9
--- /dev/null
+++ b/llvm/test/Analysis/ScalarEvolution/implied-via-addition.ll
@@ -0,0 +1,111 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -disable-output -passes="print<scalar-evolution>" \
+; RUN: -scalar-evolution-classify-expressions=0 2>&1 | FileCheck %s
+
+define void @implied1(i32 %n) {
+; Prove that (n > 1) ===> (n - 1 > 0).
+; CHECK-LABEL: 'implied1'
+; CHECK-NEXT: Determining loop execution counts for: @implied1
+; CHECK-NEXT: Loop %header: backedge-taken count is (-2 + %n)
+; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 2147483646
+; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (-2 + %n)
+; CHECK-NEXT: Loop %header: Trip multiple is 1
+;
+entry:
+ %cmp1 = icmp sgt i32 %n, 1
+ %n.minus.1 = sub nsw i32 %n, 1
+ call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
+ br label %header
+
+header:
+ %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
+ %indvar.next = add i32 %indvar, 1
+ %exitcond = icmp sgt i32 %n.minus.1, %indvar.next
+ br i1 %exitcond, label %header, label %exit
+
+exit:
+ ret void
+}
+
+define void @implied1_neg(i32 %n) {
+; Prove that (n > 0) =\=> (n - 1 > 0).
+; CHECK-LABEL: 'implied1_neg'
+; CHECK-NEXT: Determining loop execution counts for: @implied1_neg
+; CHECK-NEXT: Loop %header: backedge-taken count is (-1 + (1 smax (-1 + %n)))<nsw>
+; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 2147483646
+; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (-1 + (1 smax (-1 + %n)))<nsw>
+; CHECK-NEXT: Loop %header: Trip multiple is 1
+;
+entry:
+ %cmp1 = icmp sgt i32 %n, 0
+ %n.minus.1 = sub nsw i32 %n, 1
+ call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
+ br label %header
+
+header:
+ %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
+ %indvar.next = add i32 %indvar, 1
+ %exitcond = icmp sgt i32 %n.minus.1, %indvar.next
+ br i1 %exitcond, label %header, label %exit
+
+exit:
+ ret void
+}
+
+define void @implied2(i32 %n) {
+; Prove that (n >= -1) ===> (n + 1 >= 0).
+; CHECK-LABEL: 'implied2'
+; CHECK-NEXT: Determining loop execution counts for: @implied2
+; CHECK-NEXT: Loop %header: backedge-taken count is (zext i32 (1 + %n) to i64)
+; CHECK-NEXT: Loop %header: constant max backedge-taken count is i64 4294967295
+; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is (zext i32 (1 + %n) to i64)
+; CHECK-NEXT: Loop %header: Trip multiple is 1
+;
+entry:
+ %cmp1 = icmp uge i32 %n, -1
+ %n.1 = add nuw i32 %n, 1
+ call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
+ br label %header
+
+header:
+ %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
+ %indvar.next = add i32 %indvar, 1
+ %exitcond = icmp uge i32 %n.1, %indvar.next
+ br i1 %exitcond, label %header, label %exit
+
+exit:
+ ret void
+}
+
+define void @implied2_neg(i32 %n) {
+; Prove that (n >= -1) =\=> (n - 1 >= 0).
+; CHECK-LABEL: 'implied2_neg'
+; CHECK-NEXT: Determining loop execution counts for: @implied2_neg
+; CHECK-NEXT: Loop %header: Unpredictable backedge-taken count.
+; CHECK-NEXT: Loop %header: Unpredictable constant max backedge-taken count.
+; CHECK-NEXT: Loop %header: Unpredictable symbolic max backedge-taken count.
+; CHECK-NEXT: Loop %header: Predicated backedge-taken count is (-1 + (1 smax (1 + (sext i32 (-1 + %n) to i64))<nsw>))<nsw>
+; CHECK-NEXT: Predicates:
+; CHECK-NEXT: {1,+,1}<%header> Added Flags: <nssw>
+; CHECK-NEXT: Loop %header: Predicated constant max backedge-taken count is i64 2147483647
+; CHECK-NEXT: Predicates:
+; CHECK-NEXT: {1,+,1}<%header> Added Flags: <nssw>
+; CHECK-NEXT: Loop %header: Predicated symbolic max backedge-taken count is (-1 + (1 smax (1 + (sext i32 (-1 + %n) to i64))<nsw>))<nsw>
+; CHECK-NEXT: Predicates:
+; CHECK-NEXT: {1,+,1}<%header> Added Flags: <nssw>
+;
+entry:
+ %cmp1 = icmp uge i32 %n, -1
+ %n.minus.1 = sub nuw nsw i32 %n, 1
+ call void(i1, ...) @llvm.experimental.guard(i1 %cmp1) [ "deopt"() ]
+ br label %header
+
+header:
+ %indvar = phi i32 [ %indvar.next, %header ], [ 0, %entry ]
+ %indvar.next = add i32 %indvar, 1
+ %exitcond = icmp sge i32 %n.minus.1, %indvar.next
+ br i1 %exitcond, label %header, label %exit
+
+exit:
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/123082
More information about the llvm-commits
mailing list