1; RUN: opt -S < %s -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 | FileCheck %s
2
3target 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"
4
5; Make sure we are preserving debug info in the vectorized code.
6
7; CHECK-LABEL: define i32 @f(
8; CHECK: for.body.lr.ph
9; CHECK:   min.iters.check = icmp ult i64 {{.*}}, 2, !dbg !{{[0-9]+}}
10; CHECK: vector.body
11; CHECK:   index {{.*}}, !dbg ![[LOC1:[0-9]+]]
12; CHECK:   getelementptr inbounds i32, i32* %a, {{.*}}, !dbg ![[LOC2:[0-9]+]]
13; CHECK:   getelementptr inbounds i32, i32* %b, {{.*}}, !dbg ![[LOC1]]
14; CHECK:   load <2 x i32>, <2 x i32>* {{.*}}, !dbg ![[LOC1]]
15; CHECK:   add <2 x i32> {{.*}}, !dbg ![[LOC1]]
16; CHECK:   add nuw i64 %index, 2, !dbg ![[LOC1]]
17; CHECK:   icmp eq i64 %index.next, %n.vec, !dbg ![[LOC1]]
18; CHECK: middle.block
19; CHECK:   call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %{{.*}}), !dbg ![[BR_LOC:[0-9]+]]
20; CHECK: for.body
21; CHECK: br i1{{.*}}, label %for.body,{{.*}}, !dbg ![[BR_LOC]],
22
23define i32 @f(i32* nocapture %a, i32* %b, i32 %size) !dbg !4 {
24entry:
25  call void @llvm.dbg.value(metadata i32* %a, metadata !13, metadata !DIExpression()), !dbg !19
26  call void @llvm.dbg.value(metadata i32 %size, metadata !14, metadata !DIExpression()), !dbg !19
27  call void @llvm.dbg.value(metadata i32 0, metadata !15, metadata !DIExpression()), !dbg !20
28  call void @llvm.dbg.value(metadata i32 0, metadata !16, metadata !DIExpression()), !dbg !21
29  %cmp4 = icmp eq i32 %size, 0, !dbg !21
30  br i1 %cmp4, label %for.end, label %for.body.lr.ph, !dbg !21
31
32for.body.lr.ph:                                   ; preds = %entry
33  br label %for.body, !dbg !21
34
35for.body:                                         ; preds = %for.body.lr.ph, %for.body
36  %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]
37  %sum = phi i32 [ 0, %for.body.lr.ph ], [ %sum.next, %for.body ]
38  %arrayidx.1 = getelementptr inbounds i32, i32* %a, i64 %indvars.iv, !dbg !19
39  %arrayidx.2 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv, !dbg !22
40  %l.1 = load i32, i32* %arrayidx.1, align 4, !dbg !22
41  %l.2 = load i32, i32* %arrayidx.2, align 4, !dbg !22
42  %add.1 = add i32 %l.1, %l.2
43  %sum.next = add i32 %add.1, %sum, !dbg !22
44  %indvars.iv.next = add i64 %indvars.iv, 1, !dbg !22
45  call void @llvm.dbg.value(metadata !{null}, metadata !16, metadata !DIExpression()), !dbg !22
46  %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !22
47  %exitcond = icmp ne i32 %lftr.wideiv, %size, !dbg !21
48  br i1 %exitcond, label %for.body, label %for.cond.for.end_crit_edge, !dbg !21
49
50for.cond.for.end_crit_edge:                       ; preds = %for.body
51  %add.lcssa = phi i32 [ %sum.next, %for.body ]
52  call void @llvm.dbg.value(metadata i32 %add.lcssa, metadata !15, metadata !DIExpression()), !dbg !22
53  br label %for.end, !dbg !21
54
55for.end:                                          ; preds = %entry, %for.cond.for.end_crit_edge
56  %sum.0.lcssa = phi i32 [ %add.lcssa, %for.cond.for.end_crit_edge ], [ 0, %entry ]
57  ret i32 %sum.0.lcssa, !dbg !26
58}
59
60define i32 @test_debug_loc_on_branch_in_loop(i32* noalias %src, i32* noalias %dst) {
61; CHECK-LABEL: define i32 @test_debug_loc_on_branch_in_loop(
62; CHECK-LABEL: vector.body:
63; CHECK:        [[LOAD:%.+]] = load <2 x i32>, <2 x i32>* {{.+}}, align 4
64; CHECK-NEXT:   [[CMP:%.+]] = icmp eq <2 x i32> [[LOAD]], <i32 10, i32 10>
65; CHECK-NEXT:   [[XOR:%.+]] = xor <2 x i1> [[CMP:%.+]], <i1 true, i1 true>, !dbg [[LOC3:!.+]]
66; CHECK-NEXT:   [[EXT:%.+]] = extractelement <2 x i1> [[XOR]], i32 0, !dbg [[LOC3]]
67; CHECK-NEXT:   br i1 [[EXT]], label %pred.store.if, label %pred.store.continue
68; CHECK-NOT:  !dbg
69; CHECK-EMPTY:
70; CHECK-NEXT: pred.store.if:
71; CHECK-NEXT:   [[GEP:%.+]] = getelementptr inbounds i32, i32* %dst, i64 {{.+}}, !dbg [[LOC3]]
72; CHECK-NEXT:   store i32 0, i32* [[GEP]], align 4, !dbg [[LOC3]]
73; CHECK-NEXT:   br label %pred.store.continue, !dbg [[LOC3]]
74; CHECK-EMPTY:
75;
76entry:
77  br label %loop.header
78
79loop.header:
80  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
81  %gep.src = getelementptr inbounds i32, i32* %src, i64 %iv
82  %l = load i32, i32* %gep.src, align 4
83  %cmp = icmp eq i32 %l, 10
84  br i1 %cmp, label %loop.latch, label %if.then, !dbg !28
85
86if.then:
87  %gep.dst = getelementptr inbounds i32, i32* %dst, i64 %iv
88  store i32 0, i32* %gep.dst, align 4
89  br label %loop.latch
90
91loop.latch:
92  %iv.next = add nuw nsw i64 %iv, 1
93  %exitcond.not = icmp eq i64 %iv.next, 1000
94  br i1 %exitcond.not, label %exit, label %loop.header
95
96exit:
97  ret i32 0
98}
99
100define i32 @test_different_debug_loc_on_replicate_recipe(i32* noalias %src, i32* noalias %dst) {
101; CHECK-LABEL: define i32 @test_different_debug_loc_on_replicate_recipe(
102; CHECK-LABEL: vector.body:
103; CHECK:        [[LOAD:%.+]] = load <2 x i32>, <2 x i32>* {{.+}}, align 4
104; CHECK-NEXT:   [[CMP:%.+]] = icmp eq <2 x i32> [[LOAD]], <i32 10, i32 10>
105; CHECK-NEXT:   [[XOR:%.+]] = xor <2 x i1> [[CMP:%.+]], <i1 true, i1 true>, !dbg [[LOC4:!.+]]
106; CHECK-NEXT:   [[EXT:%.+]] = extractelement <2 x i1> [[XOR]], i32 0, !dbg [[LOC4]]
107; CHECK-NEXT:   br i1 [[EXT]], label %pred.store.if, label %pred.store.continue
108; CHECK-NOT:  !dbg
109; CHECK-EMPTY:
110; CHECK-NEXT: pred.store.if:
111; CHECK-NEXT:   [[GEP:%.+]] = getelementptr inbounds i32, i32* %dst, i64 {{.+}}, !dbg [[LOC5:!.+]]
112; CHECK-NEXT:   store i32 0, i32* [[GEP]], align 4, !dbg [[LOC5]]
113; CHECK-NEXT:   br label %pred.store.continue, !dbg [[LOC4]]
114; CHECK-EMPTY:
115;
116entry:
117  br label %loop.header
118
119loop.header:
120  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
121  %gep.src = getelementptr inbounds i32, i32* %src, i64 %iv
122  %l = load i32, i32* %gep.src, align 4
123  %cmp = icmp eq i32 %l, 10
124  br i1 %cmp, label %loop.latch, label %if.then, !dbg !33
125
126if.then:
127  %gep.dst = getelementptr inbounds i32, i32* %dst, i64 %iv, !dbg !34
128  store i32 0, i32* %gep.dst, align 4
129  br label %loop.latch
130
131loop.latch:
132  %iv.next = add nuw nsw i64 %iv, 1
133  %exitcond.not = icmp eq i64 %iv.next, 1000
134  br i1 %exitcond.not, label %exit, label %loop.header
135
136exit:
137  ret i32 0
138}
139
140; CHECK: ![[LOC2]] = !DILocation(line: 3
141; CHECK: ![[BR_LOC]] = !DILocation(line: 5,
142; CHECK: ![[LOC1]] = !DILocation(line: 6
143; CHECK: [[LOC3]] = !DILocation(line: 137
144; CHECK: [[LOC4]] = !DILocation(line: 210
145; CHECK: [[LOC5]] = !DILocation(line: 320
146
147
148declare void @llvm.dbg.declare(metadata, metadata, metadata)
149
150declare void @llvm.dbg.value(metadata, metadata, metadata)
151
152!llvm.dbg.cu = !{!0}
153!llvm.module.flags = !{!18, !27}
154
155!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.4 (trunk 185038) (llvm/trunk 185097)", isOptimized: true, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
156!1 = !DIFile(filename: "-", directory: "/Volumes/Data/backedup/dev/os/llvm/debug")
157!2 = !{}
158!4 = distinct !DISubprogram(name: "f", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 3, file: !5, scope: !6, type: !7, retainedNodes: !12)
159!5 = !DIFile(filename: "<stdin>", directory: "/Volumes/Data/backedup/dev/os/llvm/debug")
160!6 = !DIFile(filename: "<stdin>", directory: "/Volumes/Data/backedup/dev/os/llvm/debug")
161!7 = !DISubroutineType(types: !8)
162!8 = !{!9, !10, !11}
163!9 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
164!10 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !9)
165!11 = !DIBasicType(tag: DW_TAG_base_type, name: "unsigned int", size: 32, align: 32, encoding: DW_ATE_unsigned)
166!12 = !{!13, !14, !15, !16}
167!13 = !DILocalVariable(name: "a", line: 3, arg: 1, scope: !4, file: !6, type: !10)
168!14 = !DILocalVariable(name: "size", line: 3, arg: 2, scope: !4, file: !6, type: !11)
169!15 = !DILocalVariable(name: "sum", line: 4, scope: !4, file: !6, type: !11)
170!16 = !DILocalVariable(name: "i", line: 5, scope: !17, file: !6, type: !11)
171!17 = distinct !DILexicalBlock(line: 5, column: 0, file: !5, scope: !4)
172!18 = !{i32 2, !"Dwarf Version", i32 3}
173!19 = !DILocation(line: 3, scope: !4)
174!20 = !DILocation(line: 4, scope: !4)
175!21 = !DILocation(line: 5, scope: !17)
176!22 = !DILocation(line: 6, scope: !17)
177!26 = !DILocation(line: 7, scope: !4)
178!27 = !{i32 1, !"Debug Info Version", i32 3}
179!28 = !DILocation(line: 137, column: 44, scope: !29)
180!29 = distinct !DILexicalBlock(scope: !30, file: !5, line: 137, column: 2)
181!30 = distinct !DISubprogram(name: "Place", scope: !5, file: !5, line: 135, scopeLine: 135, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
182!31 = distinct !DISubprogram(name: "Place", scope: !5, file: !5, line: 135, scopeLine: 135, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
183!32 = distinct !DILexicalBlock(scope: !31, file: !5, line: 137, column: 2)
184!33 = !DILocation(line: 210, column: 44, scope: !32)
185!34 = !DILocation(line: 320, column: 44, scope: !32)
186