1 ; RUN: opt %loadPolly -polly-detect-unprofitable -basicaa -polly-independent < %s -S | FileCheck %s
2 ; RUN: opt %loadPolly -polly-detect-unprofitable -basicaa -polly-independent < %s -S | FileCheck %s
3 ; RUN: opt %loadPolly -polly-detect-unprofitable -basicaa -polly-independent -disable-polly-intra-scop-scalar-to-array -S < %s | FileCheck %s -check-prefix=SCALARACCESS
4 ; RUN: opt %loadPolly -polly-detect-unprofitable -basicaa -polly-independent -disable-polly-intra-scop-scalar-to-array < %s -S | FileCheck %s -check-prefix=SCALARACCESS
6 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
7 target triple = "x86_64-unknown-linux-gnu"
9 @A = common global [1024 x float] zeroinitializer, align 8
11 define i32 @empty() nounwind {
17 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %entry ]
18 %exitcond = icmp ne i64 %indvar, 1024
19 br i1 %exitcond, label %for.body, label %return
25 %indvar.next = add i64 %indvar, 1
34 ; CHECK: @array_access()
35 define i32 @array_access() nounwind {
41 ; SCALARACCESS: entry:
42 ; SCALARACCESS-NOT: alloca
45 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %entry ]
46 %exitcond = icmp ne i64 %indvar, 1024
47 br i1 %exitcond, label %for.body, label %return
50 %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
51 %float = uitofp i64 %indvar to float
52 store float %float, float* %arrayidx
56 ; CHECK: %float = uitofp i64 %indvar to float
57 ; CHECK: store float %float, float* %arrayidx
58 ; SCALARACCESS: for.body:
59 ; SCALARACCESS: %float = uitofp i64 %indvar to float
60 ; SCALARACCESS: store float %float, float* %arrayidx
63 %indvar.next = add i64 %indvar, 1
71 ; CHECK: @intra_scop_dep()
72 define i32 @intra_scop_dep() nounwind {
78 ; CHECK: %scalar.s2a = alloca float
80 ; SCALARACCESS: entry:
81 ; SCALARACCESS-NOT: alloca
85 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %entry ]
86 %exitcond = icmp ne i64 %indvar, 1024
87 br i1 %exitcond, label %for.body.a, label %return
90 %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
91 %scalar = load float* %arrayidx
95 ; CHECK: %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
96 ; CHECK: %scalar = load float* %arrayidx
97 ; CHECK: store float %scalar, float* %scalar.s2a
98 ; CHECK: br label %for.body.b
100 ; SCALARACCESS: for.body.a:
101 ; SCALARACCESS: %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
102 ; SCALARACCESS: %scalar = load float* %arrayidx
103 ; SCALARACCESS-NOT: store
104 ; SCALARACCESS: br label %for.body.b
107 %arrayidx2 = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
108 %float = uitofp i64 %indvar to float
109 %sum = fadd float %scalar, %float
110 store float %sum, float* %arrayidx2
114 ; CHECK: %arrayidx2 = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
115 ; CHECK: %float = uitofp i64 %indvar to float
116 ; CHECK: %scalar.loadarray = load float* %scalar.s2a
117 ; CHECK: %sum = fadd float %scalar.loadarray, %float
118 ; CHECK: store float %sum, float* %arrayidx2
119 ; CHECK: br label %for.inc
121 ; SCALARACCESS: for.body.b:
122 ; SCALARACCESS: %arrayidx2 = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
123 ; SCALARACCESS: %float = uitofp i64 %indvar to float
124 ; SCALARACCESS-NOT: load
125 ; SCALARACCESS: %sum = fadd float %scalar, %float
126 ; SCALARACCESS: store float %sum, float* %arrayidx2
127 ; SCALARACCESS: br label %for.inc
130 %indvar.next = add i64 %indvar, 1
138 ; It is not possible to have a scop which accesses a scalar element that is
139 ; a global variable. All global variables are pointers containing possibly
140 ; a single element. Hence they do not need to be handled anyways.
141 ; Please note that this is still required when scalar to array rewritting is
144 ; CHECK: @use_after_scop()
145 define i32 @use_after_scop() nounwind {
150 ; CHECK: %scalar.s2a = alloca float
153 ; SCALARACCESS: entry:
154 ; SCALARACCESS: %scalar.s2a = alloca float
155 ; SCALARACCESS: fence
158 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %entry ]
162 %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
163 %scalar = load float* %arrayidx
167 ; CHECK: %scalar = load float* %arrayidx
168 ; CHECK: store float %scalar, float* %scalar.s2a
170 ; SCALARACCESS: for.body:
171 ; SCALARACCESS: %scalar = load float* %arrayidx
172 ; SCALARACCESS: store float %scalar, float* %scalar.s2a
175 %indvar.next = add i64 %indvar, 1
176 %exitcond = icmp ne i64 %indvar, 1024
177 br i1 %exitcond, label %for.head, label %for.after
181 %return_value = fptosi float %scalar to i32
185 ; CHECK: %scalar.loadoutside = load float* %scalar.s2a
186 ; CHECK: fence seq_cst
187 ; CHECK: %return_value = fptosi float %scalar.loadoutside to i32
189 ; SCALARACCESS: for.after:
190 ; SCALARACCESS: %scalar.loadoutside = load float* %scalar.s2a
191 ; SCALARACCESS: fence seq_cst
192 ; SCALARACCESS: %return_value = fptosi float %scalar.loadoutside to i32
195 ret i32 %return_value
198 ; We currently do not transform scalar references, that have only read accesses
199 ; in the scop. There are two reasons for this:
201 ; o We don't introduce additional memory references which may yield to compile
203 ; o For integer values, such a translation may block the use of scalar
204 ; evolution on those values.
206 ; CHECK: @before_scop()
207 define i32 @before_scop() nounwind {
212 %scalar = fadd float 4.0, 5.0
217 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %preheader ]
218 %exitcond = icmp ne i64 %indvar, 1024
219 br i1 %exitcond, label %for.body, label %return
222 %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
223 store float %scalar, float* %arrayidx
227 ; CHECK: store float %scalar, float* %arrayidx
229 ; SCALARACCESS: for.body:
230 ; SCALARACCESS: store float %scalar, float* %arrayidx
233 %indvar.next = add i64 %indvar, 1
241 ; Currently not working
242 ; CHECK: @param_before_scop(
243 define i32 @param_before_scop(float %scalar) nounwind {
251 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %entry ]
252 %exitcond = icmp ne i64 %indvar, 1024
253 br i1 %exitcond, label %for.body, label %return
256 %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
257 store float %scalar, float* %arrayidx
261 ; CHECK: store float %scalar, float* %arrayidx
264 %indvar.next = add i64 %indvar, 1