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