1; RUN: opt %loadPolly -polly-mse -analyze < %s | FileCheck %s
2;
3; Verify that the accesses are correctly expanded for MemoryKind::Array
4;
5; Original source code :
6;
7; #define Ni 2000
8; #define Nj 3000
9;
10; void tmp3(double A[Ni], double B[Nj]) {
11;   int i,j;
12;   double tmp = 6;
13;   for (i = 0; i < Ni; i++) {
14;
15;     for(int h = 0; h<Nj; h++)
16;      B[h] = h;
17;
18;     for(j = 0; j < Nj; j++) {
19;      for(int k=0; k<Nj; k++) {
20; 	tmp = i+k+j;
21; 	A[i+j] = tmp*B[k];
22;       }
23;     }
24;   }
25; }
26;
27; Check if the expanded SAI are created
28;
29; CHECK: double MemRef_B_Stmt_for_body3_expanded[10000][10000]; // Element size 8
30; CHECK: double MemRef_A_Stmt_for_body11_expanded[10000][10000][10000]; // Element size 8
31;
32; Check if the memory accesses are modified
33;
34; CHECK: new: { Stmt_for_body3[i0, i1] -> MemRef_B_Stmt_for_body3_expanded[i0, i1] };
35; CHECK: new: { Stmt_for_body11[i0, i1, i2] -> MemRef_B_Stmt_for_body3_expanded[i0, i2] };
36; CHECK: new: { Stmt_for_body11[i0, i1, i2] -> MemRef_A_Stmt_for_body11_expanded[i0, i1, i2] };
37;
38target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
39target triple = "x86_64-unknown-linux-gnu"
40
41define void @mse(double* %A, double* %B) {
42entry:
43  br label %entry.split
44
45entry.split:                                      ; preds = %entry
46  br label %for.body
47
48for.body:                                         ; preds = %entry.split, %for.inc25
49  %indvars.iv14 = phi i64 [ 0, %entry.split ], [ %indvars.iv.next15, %for.inc25 ]
50  br label %for.body3
51
52for.body3:                                        ; preds = %for.body, %for.body3
53  %indvars.iv = phi i64 [ 0, %for.body ], [ %indvars.iv.next, %for.body3 ]
54  %0 = trunc i64 %indvars.iv to i32
55  %conv = sitofp i32 %0 to double
56  %arrayidx = getelementptr inbounds double, double* %B, i64 %indvars.iv
57  store double %conv, double* %arrayidx, align 8
58  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
59  %exitcond = icmp ne i64 %indvars.iv.next, 10000
60  br i1 %exitcond, label %for.body3, label %for.end
61
62for.end:                                          ; preds = %for.body3
63  br label %for.body7
64
65for.body7:                                        ; preds = %for.end, %for.inc22
66  %indvars.iv9 = phi i64 [ 0, %for.end ], [ %indvars.iv.next10, %for.inc22 ]
67  br label %for.body11
68
69for.body11:                                       ; preds = %for.body7, %for.body11
70  %indvars.iv5 = phi i64 [ 0, %for.body7 ], [ %indvars.iv.next6, %for.body11 ]
71  %1 = add nuw nsw i64 %indvars.iv9, %indvars.iv14
72  %2 = add nuw nsw i64 %1, %indvars.iv5
73  %3 = trunc i64 %2 to i32
74  %conv13 = sitofp i32 %3 to double
75  %arrayidx15 = getelementptr inbounds double, double* %B, i64 %indvars.iv5
76  %4 = load double, double* %arrayidx15, align 8
77  %mul = fmul double %4, %conv13
78  %5 = add nuw nsw i64 %indvars.iv9, %indvars.iv14
79  %arrayidx18 = getelementptr inbounds double, double* %A, i64 %5
80  store double %mul, double* %arrayidx18, align 8
81  %indvars.iv.next6 = add nuw nsw i64 %indvars.iv5, 1
82  %exitcond8 = icmp ne i64 %indvars.iv.next6, 10000
83  br i1 %exitcond8, label %for.body11, label %for.inc22
84
85for.inc22:                                        ; preds = %for.body11
86  %indvars.iv.next10 = add nuw nsw i64 %indvars.iv9, 1
87  %exitcond13 = icmp ne i64 %indvars.iv.next10, 10000
88  br i1 %exitcond13, label %for.body7, label %for.inc25
89
90for.inc25:                                        ; preds = %for.inc22
91  %indvars.iv.next15 = add nuw nsw i64 %indvars.iv14, 1
92  %exitcond16 = icmp ne i64 %indvars.iv.next15, 10000
93  br i1 %exitcond16, label %for.body, label %for.end27
94
95for.end27:                                        ; preds = %for.inc25
96  ret void
97}
98