Skip to content

Commit 026d35b

Browse files
committed
[DA] Add tests where dependencies are missed due to overflow
1 parent 26feb1a commit 026d35b

File tree

5 files changed

+506
-0
lines changed

5 files changed

+506
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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>" 2>&1 | FileCheck %s
3+
; RUN: opt < %s -disable-output "-passes=print<da>" -da-enable-dependence-test=gcd-miv 2>&1 \
4+
; RUN: | FileCheck %s --check-prefix=CHECK-GCD-MIV
5+
6+
; offset0 = 4;
7+
; offset1 = 0;
8+
; for (i = 0; i < 100; i++) {
9+
; A[offset0] = 1;
10+
; A[offset1] = 2;
11+
; offset0 += 3*m;
12+
; offset1 += 3;
13+
; }
14+
;
15+
; FIXME: DependenceAnalysis currently detects no dependency between the two
16+
; stores, but it does exist. E.g., consider `m` is 12297829382473034411, which
17+
; is a modular multiplicative inverse of 3 under modulo 2^64. Then `offset0` is
18+
; effectively `i + 4`, so accesses will be as follows:
19+
;
20+
; - A[offset0] : A[4], A[5], A[6], ...
21+
; - A[offset1] : A[0], A[3], A[6], ...
22+
;
23+
; The root cause is that DA assumes `3*m` begin a multiple of 3 in mathematical
24+
; sense, which isn't necessarily true due to overflow.
25+
;
26+
define void @gcdmiv_coef_ovfl(ptr %A, i64 %m) {
27+
; CHECK-LABEL: 'gcdmiv_coef_ovfl'
28+
; CHECK-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.0, align 1
29+
; CHECK-NEXT: da analyze - none!
30+
; CHECK-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
31+
; CHECK-NEXT: da analyze - none!
32+
; CHECK-NEXT: Src: store i8 2, ptr %gep.1, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
33+
; CHECK-NEXT: da analyze - none!
34+
;
35+
; CHECK-GCD-MIV-LABEL: 'gcdmiv_coef_ovfl'
36+
; CHECK-GCD-MIV-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.0, align 1
37+
; CHECK-GCD-MIV-NEXT: da analyze - consistent output [*]!
38+
; CHECK-GCD-MIV-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
39+
; CHECK-GCD-MIV-NEXT: da analyze - none!
40+
; CHECK-GCD-MIV-NEXT: Src: store i8 2, ptr %gep.1, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
41+
; CHECK-GCD-MIV-NEXT: da analyze - consistent output [*]!
42+
;
43+
entry:
44+
%step = mul i64 3, %m
45+
br label %loop
46+
47+
loop:
48+
%i = phi i64 [ 0, %entry ], [ %i.inc, %loop ]
49+
%offset.0 = phi i64 [ 4, %entry ] , [ %offset.0.next, %loop ]
50+
%offset.1 = phi i64 [ 0, %entry ] , [ %offset.1.next, %loop ]
51+
%gep.0 = getelementptr inbounds i8, ptr %A, i64 %offset.0
52+
%gep.1 = getelementptr inbounds i8, ptr %A, i64 %offset.1
53+
store i8 1, ptr %gep.0
54+
store i8 2, ptr %gep.1
55+
%i.inc = add nuw nsw i64 %i, 1
56+
%offset.0.next = add nsw i64 %offset.0, %step
57+
%offset.1.next = add nsw i64 %offset.1, 3
58+
%ec = icmp eq i64 %i.inc, 100
59+
br i1 %ec, label %exit, label %loop
60+
61+
exit:
62+
ret void
63+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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>" 2>&1 | FileCheck %s
3+
; RUN: opt < %s -disable-output "-passes=print<da>" -da-enable-dependence-test=strong-siv 2>&1 \
4+
; RUN: | FileCheck %s --check-prefix=CHECK-STRONG-SIV
5+
6+
; offset0 = -2;
7+
; offset1 = -4;
8+
; for (i = 0; i < (1LL << 62); i++, offset0 += 2, offset1 += 2) {
9+
; if (0 <= offset0)
10+
; A[offset0] = 1;
11+
; if (0 <= offset1)
12+
; A[offset1] = 2;
13+
; }
14+
;
15+
; FIXME: DependenceAnalysis currently detects no dependency between the two
16+
; stores, but it does exist.
17+
; The root cause is that the product of the BTC and the coefficient triggers an
18+
; overflow.
19+
define void @strongsiv_const_ovfl(ptr %A) {
20+
; CHECK-LABEL: 'strongsiv_const_ovfl'
21+
; CHECK-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.0, align 1
22+
; CHECK-NEXT: da analyze - none!
23+
; CHECK-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
24+
; CHECK-NEXT: da analyze - none!
25+
; CHECK-NEXT: Src: store i8 2, ptr %gep.1, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
26+
; CHECK-NEXT: da analyze - none!
27+
;
28+
; CHECK-STRONG-SIV-LABEL: 'strongsiv_const_ovfl'
29+
; CHECK-STRONG-SIV-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.0, align 1
30+
; CHECK-STRONG-SIV-NEXT: da analyze - none!
31+
; CHECK-STRONG-SIV-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
32+
; CHECK-STRONG-SIV-NEXT: da analyze - none!
33+
; CHECK-STRONG-SIV-NEXT: Src: store i8 2, ptr %gep.1, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
34+
; CHECK-STRONG-SIV-NEXT: da analyze - none!
35+
;
36+
entry:
37+
br label %loop.header
38+
39+
loop.header:
40+
%i = phi i64 [ 0, %entry ], [ %i.inc, %loop.latch ]
41+
%offset.0 = phi i64 [ -2, %entry ], [ %offset.0.next, %loop.latch ]
42+
%offset.1 = phi i64 [ -4, %entry ], [ %offset.1.next, %loop.latch ]
43+
%ec = icmp eq i64 %i, 4611686018427387904
44+
br i1 %ec, label %exit, label %loop.body
45+
46+
loop.body:
47+
%cond.0 = icmp sge i64 %offset.0, 0
48+
%cond.1 = icmp sge i64 %offset.1, 0
49+
br i1 %cond.0, label %if.then.0, label %loop.middle
50+
51+
if.then.0:
52+
%gep.0 = getelementptr inbounds i8, ptr %A, i64 %offset.0
53+
store i8 1, ptr %gep.0
54+
br label %loop.middle
55+
56+
loop.middle:
57+
br i1 %cond.1, label %if.then.1, label %loop.latch
58+
59+
if.then.1:
60+
%gep.1 = getelementptr inbounds i8, ptr %A, i64 %offset.1
61+
store i8 2, ptr %gep.1
62+
br label %loop.latch
63+
64+
loop.latch:
65+
%i.inc = add nuw nsw i64 %i, 1
66+
%offset.0.next = add nsw i64 %offset.0, 2
67+
%offset.1.next = add nsw i64 %offset.1, 2
68+
br label %loop.header
69+
70+
exit:
71+
ret void
72+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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>" 2>&1 | FileCheck %s
3+
; RUN: opt < %s -disable-output "-passes=print<da>" -da-enable-dependence-test=symbolic-rdiv 2>&1 \
4+
; RUN: | FileCheck %s --check-prefix=CHECK-SYMBOLIC-RDIV
5+
6+
; offset = -2;
7+
; for (i = 0; i < (1LL << 62); i++, offset += 2) {
8+
; if (0 <= offset0)
9+
; A[offset0] = 1;
10+
; A[i] = 2;
11+
; }
12+
;
13+
; FIXME: DependenceAnalysis currently detects no dependency between the two
14+
; stores, but it does exist.
15+
; The root cause is that the product of the BTC and the coefficient triggers an
16+
; overflow.
17+
define void @symbolicrdiv_prod_ovfl(ptr %A) {
18+
; CHECK-LABEL: 'symbolicrdiv_prod_ovfl'
19+
; CHECK-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.0, align 1
20+
; CHECK-NEXT: da analyze - none!
21+
; CHECK-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
22+
; CHECK-NEXT: da analyze - none!
23+
; CHECK-NEXT: Src: store i8 2, ptr %gep.1, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
24+
; CHECK-NEXT: da analyze - none!
25+
;
26+
; CHECK-SYMBOLIC-RDIV-LABEL: 'symbolicrdiv_prod_ovfl'
27+
; CHECK-SYMBOLIC-RDIV-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.0, align 1
28+
; CHECK-SYMBOLIC-RDIV-NEXT: da analyze - none!
29+
; CHECK-SYMBOLIC-RDIV-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
30+
; CHECK-SYMBOLIC-RDIV-NEXT: da analyze - none!
31+
; CHECK-SYMBOLIC-RDIV-NEXT: Src: store i8 2, ptr %gep.1, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
32+
; CHECK-SYMBOLIC-RDIV-NEXT: da analyze - consistent output [*]!
33+
;
34+
entry:
35+
br label %loop.header
36+
37+
loop.header:
38+
%i = phi i64 [ 0, %entry ], [ %i.inc, %loop.latch ]
39+
%offset = phi i64 [ -2, %entry ], [ %offset.next, %loop.latch ]
40+
%ec = icmp eq i64 %i, 4611686018427387904
41+
br i1 %ec, label %exit, label %loop.body
42+
43+
loop.body:
44+
%cond = icmp sge i64 %offset, 0
45+
br i1 %cond, label %if.then, label %loop.latch
46+
47+
if.then:
48+
%gep.0 = getelementptr inbounds i8, ptr %A, i64 %offset
49+
store i8 1, ptr %gep.0
50+
br label %loop.latch
51+
52+
loop.latch:
53+
%gep.1 = getelementptr inbounds i8, ptr %A, i64 %i
54+
store i8 2, ptr %gep.1
55+
%i.inc = add nuw nsw i64 %i, 1
56+
%offset.next = add nsw i64 %offset, 2
57+
br label %loop.header
58+
59+
exit:
60+
ret void
61+
}
62+
63+
; offset0 = -4611686018427387904 // -2^62
64+
; offset1 = 4611686018427387904 // 2^62
65+
; for (i = 0; i < (1LL << 62) - 100; i++) {
66+
; if (0 <= offset0)
67+
; A[offset0] = 1;
68+
; if (0 <= offset1)
69+
; A[offset1] = 2;
70+
; offset0 += 2;
71+
; offset1 -= 1;
72+
; }
73+
;
74+
; FIXME: DependenceAnalysis currently detects no dependency between the two
75+
; stores, but it does exist.
76+
; The root cause is that the calculation of the differenct between the two
77+
; constants (-2^62 and 2^62) triggers an overflow.
78+
define void @symbolicrdiv_delta_ovfl(ptr %A) {
79+
; CHECK-LABEL: 'symbolicrdiv_delta_ovfl'
80+
; CHECK-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.0, align 1
81+
; CHECK-NEXT: da analyze - none!
82+
; CHECK-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
83+
; CHECK-NEXT: da analyze - none!
84+
; CHECK-NEXT: Src: store i8 2, ptr %gep.1, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
85+
; CHECK-NEXT: da analyze - none!
86+
;
87+
; CHECK-SYMBOLIC-RDIV-LABEL: 'symbolicrdiv_delta_ovfl'
88+
; CHECK-SYMBOLIC-RDIV-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 1, ptr %gep.0, align 1
89+
; CHECK-SYMBOLIC-RDIV-NEXT: da analyze - consistent output [*]!
90+
; CHECK-SYMBOLIC-RDIV-NEXT: Src: store i8 1, ptr %gep.0, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
91+
; CHECK-SYMBOLIC-RDIV-NEXT: da analyze - none!
92+
; CHECK-SYMBOLIC-RDIV-NEXT: Src: store i8 2, ptr %gep.1, align 1 --> Dst: store i8 2, ptr %gep.1, align 1
93+
; CHECK-SYMBOLIC-RDIV-NEXT: da analyze - consistent output [*]!
94+
;
95+
entry:
96+
br label %loop.header
97+
98+
loop.header:
99+
%i = phi i64 [ 0, %entry ], [ %i.inc, %loop.latch ]
100+
%offset.0 = phi i64 [ -4611686018427387904, %entry ], [ %offset.0.next, %loop.latch ]
101+
%offset.1 = phi i64 [ 4611686018427387904, %entry ], [ %offset.1.next, %loop.latch ]
102+
%cond.0 = icmp sge i64 %offset.0, 0
103+
%cond.1 = icmp sge i64 %offset.1, 0
104+
br i1 %cond.0, label %if.then.0, label %loop.middle
105+
106+
if.then.0:
107+
%gep.0 = getelementptr inbounds i8, ptr %A, i64 %offset.0
108+
store i8 1, ptr %gep.0
109+
br label %loop.middle
110+
111+
loop.middle:
112+
br i1 %cond.1, label %if.then.1, label %loop.latch
113+
114+
if.then.1:
115+
%gep.1 = getelementptr inbounds i8, ptr %A, i64 %offset.1
116+
store i8 2, ptr %gep.1
117+
br label %loop.latch
118+
119+
loop.latch:
120+
%i.inc = add nuw nsw i64 %i, 1
121+
%offset.0.next = add nsw i64 %offset.0, 2
122+
%offset.1.next = sub nsw i64 %offset.1, 1
123+
%ec = icmp eq i64 %i.inc, 4611686018427387804 ; 2^62 - 100
124+
br i1 %ec, label %exit, label %loop.header
125+
126+
exit:
127+
ret void
128+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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>" 2>&1 | FileCheck %s
3+
; RUN: opt < %s -disable-output "-passes=print<da>" -da-enable-dependence-test=weak-crossing-siv 2>&1 \
4+
; RUN: | FileCheck %s --check-prefix=CHECK-WEAK-CROSSING-SIV
5+
6+
; max_i = INT64_MAX/3 // 3074457345618258602
7+
; for (long long i = 0; i <= max_i; i++) {
8+
; A[-3*i + INT64_MAX] = 0;
9+
; if (i)
10+
; A[3*i - 2] = 1;
11+
; }
12+
;
13+
; FIXME: DependencyAnalsysis currently detects no dependency between
14+
; `A[-3*i + INT64_MAX]` and `A[3*i - 2]`, but it does exist. For example,
15+
;
16+
; memory location | -3*i + INT64_MAX | 3*i - 2
17+
; ------------------|------------------|-----------
18+
; A[1] | i = max_i | i = 1
19+
; A[INT64_MAX - 3] | i = 1 | i = max_i
20+
;
21+
; The root cause is that the calculation of the differenct between the two
22+
; constants (INT64_MAX and -2) triggers an overflow.
23+
24+
define void @weakcorssing_delta_ovfl(ptr %A) {
25+
; CHECK-LABEL: 'weakcorssing_delta_ovfl'
26+
; CHECK-NEXT: Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 0, ptr %idx.0, align 1
27+
; CHECK-NEXT: da analyze - none!
28+
; CHECK-NEXT: Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
29+
; CHECK-NEXT: da analyze - none!
30+
; CHECK-NEXT: Src: store i8 1, ptr %idx.1, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
31+
; CHECK-NEXT: da analyze - none!
32+
;
33+
; CHECK-WEAK-CROSSING-SIV-LABEL: 'weakcorssing_delta_ovfl'
34+
; CHECK-WEAK-CROSSING-SIV-NEXT: Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 0, ptr %idx.0, align 1
35+
; CHECK-WEAK-CROSSING-SIV-NEXT: da analyze - consistent output [*]!
36+
; CHECK-WEAK-CROSSING-SIV-NEXT: Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
37+
; CHECK-WEAK-CROSSING-SIV-NEXT: da analyze - none!
38+
; CHECK-WEAK-CROSSING-SIV-NEXT: Src: store i8 1, ptr %idx.1, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
39+
; CHECK-WEAK-CROSSING-SIV-NEXT: da analyze - consistent output [*]!
40+
;
41+
entry:
42+
br label %loop.header
43+
44+
loop.header:
45+
%i = phi i64 [ 0, %entry ], [ %i.inc, %loop.latch ]
46+
%subscript.0 = phi i64 [ 9223372036854775807, %entry ], [ %subscript.0.next, %loop.latch ]
47+
%subscript.1 = phi i64 [ -2, %entry ], [ %subscript.1.next, %loop.latch ]
48+
%idx.0 = getelementptr inbounds i8, ptr %A, i64 %subscript.0
49+
store i8 0, ptr %idx.0
50+
%cond.store = icmp ne i64 %i, 0
51+
br i1 %cond.store, label %if.store, label %loop.latch
52+
53+
if.store:
54+
%idx.1 = getelementptr inbounds i8, ptr %A, i64 %subscript.1
55+
store i8 1, ptr %idx.1
56+
br label %loop.latch
57+
58+
loop.latch:
59+
%i.inc = add nuw nsw i64 %i, 1
60+
%subscript.0.next = add nsw i64 %subscript.0, -3
61+
%subscript.1.next = add nsw i64 %subscript.1, 3
62+
%ec = icmp sgt i64 %i.inc, 3074457345618258602
63+
br i1 %ec, label %exit, label %loop.header
64+
65+
exit:
66+
ret void
67+
}
68+
69+
; max_i = INT64_MAX/3 // 3074457345618258602
70+
; for (long long i = 0; i <= max_i; i++) {
71+
; A[-3*i + INT64_MAX] = 0;
72+
; A[3*i + 1] = 1;
73+
; }
74+
;
75+
; FIXME: DependencyAnalsysis currently detects no dependency between
76+
; `A[-3*i + INT64_MAX]` and `A[3*i - 2]`, but it does exist. For example,
77+
;
78+
; memory location | -3*i + INT64_MAX | 3*i + 1
79+
; ------------------|------------------|--------------
80+
; A[1] | i = max_i | i = 0
81+
; A[INT64_MAX - 3] | i = 1 | i = max_i - 1
82+
;
83+
; The root cause is that the product of the BTC, the coefficient, and 2
84+
; triggers an overflow.
85+
;
86+
define void @weakcorssing_prod_ovfl(ptr %A) {
87+
; CHECK-LABEL: 'weakcorssing_prod_ovfl'
88+
; CHECK-NEXT: Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 0, ptr %idx.0, align 1
89+
; CHECK-NEXT: da analyze - none!
90+
; CHECK-NEXT: Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
91+
; CHECK-NEXT: da analyze - none!
92+
; CHECK-NEXT: Src: store i8 1, ptr %idx.1, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
93+
; CHECK-NEXT: da analyze - none!
94+
;
95+
; CHECK-WEAK-CROSSING-SIV-LABEL: 'weakcorssing_prod_ovfl'
96+
; CHECK-WEAK-CROSSING-SIV-NEXT: Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 0, ptr %idx.0, align 1
97+
; CHECK-WEAK-CROSSING-SIV-NEXT: da analyze - consistent output [*]!
98+
; CHECK-WEAK-CROSSING-SIV-NEXT: Src: store i8 0, ptr %idx.0, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
99+
; CHECK-WEAK-CROSSING-SIV-NEXT: da analyze - none!
100+
; CHECK-WEAK-CROSSING-SIV-NEXT: Src: store i8 1, ptr %idx.1, align 1 --> Dst: store i8 1, ptr %idx.1, align 1
101+
; CHECK-WEAK-CROSSING-SIV-NEXT: da analyze - consistent output [*]!
102+
;
103+
entry:
104+
br label %loop
105+
106+
loop:
107+
%i = phi i64 [ 0, %entry ], [ %i.inc, %loop ]
108+
%subscript.0 = phi i64 [ 9223372036854775807, %entry ], [ %subscript.0.next, %loop ]
109+
%subscript.1 = phi i64 [ 1, %entry ], [ %subscript.1.next, %loop ]
110+
%idx.0 = getelementptr inbounds i8, ptr %A, i64 %subscript.0
111+
%idx.1 = getelementptr inbounds i8, ptr %A, i64 %subscript.1
112+
store i8 0, ptr %idx.0
113+
store i8 1, ptr %idx.1
114+
%i.inc = add nuw nsw i64 %i, 1
115+
%subscript.0.next = add nsw i64 %subscript.0, -3
116+
%subscript.1.next = add nsw i64 %subscript.1, 3
117+
%ec = icmp sgt i64 %i.inc, 3074457345618258602
118+
br i1 %ec, label %exit, label %loop
119+
120+
exit:
121+
ret void
122+
}

0 commit comments

Comments
 (0)