1; RUN: opt %loadPolly -S -polly-codegen < %s | FileCheck %s
2;
3;    int jd(int *restrict A, int x, int N, int c) {
4;      for (int i = 0; i < N; i++)
5;        for (int j = 0; j < N; j++)
6;          if (i < c)
7;            x += A[i];
8;      return x;
9;    }
10;
11target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
12
13define i32 @jd(i32* noalias %A, i32 %x, i32 %N, i32 %c) {
14entry:
15; CHECK-LABEL: entry:
16; CHECK-DAG:     %x.addr.2.s2a = alloca i32
17; CHECK-DAG:     %x.addr.2.phiops = alloca i32
18; CHECK-DAG:     %x.addr.1.s2a = alloca i32
19; CHECK-DAG:     %x.addr.1.phiops = alloca i32
20; CHECK-DAG:     %x.addr.0.s2a = alloca i32
21; CHECK-DAG:     %x.addr.0.phiops = alloca i32
22  %tmp = sext i32 %N to i64
23  %tmp1 = sext i32 %c to i64
24  br label %for.cond
25
26; CHECK-LABEL: polly.merge_new_and_old:
27; CHECK:         %x.addr.0.merge = phi i32 [ %x.addr.0.final_reload, %polly.exiting ], [ %x.addr.0, %for.cond ]
28; CHECK:         ret i32 %x.addr.0.merge
29
30; CHECK-LABEL: polly.start:
31; CHECK-NEXT:    store i32 %x, i32* %x.addr.0.phiops
32; CHECK-NEXT:    sext
33
34; CHECK-LABEL: polly.merge{{[a-z_0-9]*}}:
35; CHECK:         %x.addr.0.final_reload = load i32, i32* %x.addr.0.s2a
36
37for.cond:                                         ; preds = %for.inc5, %entry
38; CHECK-LABEL: polly.stmt.for.cond{{[0-9]*}}:
39; CHECK:         %x.addr.0.phiops.reload[[R1:[0-9]*]] = load i32, i32* %x.addr.0.phiops
40; CHECK:         store i32 %x.addr.0.phiops.reload[[R1]], i32* %x.addr.0.s2a
41  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc5 ], [ 0, %entry ]
42  %x.addr.0 = phi i32 [ %x, %entry ], [ %x.addr.1, %for.inc5 ]
43  %cmp = icmp slt i64 %indvars.iv, %tmp
44  br i1 %cmp, label %for.body, label %for.end7
45
46for.body:                                         ; preds = %for.cond
47; CHECK-LABEL: polly.stmt.for.body:
48; CHECK:         %x.addr.0.s2a.reload[[R2:[0-9]*]] = load i32, i32* %x.addr.0.s2a
49; CHECK:         store i32 %x.addr.0.s2a.reload[[R2]], i32* %x.addr.1.phiops
50  br label %for.cond1
51
52for.inc5:                                         ; preds = %for.end
53; CHECK-LABEL: polly.stmt.for.inc5:
54; CHECK:         %x.addr.1.s2a.reload[[R5:[0-9]*]] = load i32, i32* %x.addr.1.s2a
55; CHECK:         store i32 %x.addr.1.s2a.reload[[R5]], i32* %x.addr.0.phiops
56  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
57  br label %for.cond
58
59for.cond1:                                        ; preds = %for.inc, %for.body
60; CHECK-LABEL: polly.stmt.for.cond1:
61; CHECK:         %x.addr.1.phiops.reload = load i32, i32* %x.addr.1.phiops
62; CHECK:         store i32 %x.addr.1.phiops.reload, i32* %x.addr.1.s2a
63  %x.addr.1 = phi i32 [ %x.addr.0, %for.body ], [ %x.addr.2, %for.inc ]
64  %j.0 = phi i32 [ 0, %for.body ], [ %inc, %for.inc ]
65  %exitcond = icmp ne i32 %j.0, %N
66  br i1 %exitcond, label %for.body3, label %for.end
67
68for.body3:                                        ; preds = %for.cond1
69; CHECK-LABEL: polly.stmt.for.body3:
70; CHECK:  %x.addr.1.s2a.reload = load i32, i32* %x.addr.1.s2a
71; CHECK:  store i32 %x.addr.1.s2a.reload, i32* %x.addr.2.phiops
72  %cmp4 = icmp slt i64 %indvars.iv, %tmp1
73  br i1 %cmp4, label %if.then, label %if.end
74
75if.end:                                           ; preds = %if.then, %for.body3
76; CHECK-LABEL: polly.stmt.if.end:
77; CHECK:         %x.addr.2.phiops.reload = load i32, i32* %x.addr.2.phiops
78; CHECK:         store i32 %x.addr.2.phiops.reload, i32* %x.addr.2.s2a
79  %x.addr.2 = phi i32 [ %add, %if.then ], [ %x.addr.1, %for.body3 ]
80  br label %for.inc
81
82for.inc:                                          ; preds = %if.end
83; CHECK-LABEL: polly.stmt.for.inc:
84; CHECK:         %x.addr.2.s2a.reload[[R3:[0-9]*]] = load i32, i32* %x.addr.2.s2a
85; CHECK:         store i32 %x.addr.2.s2a.reload[[R3]], i32* %x.addr.1.phiops
86  %inc = add nsw i32 %j.0, 1
87  br label %for.cond1
88
89if.then:                                          ; preds = %for.body3
90; CHECK-LABEL: polly.stmt.if.then:
91; CHECK:         %x.addr.1.s2a.reload[[R5:[0-9]*]] = load i32, i32* %x.addr.1.s2a
92; CHECK:         %p_add = add nsw i32 %x.addr.1.s2a.reload[[R5]], %tmp2_p_scalar_
93; CHECK:         store i32 %p_add, i32* %x.addr.2.phiops
94  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
95  %tmp2 = load i32, i32* %arrayidx, align 4
96  %add = add nsw i32 %x.addr.1, %tmp2
97  br label %if.end
98
99for.end:                                          ; preds = %for.cond1
100  br label %for.inc5
101
102for.end7:                                         ; preds = %for.cond
103  ret i32 %x.addr.0
104}
105
106