1 ; RUN: opt %loadPolly -polly-detect-unprofitable -basicaa -polly-analyze-ir -disable-polly-intra-scop-scalar-to-array -analyze < %s | FileCheck %s
2 ; RUN: opt %loadPolly -polly-detect-unprofitable -basicaa -polly-analyze-ir -disable-polly-intra-scop-scalar-to-array -analyze < %s | FileCheck %s
4 ; ModuleID = 'scalar_to_array.ll'
5 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"
6 target triple = "x86_64-unknown-linux-gnu"
8 @A = common global [1024 x float] zeroinitializer, align 8
11 ; Function Attrs: nounwind
12 define i32 @empty() #0 {
17 for.cond: ; preds = %for.inc, %entry
18 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %entry ]
19 %exitcond = icmp ne i64 %indvar, 1024
20 br i1 %exitcond, label %for.body, label %return
22 for.body: ; preds = %for.cond
25 for.inc: ; preds = %for.body
26 %indvar.next = add i64 %indvar, 1
29 return: ; preds = %for.cond
35 ; Function Attrs: nounwind
36 define i32 @array_access() #0 {
41 for.cond: ; preds = %for.inc, %entry
42 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %entry ]
43 %exitcond = icmp ne i64 %indvar, 1024
44 br i1 %exitcond, label %for.body, label %return
46 for.body: ; preds = %for.cond
47 %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
48 %float = uitofp i64 %indvar to float
49 store float %float, float* %arrayidx
53 ; CHECK: Write A[{0,+,4}<%for.cond>]
55 for.inc: ; preds = %for.body
56 %indvar.next = add i64 %indvar, 1
59 return: ; preds = %for.cond
64 ; Function Attrs: nounwind
65 ; CHECK: intra_scop_dep
66 define i32 @intra_scop_dep() #0 {
71 for.cond: ; preds = %for.inc, %entry
72 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %entry ]
73 %exitcond = icmp ne i64 %indvar, 1024
74 br i1 %exitcond, label %for.body.a, label %return
76 for.body.a: ; preds = %for.cond
77 %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
78 %scalar = load float* %arrayidx
80 ; CHECK: BB: for.body.a
81 ; CHECK: Read A[{0,+,4}<%for.cond>]
82 ; CHECK: Write scalar[0]
84 for.body.b: ; preds = %for.body.a
85 %arrayidx2 = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
86 %float = uitofp i64 %indvar to float
87 %sum = fadd float %scalar, %float
88 store float %sum, float* %arrayidx2
90 ; CHECK: BB: for.body.b
91 ; CHECK: Read scalar[0]
92 ; CHECK: Write A[{0,+,4}<%for.cond>]
94 for.inc: ; preds = %for.body.b
95 %indvar.next = add i64 %indvar, 1
98 return: ; preds = %for.cond
103 ; It is not possible to have a scop which accesses a scalar element that is
104 ; a global variable. All global variables are pointers containing possibly
105 ; a single element. Hence they do not need to be handled anyways.
106 ; Please note that this is still required when scalar to array rewritting is
109 ; CHECK: use_after_scop
110 ; Function Attrs: nounwind
111 define i32 @use_after_scop() #0 {
113 %scalar.s2a = alloca float
117 for.head: ; preds = %for.inc, %entry
118 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %entry ]
121 for.body: ; preds = %for.head
122 %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
123 %scalar = load float* %arrayidx
124 store float %scalar, float* %scalar.s2a
125 ; Escaped uses are still required to be rewritten to stack variable.
126 ; CHECK: BB: for.body
127 ; CHECK: Read A[{0,+,4}<%for.head>]
128 ; CHECK: Write scalar.s2a[0]
131 for.inc: ; preds = %for.body
132 %indvar.next = add i64 %indvar, 1
133 %exitcond = icmp ne i64 %indvar, 1024
134 br i1 %exitcond, label %for.head, label %for.after
136 for.after: ; preds = %for.inc
137 %scalar.loadoutside = load float* %scalar.s2a
139 %return_value = fptosi float %scalar.loadoutside to i32
142 return: ; preds = %for.after
143 ret i32 %return_value
146 ; We currently do not transform scalar references, that have only read accesses
147 ; in the scop. There are two reasons for this:
149 ; o We don't introduce additional memory references which may yield to compile
151 ; o For integer values, such a translation may block the use of scalar
152 ; evolution on those values.
155 ; Function Attrs: nounwind
156 define i32 @before_scop() #0 {
160 preheader: ; preds = %entry
161 %scalar = fadd float 4.000000e+00, 5.000000e+00
165 for.cond: ; preds = %for.inc, %preheader
166 %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %preheader ]
167 %exitcond = icmp ne i64 %indvar, 1024
168 br i1 %exitcond, label %for.body, label %return
170 for.body: ; preds = %for.cond
171 %arrayidx = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
172 store float %scalar, float* %arrayidx
174 ; CHECK: BB: for.body
175 ; CHECK: Write A[{0,+,4}<%for.cond>]
177 for.inc: ; preds = %for.body
178 %indvar.next = add i64 %indvar, 1
181 return: ; preds = %for.cond
186 attributes #0 = { nounwind }