blob: fe074a63ee10d6225174b799ee728f8161815dc6 [file] [log] [blame]
Andrey Turetskiy9f02c582016-06-07 14:55:27 +00001; RUN: opt -loop-accesses -analyze -S < %s | FileCheck %s
2
3; This is the test case from PR26314.
4; When we were retrying dependence checking with memchecks only,
5; the loop-invariant access in the inner loop was incorrectly determined to be wrapping
6; because it was not strided in the inner loop.
7
8; #define Z 32
9; typedef struct s {
10; int v1[Z];
11; int v2[Z];
12; int v3[Z][Z];
13; } s;
14;
15; void slow_function (s* const obj) {
16; for (int j=0; j<Z; j++) {
17; for (int k=0; k<Z; k++) {
18; int x = obj->v1[k] + obj->v2[j];
19; obj->v3[j][k] += x;
20; }
21; }
22; }
23
24; CHECK: function 'Test':
25; CHECK: .inner:
26; CHECK-NEXT: Memory dependences are safe
27; CHECK-NEXT: Dependences:
28; CHECK-NEXT: Run-time memory checks:
29; CHECK: Check 0:
30; CHECK: Check 1:
31
32target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
33target triple = "x86_64-unknown-linux-gnu"
34
35%struct.s = type { [32 x i32], [32 x i32], [32 x [32 x i32]] }
36
37define void @Test(%struct.s* nocapture %obj) #0 {
38 br label %.outer.preheader
39
40
41.outer.preheader:
42 %i = phi i64 [ 0, %0 ], [ %i.next, %.outer ]
43 %1 = getelementptr inbounds %struct.s, %struct.s* %obj, i64 0, i32 1, i64 %i
44 br label %.inner
45
46.exit:
47 ret void
48
49.outer:
50 %i.next = add nuw nsw i64 %i, 1
51 %exitcond.outer = icmp eq i64 %i.next, 32
52 br i1 %exitcond.outer, label %.exit, label %.outer.preheader
53
54.inner:
55 %j = phi i64 [ 0, %.outer.preheader ], [ %j.next, %.inner ]
56 %2 = getelementptr inbounds %struct.s, %struct.s* %obj, i64 0, i32 0, i64 %j
57 %3 = load i32, i32* %2
58 %4 = load i32, i32* %1
59 %5 = add nsw i32 %4, %3
60 %6 = getelementptr inbounds %struct.s, %struct.s* %obj, i64 0, i32 2, i64 %i, i64 %j
61 %7 = load i32, i32* %6
62 %8 = add nsw i32 %5, %7
63 store i32 %8, i32* %6
64 %j.next = add nuw nsw i64 %j, 1
65 %exitcond.inner = icmp eq i64 %j.next, 32
66 br i1 %exitcond.inner, label %.outer, label %.inner
67}