[llvm] SCEV: cover a codepath in isImpliedCondBalancedTypes (PR #123070)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 15 07:39:14 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Ramkumar Ramachandra (artagnon)
<details>
<summary>Changes</summary>
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
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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/123070
More information about the llvm-commits
mailing list