1*e1f056f6Srahulana-quic; RUN: opt %loadNPMPolly -polly-invariant-load-hoisting=true '-passes=print<polly-function-scops>' -disable-output < %s 2>&1 | FileCheck %s 2*e1f056f6Srahulana-quic; RUN: opt %loadNPMPolly -polly-invariant-load-hoisting=true -polly-overflow-tracking=never -passes=polly-codegen -S < %s | FileCheck %s --check-prefix=IR 335f70200SMichael Kruse; 435f70200SMichael Kruse; As (p + q) can overflow we have to check that we load from 535f70200SMichael Kruse; I[p + q] only if it does not. 635f70200SMichael Kruse; 735f70200SMichael Kruse; CHECK: Invariant Accesses: { 835f70200SMichael Kruse; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0] 935f70200SMichael Kruse; CHECK-NEXT: [N, p, q] -> { Stmt_for_body[i0] -> MemRef_I[p + q] }; 1035f70200SMichael Kruse; CHECK-NEXT: Execution Context: [N, p, q] -> { : N > 0 and -2147483648 - p <= q <= 2147483647 - p } 1135f70200SMichael Kruse; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0] 1235f70200SMichael Kruse; CHECK-NEXT: [N, p, q] -> { Stmt_for_body[i0] -> MemRef_tmp1[0] }; 1335f70200SMichael Kruse; CHECK-NEXT: Execution Context: [N, p, q] -> { : N > 0 } 1435f70200SMichael Kruse; CHECK-NEXT: } 1535f70200SMichael Kruse; 1635f70200SMichael Kruse; IR: polly.preload.merge: 17fc78ebadSNikita Popov; IR-NEXT: %polly.preload.tmp1.merge = phi ptr [ %polly.access.I.load, %polly.preload.exec ], [ null, %polly.preload.cond ] 18fc78ebadSNikita Popov; IR-NEXT: store ptr %polly.preload.tmp1.merge, ptr %tmp1.preload.s2a 1935f70200SMichael Kruse; IR-NEXT: %12 = sext i32 %N to i64 2035f70200SMichael Kruse; IR-NEXT: %13 = icmp sge i64 %12, 1 2135f70200SMichael Kruse; IR-NEXT: %14 = sext i32 %q to i64 2235f70200SMichael Kruse; IR-NEXT: %15 = sext i32 %p to i64 2335f70200SMichael Kruse; IR-NEXT: %16 = add nsw i64 %15, %14 2435f70200SMichael Kruse; IR-NEXT: %17 = icmp sle i64 %16, 2147483647 2535f70200SMichael Kruse; IR-NEXT: %18 = and i1 %13, %17 2635f70200SMichael Kruse; IR-NEXT: %19 = sext i32 %q to i64 2735f70200SMichael Kruse; IR-NEXT: %20 = sext i32 %p to i64 2835f70200SMichael Kruse; IR-NEXT: %21 = add nsw i64 %20, %19 2935f70200SMichael Kruse; IR-NEXT: %22 = icmp sge i64 %21, -2147483648 3035f70200SMichael Kruse; IR-NEXT: %23 = and i1 %18, %22 31782c0dd1SFlorian Hahn; IR-NEXT: %polly.preload.cond.result1 = and i1 %23, true 32782c0dd1SFlorian Hahn; IR-NEXT: br label %polly.preload.cond2 3335f70200SMichael Kruse; 34782c0dd1SFlorian Hahn; IR: polly.preload.cond2: 35782c0dd1SFlorian Hahn; IR-NEXT: br i1 %polly.preload.cond.result1 3635f70200SMichael Kruse; 37782c0dd1SFlorian Hahn; IR: polly.preload.exec4: 38fc78ebadSNikita Popov; IR-NEXT: %polly.access.polly.preload.tmp1.merge = getelementptr i32, ptr %polly.preload.tmp1.merge, i64 0 39fc78ebadSNikita Popov; IR-NEXT: %polly.access.polly.preload.tmp1.merge.load = load i32, ptr %polly.access.polly.preload.tmp1.merge, align 4 4035f70200SMichael Kruse; 4135f70200SMichael Kruse; void f(int **I, int *A, int N, int p, int q) { 4235f70200SMichael Kruse; for (int i = 0; i < N; i++) 4335f70200SMichael Kruse; A[i] = *(I[p + q]); 4435f70200SMichael Kruse; } 4535f70200SMichael Kruse; 4635f70200SMichael Krusetarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 4735f70200SMichael Kruse 48fc78ebadSNikita Popovdefine void @f(ptr %I, ptr %A, i32 %N, i32 %p, i32 %q) { 4935f70200SMichael Kruseentry: 5035f70200SMichael Kruse %tmp = sext i32 %N to i64 5135f70200SMichael Kruse br label %for.cond 5235f70200SMichael Kruse 5335f70200SMichael Krusefor.cond: ; preds = %for.inc, %entry 5435f70200SMichael Kruse %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ] 5535f70200SMichael Kruse %cmp = icmp slt i64 %indvars.iv, %tmp 5635f70200SMichael Kruse br i1 %cmp, label %for.body, label %for.end 5735f70200SMichael Kruse 5835f70200SMichael Krusefor.body: ; preds = %for.cond 5935f70200SMichael Kruse %add = add i32 %p, %q 6035f70200SMichael Kruse %idxprom = sext i32 %add to i64 61fc78ebadSNikita Popov %arrayidx = getelementptr inbounds ptr, ptr %I, i64 %idxprom 62fc78ebadSNikita Popov %tmp1 = load ptr, ptr %arrayidx, align 8 63fc78ebadSNikita Popov %tmp2 = load i32, ptr %tmp1, align 4 64fc78ebadSNikita Popov %arrayidx2 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv 65fc78ebadSNikita Popov store i32 %tmp2, ptr %arrayidx2, align 4 6635f70200SMichael Kruse br label %for.inc 6735f70200SMichael Kruse 6835f70200SMichael Krusefor.inc: ; preds = %for.body 6935f70200SMichael Kruse %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 7035f70200SMichael Kruse br label %for.cond 7135f70200SMichael Kruse 7235f70200SMichael Krusefor.end: ; preds = %for.cond 7335f70200SMichael Kruse ret void 7435f70200SMichael Kruse} 75