Fix Polly
[polly-mirror.git] / test / Isl / CodeGen / OpenMP / single_loop.ll
blob6de65bd8ad98bc2eca4fe0600d49db8aa7820922
1 ; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
2 ; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen -S -verify-dom-info < %s | FileCheck %s -check-prefix=IR
4 ; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-import-jscop -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST-STRIDE4
5 ; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-import-jscop -polly-codegen -S < %s | FileCheck %s -check-prefix=IR-STRIDE4
7 ; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen -polly-omp-backend=LLVM -polly-scheduling=static -polly-scheduling-chunksize=43 -S -verify-dom-info < %s | FileCheck %s -check-prefix=LIBOMP-IR
8 ; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen -polly-omp-backend=LLVM -polly-scheduling=dynamic -S -verify-dom-info < %s | FileCheck %s -check-prefix=LIBOMP-IR-DYNAMIC
9 ; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen -polly-omp-backend=LLVM -polly-scheduling=dynamic -polly-scheduling-chunksize=4 -S -verify-dom-info < %s | FileCheck %s -check-prefix=LIBOMP-IR-DYNAMIC-FOUR
10 ; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-import-jscop -polly-codegen -polly-omp-backend=LLVM -S < %s | FileCheck %s -check-prefix=LIBOMP-IR-STRIDE4
12 ; This extensive test case tests the creation of the full set of OpenMP calls
13 ; as well as the subfunction creation using a trivial loop as example.
15 ; #define N 1024
16 ; float A[N];
18 ; void single_parallel_loop(void) {
19 ;   for (long i = 0; i < N; i++)
20 ;     A[i] = 1;
21 ; }
23 ; AST: #pragma simd
24 ; AST: #pragma omp parallel for
25 ; AST: for (int c0 = 0; c0 <= 1023; c0 += 1)
26 ; AST:   Stmt_S(c0);
28 ; AST-STRIDE4: #pragma omp parallel for
29 ; AST-STRIDE4: for (int c0 = 0; c0 <= 1023; c0 += 4)
30 ; AST-STRIDE4:   #pragma simd
31 ; AST-STRIDE4:   for (int c1 = c0; c1 <= c0 + 3; c1 += 1)
32 ; AST-STRIDE4:     Stmt_S(c1);
34 ; IR-LABEL: single_parallel_loop()
35 ; IR-NEXT: entry
36 ; IR-NEXT:   %polly.par.userContext = alloca
38 ; IR-LABEL: polly.parallel.for:
39 ; IR-NEXT:   %polly.par.userContext1 = bitcast {}* %polly.par.userContext to i8*
40 ; IR-NEXT:   call void @GOMP_parallel_loop_runtime_start(void (i8*)* @single_parallel_loop_polly_subfn, i8* %polly.par.userContext1, i32 0, i64 0, i64 1024, i64 1)
41 ; IR-NEXT:   call void @single_parallel_loop_polly_subfn(i8* %polly.par.userContext1)
42 ; IR-NEXT:   call void @GOMP_parallel_end()
43 ; IR-NEXT:   br label %polly.exiting
45 ; IR: define internal void @single_parallel_loop_polly_subfn(i8* %polly.par.userContext) #1
46 ; IR-LABEL: polly.par.setup:
47 ; IR-NEXT:   %polly.par.LBPtr = alloca i64
48 ; IR-NEXT:   %polly.par.UBPtr = alloca i64
49 ; IR-NEXT:   %polly.par.userContext1 =
50 ; IR:   br label %polly.par.checkNext
52 ; IR-LABEL: polly.par.exit:
53 ; IR-NEXT:   call void @GOMP_loop_end_nowait()
54 ; IR-NEXT:   ret void
56 ; IR-LABEL: polly.par.checkNext:
57 ; IR-NEXT:   %[[parnext:[._a-zA-Z0-9]*]] = call i8 @GOMP_loop_runtime_next(i64* %polly.par.LBPtr, i64* %polly.par.UBPtr)
58 ; IR-NEXT:   %[[cmp:[._a-zA-Z0-9]*]] = icmp ne i8 %[[parnext]], 0
59 ; IR-NEXT:   br i1 %[[cmp]], label %polly.par.loadIVBounds, label %polly.par.exit
61 ; IR-LABEL: polly.par.loadIVBounds:
62 ; IR-NEXT:   %polly.par.LB = load i64, i64* %polly.par.LBPtr
63 ; IR-NEXT:   %polly.par.UB = load i64, i64* %polly.par.UBPtr
64 ; IR-NEXT:   %polly.par.UBAdjusted = sub i64 %polly.par.UB, 1
65 ; IR-NEXT:   br label %polly.loop_preheader
67 ; IR-LABEL: polly.loop_exit:
68 ; IR-NEXT:   br label %polly.par.checkNext
70 ; IR-LABEL: polly.loop_header:
71 ; IR-NEXT:   %polly.indvar = phi i64 [ %polly.par.LB, %polly.loop_preheader ], [ %polly.indvar_next, %polly.stmt.S ]
72 ; IR-NEXT:   br label %polly.stmt.S
74 ; IR-LABEL: polly.stmt.S:
75 ; IR-NEXT:   %[[gep:[._a-zA-Z0-9]*]] = getelementptr [1024 x float], [1024 x float]* {{.*}}, i64 0, i64 %polly.indvar
76 ; IR-NEXT:   store float 1.000000e+00, float* %[[gep]]
77 ; IR-NEXT:   %polly.indvar_next = add nsw i64 %polly.indvar, 1
78 ; IR-NEXT:   %polly.loop_cond = icmp sle i64 %polly.indvar_next, %polly.par.UBAdjusted
79 ; IR-NEXT:   br i1 %polly.loop_cond, label %polly.loop_header, label %polly.loop_exit
81 ; IR-LABEL: polly.loop_preheader:
82 ; IR-NEXT:   br label %polly.loop_header
84 ; IR: attributes #1 = { "polly.skip.fn" }
86 ; IR-STRIDE4:   call void @GOMP_parallel_loop_runtime_start(void (i8*)* @single_parallel_loop_polly_subfn, i8* %polly.par.userContext1, i32 0, i64 0, i64 1024, i64 4)
87 ; IR-STRIDE4:  add nsw i64 %polly.indvar, 3
88 ; IR-STRIDE4:  %polly.indvar_next = add nsw i64 %polly.indvar, 4
89 ; IR-STRIDE4   %polly.adjust_ub = sub i64 %polly.par.UBAdjusted, 4
91 ; LIBOMP-IR: %struct.ident_t = type { i32, i32, i32, i32, i8* }
93 ; LIBOMP-IR-LABEL: single_parallel_loop()
94 ; LIBOMP-IR-NEXT: entry
95 ; LIBOMP-IR-NEXT:   %polly.par.userContext = alloca
97 ; LIBOMP-IR-LABEL: polly.parallel.for:
98 ; LIBOMP-IR-NEXT:   %polly.par.userContext1 = bitcast {}* %polly.par.userContext to i8*
99 ; LIBOMP-IR-NEXT:   call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @.loc.dummy, i32 4, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i64, i64, i64, i8*)* @single_parallel_loop_polly_subfn to void (i32*, i32*, ...)*), i64 0, i64 1024, i64 1, i8* %polly.par.userContext1)
100 ; LIBOMP-IR-NEXT:   br label %polly.exiting
102 ; LIBOMP-IR: define internal void @single_parallel_loop_polly_subfn(i32* %polly.kmpc.global_tid, i32* %polly.kmpc.bound_tid, i64 %polly.kmpc.lb, i64 %polly.kmpc.ub, i64 %polly.kmpc.inc, i8* %polly.kmpc.shared)
103 ; LIBOMP-IR-LABEL: polly.par.setup:
104 ; LIBOMP-IR-NEXT:   %polly.par.LBPtr = alloca i64
105 ; LIBOMP-IR-NEXT:   %polly.par.UBPtr = alloca i64
106 ; LIBOMP-IR-NEXT:   %polly.par.lastIterPtr = alloca i32
107 ; LIBOMP-IR-NEXT:   %polly.par.StridePtr = alloca i64
108 ; LIBOMP-IR-NEXT:   %polly.par.userContext = bitcast i8* %polly.kmpc.shared
109 ; LIBOMP-IR-NEXT:   %polly.par.global_tid = load i32, i32* %polly.kmpc.global_tid
110 ; LIBOMP-IR-NEXT:   store i64 %polly.kmpc.lb, i64* %polly.par.LBPtr
111 ; LIBOMP-IR-NEXT:   store i64 %polly.kmpc.ub, i64* %polly.par.UBPtr
112 ; LIBOMP-IR-NEXT:   store i32 0, i32* %polly.par.lastIterPtr
113 ; LIBOMP-IR-NEXT:   store i64 %polly.kmpc.inc, i64* %polly.par.StridePtr
114 ; LIBOMP-IR-NEXT:   %polly.indvar.UBAdjusted = add i64 %polly.kmpc.ub, -1
115 ; LIBOMP-IR-NEXT:   call void @__kmpc_for_static_init_{{[4|8]}}(%struct.ident_t* @.loc.dummy{{[.0-9]*}}, i32 %polly.par.global_tid, i32 33, i32* %polly.par.lastIterPtr, i64* %polly.par.LBPtr, i64* %polly.par.UBPtr, i64* %polly.par.StridePtr, i64 1, i64 43)
116 ; LIBOMP-IR-NEXT:   %polly.indvar.LB = load i64, i64* %polly.par.LBPtr
117 ; LIBOMP-IR-NEXT:   %polly.indvar.UB = load i64, i64* %polly.par.UBPtr
118 ; LIBOMP-IR-NEXT:   %polly.adjustedUBOutOfBounds = icmp slt i64 %polly.indvar.UB, %polly.indvar.UBAdjusted
119 ; LIBOMP-IR-NEXT:   %{{[0-9]+}} = select i1 %polly.adjustedUBOutOfBounds, i64 %polly.indvar.UB, i64 %polly.indvar.UBAdjusted
120 ; LIBOMP-IR-NEXT:   store i64 %{{[0-9]+}}, i64* %polly.par.UBPtr
121 ; LIBOMP-IR-NEXT:   %polly.hasIteration = icmp sle i64 %polly.indvar.LB, %{{[0-9]+}}
122 ; LIBOMP-IR:   br i1 %polly.hasIteration, label %polly.par.loadIVBounds, label %polly.par.exit
124 ; LIBOMP-IR-LABEL: polly.par.exit:
125 ; LIBOMP-IR-NEXT:   call void @__kmpc_for_static_fini(%struct.ident_t* @.loc.dummy, i32 %polly.par.global_tid)
126 ; LIBOMP-IR-NEXT:   ret void
128 ; LIBOMP-IR-LABEL: polly.par.checkNext:
129 ; LIBOMP-IR-NEXT:   br label %polly.par.exit
131 ; LIBOMP-IR-LABEL: polly.par.loadIVBounds:
132 ; LIBOMP-IR-NEXT:   br label %polly.loop_preheader
134 ; LIBOMP-IR-LABEL: polly.loop_exit:
135 ; LIBOMP-IR-NEXT:   br label %polly.par.checkNext
137 ; LIBOMP-IR-LABEL: polly.loop_header:
138 ; LIBOMP-IR-NEXT:   %polly.indvar = phi i64 [ %polly.indvar.LB, %polly.loop_preheader ], [ %polly.indvar_next, %polly.stmt.S ]
139 ; LIBOMP-IR-NEXT:   br label %polly.stmt.S
141 ; LIBOMP-IR-LABEL: polly.stmt.S:
142 ; LIBOMP-IR-NEXT:   %[[gep:[._a-zA-Z0-9]*]] = getelementptr [1024 x float], [1024 x float]* {{.*}}, i64 0, i64 %polly.indvar
143 ; LIBOMP-IR-NEXT:   store float 1.000000e+00, float* %[[gep]]
144 ; LIBOMP-IR-NEXT:   %polly.indvar_next = add nsw i64 %polly.indvar, %polly.kmpc.inc
145 ; LIBOMP-IR-NEXT:   %polly.loop_cond = icmp sle i64 %polly.indvar_next, %{{[0-9]+}}
146 ; LIBOMP-IR-NEXT:   br i1 %polly.loop_cond, label %polly.loop_header, label %polly.loop_exit
148 ; LIBOMP-IR-LABEL: polly.loop_preheader:
149 ; LIBOMP-IR-NEXT:   br label %polly.loop_header
151 ; LIBOMP-IR: attributes #1 = { "polly.skip.fn" }
153 ; LIBOMP-IR-DYNAMIC:   call void @__kmpc_dispatch_init_{{[4|8]}}(%struct.ident_t* @.loc.dummy, i32 %polly.par.global_tid, i32 35, i64 %polly.kmpc.lb, i64 %polly.indvar.UBAdjusted, i64 %polly.kmpc.inc, i64 1)
154 ; LIBOMP-IR-DYNAMIC-NEXT:   %{{[0-9]+}} = call i32 @__kmpc_dispatch_next_{{[4|8]}}(%struct.ident_t* @.loc.dummy, i32 %polly.par.global_tid, i32* %polly.par.lastIterPtr, i64* %polly.par.LBPtr, i64* %polly.par.UBPtr, i64* %polly.par.StridePtr)
155 ; LIBOMP-IR-DYNAMIC-NEXT:   %polly.hasIteration = icmp eq i32 %{{[0-9]+}}, 1
156 ; LIBOMP-IR-DYNAMIC-NEXT:   br i1 %polly.hasIteration, label %polly.par.loadIVBounds, label %polly.par.exit
158 ; LIBOMP-IR-DYNAMIC-LABEL: polly.par.exit:
159 ; LIBOMP-IR-DYNAMIC-NEXT:   ret void
161 ; LIBOMP-IR-DYNAMIC-LABEL: polly.par.checkNext:
162 ; LIBOMP-IR-DYNAMIC-NEXT:   %{{[0-9]+}} = call i32 @__kmpc_dispatch_next_{{[4|8]}}(%struct.ident_t* @.loc.dummy, i32 %polly.par.global_tid, i32* %polly.par.lastIterPtr, i64* %polly.par.LBPtr, i64* %polly.par.UBPtr, i64* %polly.par.StridePtr)
163 ; LIBOMP-IR-DYNAMIC-NEXT:   %polly.hasWork = icmp eq i32 %{{[0-9]+}}, 1
164 ; LIBOMP-IR-DYNAMIC-NEXT:   br i1 %polly.hasWork, label %polly.par.loadIVBounds, label %polly.par.exit
166 ; LIBOMP-IR-DYNAMIC-LABEL: polly.par.loadIVBounds:
167 ; LIBOMP-IR-DYNAMIC-NEXT:   %polly.indvar.LB = load i64, i64* %polly.par.LBPtr
168 ; LIBOMP-IR-DYNAMIC-NEXT:   %polly.indvar.UB = load i64, i64* %polly.par.UBPtr
169 ; LIBOMP-IR-DYNAMIC-NEXT:   br label %polly.loop_preheader
171 ; LIBOMP-IR-DYNAMIC-FOUR:   call void @__kmpc_dispatch_init_{{[4|8]}}(%struct.ident_t* @.loc.dummy, i32 %polly.par.global_tid, i32 35, i64 %polly.kmpc.lb, i64 %polly.indvar.UBAdjusted, i64 %polly.kmpc.inc, i64 4)
173 ; LIBOMP-IR-STRIDE4:     call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @.loc.dummy, i32 4, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i64, i64, i64, i8*)* @single_parallel_loop_polly_subfn to void (i32*, i32*, ...)*), i64 0, i64 1024, i64 4, i8* %polly.par.userContext1)
175 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"
177 @A = common global [1024 x float] zeroinitializer, align 16
179 define void @single_parallel_loop() nounwind {
180 entry:
181   br label %for.i
183 for.i:
184   %indvar = phi i64 [ %indvar.next, %for.inc], [ 0, %entry ]
185   %scevgep = getelementptr [1024 x float], [1024 x float]* @A, i64 0, i64 %indvar
186   %exitcond = icmp ne i64 %indvar, 1024
187   br i1 %exitcond, label %S, label %exit
190   store float 1.0, float* %scevgep
191   br label %for.inc
193 for.inc:
194   %indvar.next = add i64 %indvar, 1
195   br label %for.i
197 exit:
198   ret void