Skip to content

Commit d088dbe

Browse files
committed
add another test
1 parent 9bfa9d5 commit d088dbe

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
; RUN: opt < %s -disable-output -passes="print<da>" 2>&1 | FileCheck %s -check-prefix=DISABLE-CHECK
5+
6+
;
7+
; for (i = 0; i < (1ULL << 60); i++) {
8+
; A[i] = 1;
9+
;
10+
; unsigned long long offset = i * 32 + (1ULL << 62);
11+
; // offset is positive when interpreted as a signed value.
12+
; // To prevent violating the size limitation for an allocated object.
13+
; if (offset < (1ULL << 63))
14+
; A[offset] = 2;
15+
; }
16+
;
17+
; -----------------------------------------------------------------------------
18+
;
19+
; There is a dependency between the two stores. To detect it, we need to check
20+
; the monotonicity and bail out the analysis since `offset` is not monotonic.
21+
;
22+
; memory location | first store (A[i]) | second store (A[offset])
23+
; ------------------|--------------------|----------------------------
24+
; A[0] | i = 0 | i = 2^59 - 2^57
25+
; A[2^60 - 32] | i = 2^60 - 32 | i = 2^59 - 2^57 + 2^55 - 1
26+
;
27+
define void @f(ptr %A) {
28+
; CHECK-LABEL: 'f'
29+
; CHECK-NEXT: Monotonicity check:
30+
; CHECK-NEXT: Inst: store i8 1, ptr %idx.0, align 1
31+
; CHECK-NEXT: Expr: {0,+,1}<nuw><nsw><%loop.header>
32+
; CHECK-NEXT: Monotonicity: MultiSignedMonotonic
33+
; CHECK-NEXT: Inst: store i8 2, ptr %idx.1, align 1
34+
; CHECK-NEXT: Expr: {4611686018427387904,+,32}<%loop.header>
35+
; CHECK-NEXT: Monotonicity: Unknown
36+
; CHECK-NEXT: Reason: {4611686018427387904,+,32}<%loop.header>
37+
; CHECK-EMPTY:
38+
; CHECK-NEXT: Src: store i8 1, ptr %idx.0, align 1 --> Dst: store i8 1, ptr %idx.0, align 1
39+
; CHECK-NEXT: da analyze - none!
40+
; CHECK-NEXT: Src: store i8 1, ptr %idx.0, align 1 --> Dst: store i8 2, ptr %idx.1, align 1
41+
; CHECK-NEXT: da analyze - confused!
42+
; CHECK-NEXT: Src: store i8 2, ptr %idx.1, align 1 --> Dst: store i8 2, ptr %idx.1, align 1
43+
; CHECK-NEXT: da analyze - confused!
44+
;
45+
; DISABLE-CHECK-LABEL: 'f'
46+
; DISABLE-CHECK-NEXT: Src: store i8 1, ptr %idx.0, align 1 --> Dst: store i8 1, ptr %idx.0, align 1
47+
; DISABLE-CHECK-NEXT: da analyze - none!
48+
; DISABLE-CHECK-NEXT: Src: store i8 1, ptr %idx.0, align 1 --> Dst: store i8 2, ptr %idx.1, align 1
49+
; DISABLE-CHECK-NEXT: da analyze - none!
50+
; DISABLE-CHECK-NEXT: Src: store i8 2, ptr %idx.1, align 1 --> Dst: store i8 2, ptr %idx.1, align 1
51+
; DISABLE-CHECK-NEXT: da analyze - none!
52+
;
53+
entry:
54+
br label %loop.header
55+
56+
loop.header:
57+
%i = phi i64 [ 0, %entry ], [ %i.next, %loop.latch ]
58+
%idx.0 = getelementptr inbounds i8, ptr %A, i64 %i
59+
store i8 1, ptr %idx.0
60+
%offset.tmp = mul i64 %i, 32
61+
%offset = add i64 %offset.tmp, 4611686018427387904 ; 1ULL << 62
62+
%if.cond = icmp sge i64 %offset, 0
63+
br i1 %if.cond, label %if.then, label %loop.latch
64+
65+
if.then:
66+
%idx.1 = getelementptr inbounds i8, ptr %A, i64 %offset
67+
store i8 2, ptr %idx.1
68+
br label %loop.latch
69+
70+
loop.latch:
71+
%i.next = add nuw nsw i64 %i, 1
72+
%exit.cond = icmp eq i64 %i.next, 1152921504606846976 ; 1ULL << 60
73+
br i1 %exit.cond, label %exit, label %loop.header
74+
75+
exit:
76+
ret void
77+
}

0 commit comments

Comments
 (0)