Skip to content

Commit da8859c

Browse files
committed
add more tests
1 parent 9c29421 commit da8859c

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

llvm/test/Analysis/DependenceAnalysis/monotonicity-cast.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,36 @@ loop:
172172
exit:
173173
ret void
174174
}
175+
176+
; SCEV handles `i & 1` as an i1 addrec. Ensure that the monotonicity analysis
177+
; properly analyzes it.
178+
;
179+
; for (i = 0; i < 100; i++)
180+
; a[i & 1] = 0;
181+
;
182+
define void @offset_truncated_to_i1(ptr %a) {
183+
; CHECK-LABEL: 'offset_truncated_to_i1'
184+
; CHECK-NEXT: Monotonicity check:
185+
; CHECK-NEXT: Inst: store i8 0, ptr %idx, align 1
186+
; CHECK-NEXT: Expr: (zext i1 {false,+,true}<%loop> to i64)
187+
; CHECK-NEXT: Monotonicity: Unknown
188+
; CHECK-NEXT: Reason: (zext i1 {false,+,true}<%loop> to i64)
189+
; CHECK-EMPTY:
190+
; CHECK-NEXT: Src: store i8 0, ptr %idx, align 1 --> Dst: store i8 0, ptr %idx, align 1
191+
; CHECK-NEXT: da analyze - confused!
192+
;
193+
entry:
194+
br label %loop
195+
196+
loop:
197+
%i = phi i64 [ 0, %entry ], [ %i.inc, %loop ]
198+
%and = and i64 %i, 1
199+
%idx = getelementptr inbounds i8, ptr %a, i64 %and
200+
store i8 0, ptr %idx
201+
%i.inc = add nsw i64 %i, 1
202+
%exitcond = icmp eq i64 %i.inc, 100
203+
br i1 %exitcond, label %exit, label %loop
204+
205+
exit:
206+
ret void
207+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
2+
; RUN: opt < %s -disable-output -passes="print<da>" -da-dump-monotonicity-report \
3+
; RUN: -da-enable-monotonicity-check 2>&1 | FileCheck %s
4+
5+
; The offset SCEV will be delinearized into a 2D array access, like as follows:
6+
;
7+
; - Outer subscript: {0,+,1}<nuw><nsw><%loop.i.header>
8+
; - Inner subscript: {0,+,1}<nuw><nsw><%loop.j.header>
9+
;
10+
; These subscripts are both monotonic, but we also need to check the
11+
; monotonicity of the original addrec.
12+
;
13+
; char A[...][32];
14+
; for (i = 0; i < 1ll << 62; i++)
15+
; for (j = 0; j < 32; j++)
16+
; if (i < (1ll << 57))
17+
; A[i][j] = 0;
18+
;
19+
define void @linearized_offset_wrap(ptr %a) {
20+
; CHECK-LABEL: 'linearized_offset_wrap'
21+
; CHECK-NEXT: Monotonicity check:
22+
; CHECK-NEXT: Inst: store i8 0, ptr %gep, align 1
23+
; CHECK-NEXT: Expr: {{\{\{}}0,+,32}<%loop.i.header>,+,1}<nw><%loop.j.header>
24+
; CHECK-NEXT: Monotonicity: Unknown
25+
; CHECK-NEXT: Reason: {{\{\{}}0,+,32}<%loop.i.header>,+,1}<nw><%loop.j.header>
26+
; CHECK-EMPTY:
27+
; CHECK-NEXT: Src: store i8 0, ptr %gep, align 1 --> Dst: store i8 0, ptr %gep, align 1
28+
; CHECK-NEXT: da analyze - confused!
29+
;
30+
entry:
31+
br label %loop.i.header
32+
33+
loop.i.header:
34+
%i = phi i64 [ 0, %entry ], [ %i.inc, %loop.i.latch ]
35+
br label %loop.j.header
36+
37+
loop.j.header:
38+
%j = phi i64 [ 0, %loop.i.header ], [ %j.inc, %loop.j.latch ]
39+
%cond = icmp slt i64 %i, 144115188075855872 ; 2^57
40+
br i1 %cond, label %if.then, label %loop.j.latch
41+
42+
if.then:
43+
%gep = getelementptr inbounds [32 x i8], ptr %a, i64 %i, i64 %j
44+
store i8 0, ptr %gep
45+
br label %loop.j.latch
46+
47+
loop.j.latch:
48+
%j.inc = add nuw nsw i64 %j, 1
49+
%ec.j = icmp eq i64 %j.inc, 32
50+
br i1 %ec.j, label %loop.i.latch, label %loop.j.header
51+
52+
loop.i.latch:
53+
%i.inc = add nuw nsw i64 %i, 1
54+
%ec.i = icmp eq i64 %i.inc, 4611686018427387904 ; 2^62
55+
br i1 %ec.i, label %exit, label %loop.i.header
56+
57+
exit:
58+
ret void
59+
}

0 commit comments

Comments
 (0)