-
Notifications
You must be signed in to change notification settings - Fork 14.3k
SCEV/test: cover implied-via-addition #123082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
@llvm/pr-subscribers-llvm-analysis Author: Ramkumar Ramachandra (artagnon) ChangesSince 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:
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
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
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.