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-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-function-scops>' -disable-output < %s 2>&1 | FileCheck %s \
9 ; RUN: --check-prefix=ALL
11 ; Negative test for INNERMOST.
12 ; At the moment we will optimistically assume A[i] in the conditional before the inner
13 ; loop might be invariant and expand the SCoP from the loop to include the conditional. However,
14 ; during SCoP generation we will realize that A[i] is in not always invariant.
16 ; Possible solutions could be:
17 ; - Do not optimistically assume it to be invariant (as before this commit), however we would loose
18 ; a lot of invariant cases due to possible aliasing.
19 ; - Reduce the size of the SCoP if an assumed invariant access is in fact not invariant instead of
20 ; rejecting the whole region.
22 ; INNERMOST: Function: f
23 ; INNERMOST-NEXT: Region: %bb4---%bb3
24 ; INNERMOST-NEXT: Max Loop Depth: 1
25 ; INNERMOST-NEXT: Invariant Accesses: {
26 ; INNERMOST-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0]
27 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb4[] -> MemRef_A[p_2] };
28 ; INNERMOST-NEXT: Execution Context: [tmp6, N, p_2] -> { : (tmp6 > 0 and p_2 >= N) or (tmp6 < 0 and p_2 >= N) or tmp6 = 0 }
30 ; INNERMOST-NEXT: Context:
31 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { : -2147483648 <= tmp6 <= 2147483647 and -2147483648 <= N <= 2147483647 and 0 <= p_2 <= 1024 }
32 ; INNERMOST-NEXT: Assumed Context:
33 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { : }
34 ; INNERMOST-NEXT: Invalid Context:
35 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { : p_2 < N and (tmp6 < 0 or tmp6 > 0) }
36 ; INNERMOST: p0: %tmp6
37 ; INNERMOST-NEXT: p1: %N
38 ; INNERMOST-NEXT: p2: {0,+,1}<nuw><nsw><%bb3>
39 ; INNERMOST-NEXT: Arrays {
40 ; INNERMOST-NEXT: i32 MemRef_A[*]; // Element size 4
41 ; INNERMOST-NEXT: i64 MemRef_indvars_iv_next2; // Element size 8
43 ; INNERMOST-NEXT: Arrays (Bounds as pw_affs) {
44 ; INNERMOST-NEXT: i32 MemRef_A[*]; // Element size 4
45 ; INNERMOST-NEXT: i64 MemRef_indvars_iv_next2; // Element size 8
47 ; INNERMOST-NEXT: Alias Groups (0):
49 ; INNERMOST-NEXT: Statements {
50 ; INNERMOST-NEXT: Stmt_bb11
51 ; INNERMOST-NEXT: Domain :=
52 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb11[i0] : 0 <= i0 < N and (tmp6 < 0 or tmp6 > 0) };
53 ; INNERMOST-NEXT: Schedule :=
54 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb11[i0] -> [0, i0] : tmp6 < 0 or tmp6 > 0 };
55 ; INNERMOST-NEXT: ReadAccess := [Reduction Type: +] [Scalar: 0]
56 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb11[i0] -> MemRef_A[i0] };
57 ; INNERMOST-NEXT: MustWriteAccess := [Reduction Type: +] [Scalar: 0]
58 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb11[i0] -> MemRef_A[i0] };
59 ; INNERMOST-NEXT: Stmt_bb18
60 ; INNERMOST-NEXT: Domain :=
61 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb18[] };
62 ; INNERMOST-NEXT: Schedule :=
63 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb18[] -> [1, 0] };
64 ; INNERMOST-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1]
65 ; INNERMOST-NEXT: [tmp6, N, p_2] -> { Stmt_bb18[] -> MemRef_indvars_iv_next2[] };
69 ; ALL-NEXT: Region: %bb3---%bb19
70 ; ALL-NEXT: Max Loop Depth: 1
71 ; ALL-NEXT: Invariant Accesses: {
75 ; ALL-NEXT: Assumed Context:
77 ; ALL-NEXT: Invalid Context:
78 ; ALL-NEXT: { : false }
80 ; ALL-NEXT: i32 MemRef_A[*]; // Element size 4
82 ; ALL-NEXT: Arrays (Bounds as pw_affs) {
83 ; ALL-NEXT: i32 MemRef_A[*]; // Element size 4
85 ; ALL-NEXT: Alias Groups (0):
87 ; ALL-NEXT: Statements {
88 ; ALL-NEXT: Stmt_bb4__TO__bb17
90 ; ALL-NEXT: { Stmt_bb4__TO__bb17[i0] : 0 <= i0 <= 1023 };
91 ; ALL-NEXT: Schedule :=
92 ; ALL-NEXT: { Stmt_bb4__TO__bb17[i0] -> [i0] };
93 ; ALL-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0]
94 ; ALL-NEXT: { Stmt_bb4__TO__bb17[i0] -> MemRef_A[i0] };
95 ; ALL-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0]
96 ; ALL-NEXT: { Stmt_bb4__TO__bb17[i0] -> MemRef_A[o0] : 0 <= o0 <= 2147483647 };
97 ; ALL-NEXT: MayWriteAccess := [Reduction Type: NONE] [Scalar: 0]
98 ; ALL-NEXT: { Stmt_bb4__TO__bb17[i0] -> MemRef_A[o0] : 0 <= o0 <= 2147483647 };
101 ; void f(int *A, int N) {
102 ; for (int i = 0; i < 1024; i++)
104 ; for (int j = 0; j < N; j++)
108 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
110 define void @f(ptr %A, i32 %N) {
112 %tmp = sext i32 %N to i64
115 bb3: ; preds = %bb18, %bb
116 %indvars.iv1 = phi i64 [ %indvars.iv.next2, %bb18 ], [ 0, %bb ]
117 %exitcond = icmp ne i64 %indvars.iv1, 1024
118 br i1 %exitcond, label %bb4, label %bb19
121 %tmp5 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv1
122 %tmp6 = load i32, ptr %tmp5, align 4
123 %tmp7 = icmp eq i32 %tmp6, 0
124 br i1 %tmp7, label %bb17, label %bb8
129 bb9: ; preds = %bb15, %bb8
130 %indvars.iv = phi i64 [ %indvars.iv.next, %bb15 ], [ 0, %bb8 ]
131 %tmp10 = icmp slt i64 %indvars.iv, %tmp
132 br i1 %tmp10, label %bb11, label %bb16
135 %tmp12 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
136 %tmp13 = load i32, ptr %tmp12, align 4
137 %tmp14 = add nsw i32 %tmp13, 1
138 store i32 %tmp14, ptr %tmp12, align 4
141 bb15: ; preds = %bb11
142 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
148 bb17: ; preds = %bb4, %bb16
151 bb18: ; preds = %bb17
152 %indvars.iv.next2 = add nuw nsw i64 %indvars.iv1, 1