blob: 888deccb338bc23557108f38bcc304899b693037 [file] [log] [blame]
Sanjay Patelb653de12014-09-10 17:58:16 +00001; RUN: opt < %s -O2 -force-vector-interleave=2 -force-vector-width=4 -debug-only=loop-vectorize -stats -S 2>&1 | FileCheck %s
NAKAMURA Takumi0ec19182014-04-15 10:12:47 +00002; REQUIRES: asserts
Alexey Bataevb97f9e82014-04-15 09:37:30 +00003
4; Loop from "rotated"
5; CHECK: LV: Loop hints: force=enabled
6; Loop from "nonrotated"
7; CHECK: LV: Loop hints: force=enabled
8; No more loops in the module
9; CHECK-NOT: LV: Loop hints: force=
10; In total only 1 loop should be rotated.
11; CHECK: 1 loop-rotate
12
13target 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-S128"
Alexey Bataevb97f9e82014-04-15 09:37:30 +000014
15; See http://reviews.llvm.org/D3348 for details.
16
17;
18; Test #1
19;
Eli Bendersky5d5e18d2014-06-25 15:41:00 +000020; Ensure that "llvm.loop.vectorize.enable" metadata was not lost prior to LoopVectorize pass.
Alexey Bataevb97f9e82014-04-15 09:37:30 +000021; In past LoopRotate was clearing that metadata.
22;
23; The source C code is:
24; void rotated(float *a, int size)
25; {
26; int t = 0;
27; #pragma omp simd
28; for (int i = 0; i < size; ++i) {
29; a[i] = a[i-5] * a[i+2];
30; ++t;
31; }
32;}
33
34define void @rotated(float* nocapture %a, i64 %size) {
35entry:
36 %cmp1 = icmp sgt i64 %size, 0
37 br i1 %cmp1, label %for.header, label %for.end
38
39for.header:
40 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
41 %cmp2 = icmp sgt i64 %indvars.iv, %size
42 br i1 %cmp2, label %for.end, label %for.body
43
44for.body:
45
46 %0 = add nsw i64 %indvars.iv, -5
David Blaikie79e6c742015-02-27 19:29:02 +000047 %arrayidx = getelementptr inbounds float, float* %a, i64 %0
David Blaikiea79ac142015-02-27 21:17:42 +000048 %1 = load float, float* %arrayidx, align 4, !llvm.mem.parallel_loop_access !1
Alexey Bataevb97f9e82014-04-15 09:37:30 +000049 %2 = add nsw i64 %indvars.iv, 2
David Blaikie79e6c742015-02-27 19:29:02 +000050 %arrayidx2 = getelementptr inbounds float, float* %a, i64 %2
David Blaikiea79ac142015-02-27 21:17:42 +000051 %3 = load float, float* %arrayidx2, align 4, !llvm.mem.parallel_loop_access !1
Alexey Bataevb97f9e82014-04-15 09:37:30 +000052 %mul = fmul float %1, %3
David Blaikie79e6c742015-02-27 19:29:02 +000053 %arrayidx4 = getelementptr inbounds float, float* %a, i64 %indvars.iv
Alexey Bataevb97f9e82014-04-15 09:37:30 +000054 store float %mul, float* %arrayidx4, align 4, !llvm.mem.parallel_loop_access !1
55
56 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
57 br label %for.header, !llvm.loop !1
58
59for.end:
60 ret void
61}
62
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000063!1 = !{!1, !2}
64!2 = !{!"llvm.loop.vectorize.enable", i1 true}
Alexey Bataevb97f9e82014-04-15 09:37:30 +000065
66;
67; Test #2
68;
Eli Bendersky5d5e18d2014-06-25 15:41:00 +000069; Ensure that "llvm.loop.vectorize.enable" metadata was not lost even
Alexey Bataevb97f9e82014-04-15 09:37:30 +000070; if loop was not rotated (see http://reviews.llvm.org/D3348#comment-4).
71;
72define i32 @nonrotated(i32 %a) {
73entry:
74 br label %loop_cond
75loop_cond:
76 %indx = phi i32 [ 1, %entry ], [ %inc, %loop_inc ]
77 %cmp = icmp ne i32 %indx, %a
78 br i1 %cmp, label %return, label %loop_inc
79loop_inc:
80 %inc = add i32 %indx, 1
81 br label %loop_cond, !llvm.loop !3
82return:
83 ret i32 0
84}
85
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000086!3 = !{!3, !4}
87!4 = !{!"llvm.loop.vectorize.enable", i1 true}