1 ; RUN: opt %loadNPMPolly -polly-allow-nonaffine-branches \
2 ; RUN: -polly-invariant-load-hoisting=true \
3 ; RUN: -polly-allow-nonaffine-loops=true \
4 ; RUN: '-passes=print<polly-detect>,print<polly-function-scops>' -disable-output < %s 2>&1 | FileCheck %s --check-prefix=INNERMOST
5 ; RUN: opt %loadNPMPolly -polly-allow-nonaffine \
6 ; RUN: -polly-invariant-load-hoisting=true \
7 ; RUN: -polly-allow-nonaffine-branches -polly-allow-nonaffine-loops=true \
8 ; RUN: '-passes=print<polly-detect>,print<polly-function-scops>' -disable-output < %s 2>&1 | FileCheck %s --check-prefix=ALL
9 ; RUN: opt %loadNPMPolly -polly-allow-nonaffine \
10 ; RUN: -polly-invariant-load-hoisting=true \
11 ; RUN: -polly-process-unprofitable=false \
12 ; RUN: -polly-allow-nonaffine-branches -polly-allow-nonaffine-loops=true \
13 ; RUN: '-passes=print<polly-detect>,print<polly-function-scops>' -disable-output < %s 2>&1 | FileCheck %s --check-prefix=PROFIT
15 ; Negative test for INNERMOST.
16 ; At the moment we will optimistically assume A[i] in the conditional before the inner
17 ; loop might be invariant and expand the SCoP from the loop to include the conditional. However,
18 ; during SCoP generation we will realize that A[i] is only sometimes invariant.
20 ; Possible solutions could be:
21 ; - Do not optimistically assume it to be invariant (as before this commit), however we would loose
22 ; a lot of invariant cases due to possible aliasing.
23 ; - Reduce the size of the SCoP if an assumed invariant access is in fact not invariant instead of
24 ; rejecting the whole region.
26 ; INNERMOST: Function: f
27 ; INNERMOST-NEXT: Region: %bb4---%bb3
28 ; INNERMOST-NEXT: Max Loop Depth: 1
29 ; INNERMOST-NEXT: Invariant Accesses: {
30 ; INNERMOST-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0]
31 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb4[] -> MemRef_A[p_2] };
32 ; INNERMOST-NEXT: Execution Context: [tmp6, p_1, p_2] -> { : (tmp6 > 0 and p_2 >= p_1) or (tmp6 < 0 and p_2 >= p_1) or tmp6 = 0 }
34 ; INNERMOST-NEXT: Context:
35 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { : -2147483648 <= tmp6 <= 2147483647 and -2199023255552 <= p_1 <= 2199023254528 and 0 <= p_2 <= 1024 }
36 ; INNERMOST-NEXT: Assumed Context:
37 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { : }
38 ; INNERMOST-NEXT: Invalid Context:
39 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { : p_2 < p_1 and (tmp6 < 0 or tmp6 > 0) }
40 ; INNERMOST: p0: %tmp6
41 ; INNERMOST-NEXT: p1: {0,+,(sext i32 %N to i64)}<%bb3>
42 ; INNERMOST-NEXT: p2: {0,+,1}<nuw><nsw><%bb3>
43 ; INNERMOST-NEXT: Arrays {
44 ; INNERMOST-NEXT: i32 MemRef_A[*]; // Element size 4
45 ; INNERMOST-NEXT: i64 MemRef_indvars_iv_next2; // Element size 8
47 ; INNERMOST-NEXT: Arrays (Bounds as pw_affs) {
48 ; INNERMOST-NEXT: i32 MemRef_A[*]; // Element size 4
49 ; INNERMOST-NEXT: i64 MemRef_indvars_iv_next2; // Element size 8
51 ; INNERMOST-NEXT: Alias Groups (0):
53 ; INNERMOST-NEXT: Statements {
54 ; INNERMOST-NEXT: Stmt_bb12
55 ; INNERMOST-NEXT: Domain :=
56 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb12[i0] : 0 <= i0 < p_1 and (tmp6 < 0 or tmp6 > 0) };
57 ; INNERMOST-NEXT: Schedule :=
58 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb12[i0] -> [0, i0] : tmp6 < 0 or tmp6 > 0 };
59 ; INNERMOST-NEXT: ReadAccess := [Reduction Type: +] [Scalar: 0]
60 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb12[i0] -> MemRef_A[i0] };
61 ; INNERMOST-NEXT: MustWriteAccess := [Reduction Type: +] [Scalar: 0]
62 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb12[i0] -> MemRef_A[i0] };
63 ; INNERMOST-NEXT: Stmt_bb19
64 ; INNERMOST-NEXT: Domain :=
65 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb19[] };
66 ; INNERMOST-NEXT: Schedule :=
67 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb19[] -> [1, 0] };
68 ; INNERMOST-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1]
69 ; INNERMOST-NEXT: [tmp6, p_1, p_2] -> { Stmt_bb19[] -> MemRef_indvars_iv_next2[] };
73 ; ALL-NEXT: Region: %bb3---%bb20
74 ; ALL-NEXT: Max Loop Depth: 1
75 ; ALL-NEXT: Invariant Accesses: {
79 ; ALL-NEXT: Assumed Context:
81 ; ALL-NEXT: Invalid Context:
82 ; ALL-NEXT: { : false }
84 ; ALL-NEXT: i32 MemRef_A[*]; // Element size 4
86 ; ALL-NEXT: Arrays (Bounds as pw_affs) {
87 ; ALL-NEXT: i32 MemRef_A[*]; // Element size 4
89 ; ALL-NEXT: Alias Groups (0):
91 ; ALL-NEXT: Statements {
92 ; ALL-NEXT: Stmt_bb4__TO__bb18
94 ; ALL-NEXT: { Stmt_bb4__TO__bb18[i0] : 0 <= i0 <= 1023 };
95 ; ALL-NEXT: Schedule :=
96 ; ALL-NEXT: { Stmt_bb4__TO__bb18[i0] -> [i0] };
97 ; ALL-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0]
98 ; ALL-NEXT: { Stmt_bb4__TO__bb18[i0] -> MemRef_A[i0] };
99 ; ALL-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0]
100 ; ALL-NEXT: { Stmt_bb4__TO__bb18[i0] -> MemRef_A[o0] : 0 <= o0 <= 2199023254528 };
101 ; ALL-NEXT: MayWriteAccess := [Reduction Type: NONE] [Scalar: 0]
102 ; ALL-NEXT: { Stmt_bb4__TO__bb18[i0] -> MemRef_A[o0] : 0 <= o0 <= 2199023254528 };
105 ; PROFIT-NOT: Statements
107 ; void f(int *A, int N) {
108 ; for (int i = 0; i < 1024; i++)
110 ; for (int j = 0; j < N * i; j++)
114 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
116 define void @f(ptr %A, i32 %N) {
118 %tmp = sext i32 %N to i64
121 bb3: ; preds = %bb19, %bb
122 %indvars.iv1 = phi i64 [ %indvars.iv.next2, %bb19 ], [ 0, %bb ]
123 %exitcond = icmp ne i64 %indvars.iv1, 1024
124 br i1 %exitcond, label %bb4, label %bb20
127 %tmp5 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv1
128 %tmp6 = load i32, ptr %tmp5, align 4
129 %tmp7 = icmp eq i32 %tmp6, 0
130 br i1 %tmp7, label %bb18, label %bb8
135 bb9: ; preds = %bb16, %bb8
136 %indvars.iv = phi i64 [ %indvars.iv.next, %bb16 ], [ 0, %bb8 ]
137 %tmp10 = mul nsw i64 %indvars.iv1, %tmp
138 %tmp11 = icmp slt i64 %indvars.iv, %tmp10
139 br i1 %tmp11, label %bb12, label %bb17
142 %tmp13 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
143 %tmp14 = load i32, ptr %tmp13, align 4
144 %tmp15 = add nsw i32 %tmp14, 1
145 store i32 %tmp15, ptr %tmp13, align 4
148 bb16: ; preds = %bb12
149 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
155 bb18: ; preds = %bb4, %bb17
158 bb19: ; preds = %bb18
159 %indvars.iv.next2 = add nuw nsw i64 %indvars.iv1, 1