xref: /llvm-project/polly/test/CodeGen/MemAccess/create_arrays_heap.ll (revision 17168f7f786b051dd4737a576ba371742a29894d)
155cb5796SNikita Popov; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-print-scops -polly-print-import-jscop -polly-import-jscop-postfix=transformed -disable-output < %s | FileCheck %s
255cb5796SNikita Popov; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-import-jscop -polly-import-jscop-postfix=transformed -polly-codegen -S < %s | FileCheck %s --check-prefix=CODEGEN
335f70200SMichael Kruse;
435f70200SMichael Kruse; #define Ni 1056
535f70200SMichael Kruse; #define Nj 1056
635f70200SMichael Kruse; #define Nk 1024
735f70200SMichael Kruse;
835f70200SMichael Kruse; void create_arrays_heap(double beta, double A[Ni][Nk], double B[Ni][Nj]) {
935f70200SMichael Kruse;   int i,j,k;
1035f70200SMichael Kruse;
1135f70200SMichael Kruse;   for (i = 0; i < Ni; i++) {
1235f70200SMichael Kruse;     for (j = 0; j < Nj; j++) {
1335f70200SMichael Kruse;       for (k = 0; k < Nk; ++k) {
1435f70200SMichael Kruse; 	B[i][j] = beta * A[i][k];
1535f70200SMichael Kruse;       }
1635f70200SMichael Kruse;     }
1735f70200SMichael Kruse;   }
1835f70200SMichael Kruse; }
1935f70200SMichael Kruse;
2035f70200SMichael Kruse; Check if the info from the JSON file has been analysed without errors.
2135f70200SMichael Kruse; CHECK: Arrays {
2235f70200SMichael Kruse; CHECK: double MemRef_A[*][1024]; // Element size 8
2335f70200SMichael Kruse; CHECK: double MemRef_beta; // Element size 8
2435f70200SMichael Kruse; CHECK: double MemRef_B[*][1056]; // Element size 8
2535f70200SMichael Kruse; CHECK: double D[270336]; // Element size 8
2635f70200SMichael Kruse; CHECK: double E[270336][200000]; // Element size 8
2735f70200SMichael Kruse; CHECK: i64 F[270336]; // Element size 8
2835f70200SMichael Kruse;
2935f70200SMichael Kruse; Check if there are the 3 expected malloc calls with the right parameters at polly.start.
3035f70200SMichael Kruse; 	%D : size(D) = product_all_dimensions*sizeof(type) = 270336*8 = 2162688 cast to double*
3135f70200SMichael Kruse;	%E : size(E) = 270336*200000*8 = 432537600000 cast to double*
3235f70200SMichael Kruse; 	%F : size(F) = 270336*8 = 2162688 cast to i64*
3335f70200SMichael Kruse; CODEGEN: polly.start:
344491f0b9SNikita Popov; CODEGEN: %D = tail call ptr @malloc(i64 2162688)
354491f0b9SNikita Popov; CODEGEN: %E = tail call ptr @malloc(i64 432537600000)
364491f0b9SNikita Popov; CODEGEN: %F = tail call ptr @malloc(i64 2162688)
3735f70200SMichael Kruse;
3835f70200SMichael Kruse; Check if there are the 3 expected malloc calls with the right parameters at polly.exiting.
3935f70200SMichael Kruse; 	Cast to i8* before freeing because malloc give us a i8 and free is waiting for a i8*
4035f70200SMichael Kruse; CODEGEN: polly.exiting:
414491f0b9SNikita Popov; CODEGEN: tail call void @free(ptr %D)
424491f0b9SNikita Popov; CODEGEN: tail call void @free(ptr %E)
434491f0b9SNikita Popov; CODEGEN: tail call void @free(ptr %F)
4435f70200SMichael Kruse;
4535f70200SMichael Kruse; Check if the new access for array E is present.
4655cb5796SNikita Popov; CODEGEN: %polly.access.mul.{{.*}} = mul nsw i64 %polly.indvar, 200000
4755cb5796SNikita Popov; CODEGEN: %polly.access.add.{{.*}} = add nsw i64 %polly.access.mul.{{.*}}, %
484491f0b9SNikita Popov; CODEGEN: %polly.access.{{.*}} = getelementptr double, ptr %E, i64 %polly.access.add.{{.*}}
4935f70200SMichael Kruse;
5035f70200SMichael Kruse; ModuleID = 'create_arrays_heap.ll'
5135f70200SMichael Kruse;
5235f70200SMichael Krusetarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5335f70200SMichael Krusetarget triple = "x86_64-unknown-linux-gnu"
5435f70200SMichael Kruse
5535f70200SMichael Kruse; Function Attrs: nounwind uwtable
5655cb5796SNikita Popovdefine void @create_arrays_heap(double %beta, ptr nocapture readonly %A, ptr nocapture %B) local_unnamed_addr {
5735f70200SMichael Kruseentry:
5835f70200SMichael Kruse  br label %for.cond1.preheader
5935f70200SMichael Kruse
6035f70200SMichael Krusefor.cond1.preheader:                              ; preds = %for.inc16, %entry
6135f70200SMichael Kruse  %indvars.iv35 = phi i64 [ 0, %entry ], [ %indvars.iv.next36, %for.inc16 ]
6235f70200SMichael Kruse  br label %for.cond4.preheader
6335f70200SMichael Kruse
6435f70200SMichael Krusefor.cond4.preheader:                              ; preds = %for.inc13, %for.cond1.preheader
6535f70200SMichael Kruse  %indvars.iv32 = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next33, %for.inc13 ]
6655cb5796SNikita Popov  %arrayidx12 = getelementptr inbounds [1056 x double], ptr %B, i64 %indvars.iv35, i64 %indvars.iv32
6735f70200SMichael Kruse  br label %for.body6
6835f70200SMichael Kruse
6935f70200SMichael Krusefor.body6:                                        ; preds = %for.body6, %for.cond4.preheader
7035f70200SMichael Kruse  %indvars.iv = phi i64 [ 0, %for.cond4.preheader ], [ %indvars.iv.next.3, %for.body6 ]
7155cb5796SNikita Popov  %arrayidx8 = getelementptr inbounds [1024 x double], ptr %A, i64 %indvars.iv35, i64 %indvars.iv
7255cb5796SNikita Popov  %0 = load double, ptr %arrayidx8, align 8
7335f70200SMichael Kruse  %mul = fmul double %0, %beta
7455cb5796SNikita Popov  store double %mul, ptr %arrayidx12, align 8
75*17168f7fSNikita Popov  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
7655cb5796SNikita Popov  %arrayidx8.1 = getelementptr inbounds [1024 x double], ptr %A, i64 %indvars.iv35, i64 %indvars.iv.next
7755cb5796SNikita Popov  %1 = load double, ptr %arrayidx8.1, align 8
7835f70200SMichael Kruse  %mul.1 = fmul double %1, %beta
7955cb5796SNikita Popov  store double %mul.1, ptr %arrayidx12, align 8
80*17168f7fSNikita Popov  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
8155cb5796SNikita Popov  %arrayidx8.2 = getelementptr inbounds [1024 x double], ptr %A, i64 %indvars.iv35, i64 %indvars.iv.next.1
8255cb5796SNikita Popov  %2 = load double, ptr %arrayidx8.2, align 8
8335f70200SMichael Kruse  %mul.2 = fmul double %2, %beta
8455cb5796SNikita Popov  store double %mul.2, ptr %arrayidx12, align 8
85*17168f7fSNikita Popov  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
8655cb5796SNikita Popov  %arrayidx8.3 = getelementptr inbounds [1024 x double], ptr %A, i64 %indvars.iv35, i64 %indvars.iv.next.2
8755cb5796SNikita Popov  %3 = load double, ptr %arrayidx8.3, align 8
8835f70200SMichael Kruse  %mul.3 = fmul double %3, %beta
8955cb5796SNikita Popov  store double %mul.3, ptr %arrayidx12, align 8
9035f70200SMichael Kruse  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
9135f70200SMichael Kruse  %exitcond.3 = icmp eq i64 %indvars.iv.next.3, 1024
9235f70200SMichael Kruse  br i1 %exitcond.3, label %for.inc13, label %for.body6
9335f70200SMichael Kruse
9435f70200SMichael Krusefor.inc13:                                        ; preds = %for.body6
9535f70200SMichael Kruse  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
9635f70200SMichael Kruse  %exitcond34 = icmp eq i64 %indvars.iv.next33, 1056
9735f70200SMichael Kruse  br i1 %exitcond34, label %for.inc16, label %for.cond4.preheader
9835f70200SMichael Kruse
9935f70200SMichael Krusefor.inc16:                                        ; preds = %for.inc13
10035f70200SMichael Kruse  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
10135f70200SMichael Kruse  %exitcond37 = icmp eq i64 %indvars.iv.next36, 1056
10235f70200SMichael Kruse  br i1 %exitcond37, label %for.end18, label %for.cond1.preheader
10335f70200SMichael Kruse
10435f70200SMichael Krusefor.end18:                                        ; preds = %for.inc16
10535f70200SMichael Kruse  ret void
10635f70200SMichael Kruse}
10735f70200SMichael Kruse
108