1; RUN: opt %loadPolly -polly-detect -polly-allow-nonaffine-branches \
2; RUN:     -polly-allow-nonaffine-loops=false \
3; RUN:     -analyze < %s | FileCheck %s --check-prefix=REJECTNONAFFINELOOPS
4; RUN: opt %loadPolly -polly-detect -polly-allow-nonaffine-branches \
5; RUN:     -polly-allow-nonaffine-loops=true \
6; RUN:     -analyze < %s | FileCheck %s --check-prefix=ALLOWNONAFFINELOOPS
7; RUN: opt %loadPolly -polly-detect -polly-allow-nonaffine \
8; RUN:     -polly-allow-nonaffine-branches -polly-allow-nonaffine-loops=true \
9; RUN:     -analyze < %s | FileCheck %s \
10; RUN:     --check-prefix=ALLOWNONAFFINELOOPSANDACCESSES
11;
12; Here we have a non-affine loop (in the context of the loop nest)
13; and also a non-affine access (A[k]). While we can always detect the
14; innermost loop as a SCoP of depth 1, we have to reject the loop nest if not
15; both, non-affine loops as well as non-affine accesses are allowed.
16;
17; REJECTNONAFFINELOOPS:           Valid Region for Scop: bb15 => bb13
18; REJECTNONAFFINELOOPS-NOT:       Valid
19; ALLOWNONAFFINELOOPS:            Valid Region for Scop: bb15 => bb13
20; ALLOWNONAFFINELOOPS-NOT:        Valid
21; ALLOWNONAFFINELOOPSANDACCESSES: Valid Region for Scop: bb11 => bb29
22;
23;    void f(int *A) {
24;      for (int i = 0; i < 1024; i++)
25;        for (int j = 0; j < 1024; j++)
26;          for (int k = 0; k < i * j; k++)
27;            A[k] += A[i] + A[j];
28;    }
29;
30target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
31
32define void @f(i32* %A) {
33bb:
34  br label %bb11
35
36bb11:                                             ; preds = %bb28, %bb
37  %indvars.iv8 = phi i64 [ %indvars.iv.next9, %bb28 ], [ 0, %bb ]
38  %indvars.iv1 = phi i32 [ %indvars.iv.next2, %bb28 ], [ 0, %bb ]
39  %exitcond10 = icmp ne i64 %indvars.iv8, 1024
40  br i1 %exitcond10, label %bb12, label %bb29
41
42bb12:                                             ; preds = %bb11
43  br label %bb13
44
45bb13:                                             ; preds = %bb26, %bb12
46  %indvars.iv5 = phi i64 [ %indvars.iv.next6, %bb26 ], [ 0, %bb12 ]
47  %indvars.iv3 = phi i32 [ %indvars.iv.next4, %bb26 ], [ 0, %bb12 ]
48  %exitcond7 = icmp ne i64 %indvars.iv5, 1024
49  br i1 %exitcond7, label %bb14, label %bb27
50
51bb14:                                             ; preds = %bb13
52  br label %bb15
53
54bb15:                                             ; preds = %bb24, %bb14
55  %indvars.iv = phi i64 [ %indvars.iv.next, %bb24 ], [ 0, %bb14 ]
56  %lftr.wideiv = trunc i64 %indvars.iv to i32
57  %exitcond = icmp ne i32 %lftr.wideiv, %indvars.iv3
58  br i1 %exitcond, label %bb16, label %bb25
59
60bb16:                                             ; preds = %bb15
61  %tmp = getelementptr inbounds i32, i32* %A, i64 %indvars.iv8
62  %tmp17 = load i32, i32* %tmp, align 4
63  %tmp18 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv5
64  %tmp19 = load i32, i32* %tmp18, align 4
65  %tmp20 = add nsw i32 %tmp17, %tmp19
66  %tmp21 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
67  %tmp22 = load i32, i32* %tmp21, align 4
68  %tmp23 = add nsw i32 %tmp22, %tmp20
69  store i32 %tmp23, i32* %tmp21, align 4
70  br label %bb24
71
72bb24:                                             ; preds = %bb16
73  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
74  br label %bb15
75
76bb25:                                             ; preds = %bb15
77  br label %bb26
78
79bb26:                                             ; preds = %bb25
80  %indvars.iv.next6 = add nuw nsw i64 %indvars.iv5, 1
81  %indvars.iv.next4 = add nuw nsw i32 %indvars.iv3, %indvars.iv1
82  br label %bb13
83
84bb27:                                             ; preds = %bb13
85  br label %bb28
86
87bb28:                                             ; preds = %bb27
88  %indvars.iv.next9 = add nuw nsw i64 %indvars.iv8, 1
89  %indvars.iv.next2 = add nuw nsw i32 %indvars.iv1, 1
90  br label %bb11
91
92bb29:                                             ; preds = %bb11
93  ret void
94}
95