1; RUN: opt %loadPolly -analyze -polly-scops \
2; RUN: -polly-invariant-load-hoisting=true < %s | FileCheck %s
3; RUN: opt %loadPolly -S -polly-codegen \
4; RUN: -polly-invariant-load-hoisting=true < %s | FileCheck %s --check-prefix=IR
5;
6;    void f(long *A, long *B, long *ptr, long val) {
7;      for (long i = 0; i < 100; i++) {
8;        long ptrV = ((long)(ptr + 1)) + 1;
9;        long valP = (long)(((long *)(val + 1)) + 1);
10;        A[ptrV] += B[valP];
11;      }
12;    }
13;
14; CHECK:        ReadAccess :=	[Reduction Type: NONE] [Scalar: 0]
15; CHECK-NEXT:       [val, ptr] -> { Stmt_for_body[i0] -> MemRef_B[9 + val] };
16; CHECK-NEXT:   Execution Context: [val, ptr] -> {  : -4097 <= val <= 4086 }
17;
18; CHECK:   ReadAccess :=	[Reduction Type: +] [Scalar: 0]
19; CHECK-NEXT:       [val, ptr] -> { Stmt_for_body[i0] -> MemRef_A[9 + ptr] };
20; CHECK-NEXT:   MustWriteAccess :=	[Reduction Type: +] [Scalar: 0]
21; CHECK-NEXT:       [val, ptr] -> { Stmt_for_body[i0] -> MemRef_A[9 + ptr] };
22;
23; IR:      polly.stmt.for.body:
24; IR-NEXT:   %tmp4_p_scalar_ = load i64, i64* %scevgep, align 8, !alias.scope !3, !noalias !4
25; IR-NEXT:   %p_add4 = add nsw i64 %tmp4_p_scalar_, %polly.preload.tmp3.merge
26; IR-NEXT:   store i64 %p_add4, i64* %scevgep, align 8, !alias.scope !3, !noalias !4
27; IR-NEXT:   %polly.indvar_next = add nsw i64 %polly.indvar, 1
28; IR-NEXT:   %polly.loop_cond = icmp sle i64 %polly.indvar_next, 99
29; IR-NEXT:   br i1 %polly.loop_cond, label %polly.loop_header, label %polly.loop_exit
30
31; IR:      polly.loop_preheader:
32; IR-NEXT:   %41 = add i16 %val, 1
33; IR-NEXT:   %42 = ptrtoint i64* %ptr to i16
34; IR-NEXT:   %43 = add i16 %42, 9
35; IR-NEXT:   %scevgep = getelementptr i64, i64* %A, i16 %43
36; IR-NEXT:   br label %polly.loop_header
37;
38target datalayout = "e-p:16:16:16-m:e-i64:64-f80:128-n8:16:16:64-S128"
39
40define void @f(i64* %A, i64* %B, i64* %ptr, i16 %val) {
41entry:
42  br label %for.cond
43
44for.cond:                                         ; preds = %for.inc, %entry
45  %i.0 = phi i64 [ 0, %entry ], [ %inc, %for.inc ]
46  %exitcond = icmp ne i64 %i.0, 100
47  br i1 %exitcond, label %for.body, label %for.end
48
49for.body:                                         ; preds = %for.cond
50  %add.ptr = getelementptr inbounds i64, i64* %ptr, i64 1
51  %tmp = ptrtoint i64* %add.ptr to i16
52  %add = add nsw i16 %tmp, 1
53  %add1 = add nsw i16 %val, 1
54  %tmp1 = inttoptr i16 %add1 to i64*
55  %add.ptr2 = getelementptr inbounds i64, i64* %tmp1, i64 1
56  %tmp2 = ptrtoint i64* %add.ptr2 to i16
57  %arrayidx = getelementptr inbounds i64, i64* %B, i16 %tmp2
58  %tmp3 = load i64, i64* %arrayidx
59  %arrayidx3 = getelementptr inbounds i64, i64* %A, i16 %add
60  %tmp4 = load i64, i64* %arrayidx3
61  %add4 = add nsw i64 %tmp4, %tmp3
62  store i64 %add4, i64* %arrayidx3
63  br label %for.inc
64
65for.inc:                                          ; preds = %for.body
66  %inc = add nuw nsw i64 %i.0, 1
67  br label %for.cond
68
69for.end:                                          ; preds = %for.cond
70  ret void
71}
72