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