Skip to content

SCEV: cover a codepath in isImpliedCondBalancedTypes #123070

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

Merged
merged 4 commits into from
Jan 23, 2025

Conversation

artagnon
Copy link
Contributor

@artagnon artagnon commented Jan 15, 2025

The code that checks a predicate against a swapped predicate in isImpliedCondBalancedTypes is not covered by any existing test, within any Analysis or Transform. Fix this by adding a test to SCEV.

The code that checks a predicate against a swapped predicate in
isImpliedCondBalancedTypes is not covered by any existing test, within
any Analysis or Transform. Fix this by adding a test to SCEV.
@llvmbot
Copy link
Member

llvmbot commented Jan 15, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Ramkumar Ramachandra (artagnon)

Changes

The code that checks a predicate against a swapped predicate in isImpliedCondBalancedTypes is not covered by any existing test, within any Analysis or Transform. Fix this by adding a test to SCEV.

-- 8< --
See both commits individually for proof.


Full diff: https://github.com/llvm/llvm-project/pull/123070.diff

1 Files Affected:

  • (modified) llvm/test/Analysis/ScalarEvolution/implied-via-division.ll (+53)
diff --git a/llvm/test/Analysis/ScalarEvolution/implied-via-division.ll b/llvm/test/Analysis/ScalarEvolution/implied-via-division.ll
index fbe69b4b188977..3fd59299ed81c9 100644
--- a/llvm/test/Analysis/ScalarEvolution/implied-via-division.ll
+++ b/llvm/test/Analysis/ScalarEvolution/implied-via-division.ll
@@ -411,3 +411,56 @@ header:
 exit:
   ret void
 }
+
+define void @swapped_predicate(i32 %n) nounwind {
+; Prove that (n >= 1) ===> (0 >= -n / 2).
+; CHECK-LABEL: 'swapped_predicate'
+; CHECK-NEXT:  Determining loop execution counts for: @swapped_predicate
+; CHECK-NEXT:  Loop %header: backedge-taken count is (1 + %n.div.2)<nsw>
+; CHECK-NEXT:  Loop %header: constant max backedge-taken count is i32 1073741824
+; CHECK-NEXT:  Loop %header: symbolic max backedge-taken count is (1 + %n.div.2)<nsw>
+; CHECK-NEXT:  Loop %header: Trip multiple is 1
+;
+entry:
+  %cmp1 = icmp sge i32 %n, 1
+  %n.div.2 = sdiv i32 %n, 2
+  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
+  %minus.indvar = sub nsw i32 0, %indvar
+  %minus.n.div.2 = sub nsw i32 0, %n.div.2
+  %exitcond = icmp sge i32 %minus.indvar, %minus.n.div.2
+  br i1 %exitcond, label %header, label %exit
+
+exit:
+  ret void
+}
+
+define void @swapped_predicate_neg(i32 %n) nounwind {
+; Prove that (n >= 1) =\=> (-n / 2 >= 0).
+; CHECK-LABEL: 'swapped_predicate_neg'
+; CHECK-NEXT:  Determining loop execution counts for: @swapped_predicate_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.
+;
+entry:
+  %cmp1 = icmp sge i32 %n, 1
+  %n.div.2 = sdiv i32 %n, 2
+  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
+  %minus.indvar = sub nsw i32 0, %indvar
+  %minus.n.div.2 = sub nsw i32 0, %n.div.2
+  %exitcond = icmp sge i32 %minus.n.div.2, %minus.indvar
+  br i1 %exitcond, label %header, label %exit
+
+exit:
+  ret void
+}

@artagnon
Copy link
Contributor Author

Gentle ping.

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@artagnon artagnon merged commit e069518 into llvm:main Jan 23, 2025
8 checks passed
@artagnon artagnon deleted the scev-implied-swap-test branch January 23, 2025 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants