Skip to content

Commit 778a7dd

Browse files
mrdaybirdhiraditya
authored andcommitted
Add tests
1 parent 1b4945b commit 778a7dd

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13003,7 +13003,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
1300313003
const SCEV *End = nullptr, *BECount = nullptr,
1300413004
*BECountIfBackedgeTaken = nullptr;
1300513005
if (!isLoopInvariant(RHS, L)) {
13006-
if (auto RHSAddRec = dyn_cast<SCEVAddRecExpr>(RHS)) {
13006+
if (const auto *RHSAddRec = dyn_cast<SCEVAddRecExpr>(RHS)) {
1300713007
/*
1300813008
The structure of loop we are trying to calculate backedge-count of:
1300913009
left = left_start
@@ -13026,7 +13026,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
1302613026
// check if RHSStride<0 and Stride-RHSStride will not overflow
1302713027
// FIXME: Can RHSStride be positive?
1302813028
if (isKnownNegative(RHSStride) &&
13029-
willNotOverflow(llvm::Instruction::Sub, true, Stride, RHSStride)) {
13029+
willNotOverflow(Instruction::Sub, /*Signed=*/true, Stride, RHSStride)) {
1303013030

1303113031
const SCEV *Denominator = getMinusSCEV(Stride, RHSStride);
1303213032
if (isKnownPositive(Denominator)) {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
3+
4+
define dso_local void @simple(i32 noundef %n) local_unnamed_addr {
5+
; CHECK-LABEL: 'simple'
6+
; CHECK-NEXT: Classifying expressions for: @simple
7+
; CHECK-NEXT: %right.06 = phi i32 [ %dec, %while.body ], [ %n, %entry ]
8+
; CHECK-NEXT: --> {%n,+,-4}<nsw><%while.body> U: full-set S: full-set Exits: ((-4 * (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>)))<nsw> + %n) LoopDispositions: { %while.body: Computable }
9+
; CHECK-NEXT: %left.05 = phi i32 [ %inc, %while.body ], [ 0, %entry ]
10+
; CHECK-NEXT: --> {0,+,4}<nuw><nsw><%while.body> U: [0,2147483641) S: [0,2147483641) Exits: (4 * (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>)))<nuw> LoopDispositions: { %while.body: Computable }
11+
; CHECK-NEXT: %inc = add nuw nsw i32 %left.05, 4
12+
; CHECK-NEXT: --> {4,+,4}<nuw><nsw><%while.body> U: [4,2147483645) S: [4,2147483645) Exits: (4 + (4 * (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>)))<nuw>)<nuw> LoopDispositions: { %while.body: Computable }
13+
; CHECK-NEXT: %dec = add nsw i32 %right.06, -4
14+
; CHECK-NEXT: --> {(-4 + %n),+,-4}<nsw><%while.body> U: full-set S: full-set Exits: (-4 + (-4 * (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>)))<nsw> + %n) LoopDispositions: { %while.body: Computable }
15+
; CHECK-NEXT: Determining loop execution counts for: @simple
16+
; CHECK-NEXT: Loop %while.body: backedge-taken count is (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))
17+
; CHECK-NEXT: Loop %while.body: constant max backedge-taken count is i32 536870910
18+
; CHECK-NEXT: Loop %while.body: symbolic max backedge-taken count is (((-4 + (-1 * (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))<nuw><nsw> + (4 smax (-4 + %n))) /u 8) + (1 umin (-4 + (4 smax (-4 + %n)))<nsw>))
19+
; CHECK-NEXT: Loop %while.body: Trip multiple is 1
20+
;
21+
entry:
22+
%cmp4 = icmp sgt i32 %n, 0
23+
br i1 %cmp4, label %while.body, label %while.end
24+
25+
while.body:
26+
%right.06 = phi i32 [ %dec, %while.body ], [ %n, %entry ]
27+
%left.05 = phi i32 [ %inc, %while.body ], [ 0, %entry ]
28+
%inc = add nuw nsw i32 %left.05, 4
29+
%dec = add nsw i32 %right.06, -4
30+
%cmp = icmp slt i32 %inc, %dec
31+
br i1 %cmp, label %while.body, label %while.end
32+
33+
while.end:
34+
ret void
35+
}
36+
37+
define dso_local void @overflow(i32 noundef %n) local_unnamed_addr {
38+
; CHECK-LABEL: 'overflow'
39+
; CHECK-NEXT: Classifying expressions for: @overflow
40+
; CHECK-NEXT: %right.06 = phi i32 [ %dec, %while.body ], [ %n, %entry ]
41+
; CHECK-NEXT: --> {%n,+,-1}<nsw><%while.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %while.body: Computable }
42+
; CHECK-NEXT: %left.05 = phi i32 [ %inc, %while.body ], [ 2147483647, %entry ]
43+
; CHECK-NEXT: --> {2147483647,+,2147483647}<nuw><nsw><%while.body> U: [2147483647,-2147483648) S: [2147483647,-2147483648) Exits: <<Unknown>> LoopDispositions: { %while.body: Computable }
44+
; CHECK-NEXT: %inc = add nuw nsw i32 %left.05, 2147483647
45+
; CHECK-NEXT: --> {-2,+,2147483647}<nuw><nsw><%while.body> U: [-2,-1) S: [-2,0) Exits: <<Unknown>> LoopDispositions: { %while.body: Computable }
46+
; CHECK-NEXT: %dec = add nsw i32 %right.06, -1
47+
; CHECK-NEXT: --> {(-1 + %n),+,-1}<nsw><%while.body> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %while.body: Computable }
48+
; CHECK-NEXT: Determining loop execution counts for: @overflow
49+
; CHECK-NEXT: Loop %while.body: Unpredictable backedge-taken count.
50+
; CHECK-NEXT: Loop %while.body: constant max backedge-taken count is i32 1
51+
; CHECK-NEXT: Loop %while.body: symbolic max backedge-taken count is i32 1
52+
;
53+
entry:
54+
%cmp4 = icmp sgt i32 %n, 0
55+
br i1 %cmp4, label %while.body, label %while.end
56+
57+
while.body:
58+
%right.06 = phi i32 [ %dec, %while.body ], [ %n, %entry ]
59+
%left.05 = phi i32 [ %inc, %while.body ], [ 2147483647, %entry ]
60+
%inc = add nuw nsw i32 %left.05, 2147483647
61+
%dec = add nsw i32 %right.06, -1
62+
%cmp = icmp slt i32 %inc, %dec
63+
br i1 %cmp, label %while.body, label %while.end
64+
65+
while.end:
66+
ret void
67+
}
68+
69+

0 commit comments

Comments
 (0)