[PPCGCodeGeneration] Correct usage of llvm::Value with getLatestValue.
[polly-mirror.git] / test / GPGPU / invariant-load-hoisting-of-array.ll
blob21bf81365d61d2d21c0e50315dcd1ba925bea7f3
1 ; RUN: opt %loadPolly -analyze -polly-scops \
2 ; RUN: -polly-invariant-load-hoisting < %s | FileCheck %s -check-prefix=SCOP
4 ; RUN: opt %loadPolly -S -polly-codegen-ppcg \
5 ; RUN: -polly-invariant-load-hoisting < %s | FileCheck %s -check-prefix=HOST-IR
7 ; Entry: Contains (%loaded.ptr.preload.s2a = alloca double*) which is
8 ;   |    invariant load hoisted `%loaded.ptr`
9 ;   v
10 ; Run-time check --(failure branch)--> { old code - contains `%loaded.ptr` }
11 ;   |
12 ;  (success branch)
13 ;   |
14 ;   v
15 ; New Code: Should refer to `%loaded.ptr.preload.s2a`, which is
16 ;           the invariant load hoisted value, NOT `%loaded.ptr`.
18 ; In Polly, we preserve the old code and create a separate branch that executes
19 ; the GPU code if a run-time check succeeds.
21 ; We need to make sure that in the new branch, we pick up invariant load hoisted
22 ; values. The old values will belong to the old code branch.
24 ; In this case, we use to try to load the 'original' %loaded.ptr in the
25 ; 'New Code' branch,which is wrong. Check that this does not happen.
27 ; Check that we have a Scop with an invariant load of the array.
28 ; SCOP:       Function: f
29 ; SCOP-NEXT:  Region: %arrload---%for.exit
30 ; SCOP-NEXT:  Max Loop Depth:  1
31 ; SCOP-NEXT:  Invariant Accesses: {
32 ; SCOP-NEXT:          ReadAccess :=     [Reduction Type: NONE] [Scalar: 0]
33 ; SCOP-NEXT:              { Stmt_arrload[] -> MemRef_arr_of_ptrs[0] };
37 ; Check that we have the preloaded array.
38 ; HOST-IR: entry:
39 ; HOST-IR-NEXT:  %loaded.ptr.preload.s2a = alloca double*
41 ; Chek that we store the correct value in the preload.
42 ; polly.preload.begin:                              ; preds = %polly.split_new_and_old
43 ; HOST-IR: %polly.access.arr.of.ptrs = getelementptr double*, double** %arr.of.ptrs, i64 0
44 ; HOST-IR-NEXT: %polly.access.arr.of.ptrs.load = load double*, double** %polly.access.arr.of.ptrs
45 ; HOST-IR-NEXT: store double* %polly.access.arr.of.ptrs.load, double** %loaded.ptr.preload.s2a
47 ; Check that we get back data from the kernel.
48 ; HOST-IR: polly.acc.initialize:                             ; preds = %polly.start
49 ; HOST-IR: [[FIRSTINDEX:%.+]] = getelementptr double, double* %polly.access.arr.of.ptrs.load, i64 1
50 ; HOST-IR: [[BITCASTED:%.+]] = bitcast double* [[FIRSTINDEX]] to i8*
51 ; HOST-IR: call void @polly_copyFromDeviceToHost(i8* %p_dev_array_MemRef_loaded_ptr, i8* [[BITCASTED]], i64 800)
53 ; Check that the kernel launch is generated in the host IR.
54 ; This declaration would not have been generated unless a kernel launch exists.
55 ; HOST-IR: declare void @polly_launchKernel(i8*, i32, i32, i32, i32, i32, i8*)
58 ; C pseudocode equivalent
59 ; void f(double **arr_of_ptrs) {
60 ;     double *loaded_ptr = arr_of_ptrs[0];
61 ;     if (false) { return; }
62 ;     else {
63 ;         for(int i = 1; i < 100; i++) {
64 ;             loaded_ptr[i] = 42.0;
65 ;         }
66 ;     }
67 ; }
70 target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
71 target triple = "x86_64-unknown-linux-gnu"
74 ; Function Attrs: nounwind uwtable
75 define void @f(double **%arr.of.ptrs) #0 {
76 entry:
77   br label %arrload
79 arrload:                                             ; preds = %"7"
80   %loaded.ptr = load double*, double** %arr.of.ptrs, align 8
81   br i1 false, label %"for.exit", label %"for.preheader"
83 "for.preheader":                                       ; preds = %"51"
84   br label %"for.body"
86 "for.body":                                             ; preds = %"53", %"53.lr.ph"
87   %indvar = phi i64 [ 1, %"for.preheader" ], [ %indvar.next, %"for.body" ]
88   %slot = getelementptr double, double* %loaded.ptr, i64 %indvar
89   store double 42.0, double* %slot, align 8
91   %indvar.next = add nuw nsw i64 %indvar, 1
93   %check = icmp sgt i64 %indvar.next, 100
94   br i1 %check, label %"for.exit", label %"for.body"
96 "for.exit":                                             ; preds = %"52.54_crit_edge", %"51"
97     ret void
100 attributes #0 = { nounwind uwtable }