1 ; RUN: opt %loadPolly -polly-invariant-load-hoisting=true -polly-print-scops -disable-output < %s | FileCheck %s
2 ; RUN: opt %loadPolly -polly-invariant-load-hoisting=true -polly-overflow-tracking=never -polly-codegen -S < %s | FileCheck %s --check-prefix=IR
4 ; As (p + q) can overflow we have to check that we load from
5 ; I[p + q] only if it does not.
7 ; CHECK: Invariant Accesses: {
8 ; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0]
9 ; CHECK-NEXT: [N, p, q] -> { Stmt_for_body[i0] -> MemRef_I[p + q] };
10 ; CHECK-NEXT: Execution Context: [N, p, q] -> { : N > 0 and -2147483648 - p <= q <= 2147483647 - p }
11 ; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0]
12 ; CHECK-NEXT: [N, p, q] -> { Stmt_for_body[i0] -> MemRef_tmp1[0] };
13 ; CHECK-NEXT: Execution Context: [N, p, q] -> { : N > 0 }
16 ; IR: polly.preload.merge:
17 ; IR-NEXT: %polly.preload.tmp1.merge = phi ptr [ %polly.access.I.load, %polly.preload.exec ], [ null, %polly.preload.cond ]
18 ; IR-NEXT: store ptr %polly.preload.tmp1.merge, ptr %tmp1.preload.s2a
19 ; IR-NEXT: %12 = sext i32 %N to i64
20 ; IR-NEXT: %13 = icmp sge i64 %12, 1
21 ; IR-NEXT: %14 = sext i32 %q to i64
22 ; IR-NEXT: %15 = sext i32 %p to i64
23 ; IR-NEXT: %16 = add nsw i64 %15, %14
24 ; IR-NEXT: %17 = icmp sle i64 %16, 2147483647
25 ; IR-NEXT: %18 = and i1 %13, %17
26 ; IR-NEXT: %19 = sext i32 %q to i64
27 ; IR-NEXT: %20 = sext i32 %p to i64
28 ; IR-NEXT: %21 = add nsw i64 %20, %19
29 ; IR-NEXT: %22 = icmp sge i64 %21, -2147483648
30 ; IR-NEXT: %23 = and i1 %18, %22
31 ; IR-NEXT: %polly.preload.cond.result1 = and i1 %23, true
32 ; IR-NEXT: br label %polly.preload.cond2
34 ; IR: polly.preload.cond2:
35 ; IR-NEXT: br i1 %polly.preload.cond.result1
37 ; IR: polly.preload.exec4:
38 ; IR-NEXT: %polly.access.polly.preload.tmp1.merge = getelementptr i32, ptr %polly.preload.tmp1.merge, i64 0
39 ; IR-NEXT: %polly.access.polly.preload.tmp1.merge.load = load i32, ptr %polly.access.polly.preload.tmp1.merge, align 4
41 ; void f(int **I, int *A, int N, int p, int q) {
42 ; for (int i = 0; i < N; i++)
46 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
48 define void @f(ptr %I, ptr %A, i32 %N, i32 %p, i32 %q) {
50 %tmp = sext i32 %N to i64
53 for.cond: ; preds = %for.inc, %entry
54 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
55 %cmp = icmp slt i64 %indvars.iv, %tmp
56 br i1 %cmp, label %for.body, label %for.end
58 for.body: ; preds = %for.cond
60 %idxprom = sext i32 %add to i64
61 %arrayidx = getelementptr inbounds ptr, ptr %I, i64 %idxprom
62 %tmp1 = load ptr, ptr %arrayidx, align 8
63 %tmp2 = load i32, ptr %tmp1, align 4
64 %arrayidx2 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
65 store i32 %tmp2, ptr %arrayidx2, align 4
68 for.inc: ; preds = %for.body
69 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
72 for.end: ; preds = %for.cond