1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; Just run it through opt, no passes needed.
3; This tests debug intrinsics, so we must explicitly disable records.
4; RUN: opt < %s -S --write-experimental-debuginfo=false | FileCheck %s
5
6; ModuleID = 'various_ir_values.c'
7source_filename = "various_ir_values.c"
8target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
9target triple = "x86_64-unknown-linux-gnu"
10
11; Function Attrs: nounwind uwtable
12define dso_local void @foo(ptr %A) #0 !dbg !7 {
13; CHECK-LABEL: @foo(
14; CHECK-NEXT:  entry:
15; CHECK-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8, !DIAssignID [[DIASSIGNID16:![0-9]+]]
16; CHECK-NEXT:    [[I:%.*]] = alloca i32, align 4
17; CHECK-NEXT:    tail call void @llvm.dbg.assign(metadata i1 undef, metadata [[META13:![0-9]+]], metadata !DIExpression(), metadata [[DIASSIGNID16]], metadata ptr [[A_ADDR]], metadata !DIExpression()), !dbg [[DBG17:![0-9]+]]
18; CHECK-NEXT:    store ptr [[A:%.*]], ptr [[A_ADDR]], align 8, !tbaa [[TBAA18:![0-9]+]]
19; CHECK-NEXT:    tail call void @llvm.dbg.declare(metadata ptr [[A_ADDR]], metadata [[META13]], metadata !DIExpression()), !dbg [[DBG17]]
20; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 4, ptr [[I]]) #[[ATTR3:[0-9]+]], !dbg [[DBG22:![0-9]+]]
21; CHECK-NEXT:    tail call void @llvm.dbg.declare(metadata ptr [[I]], metadata [[META14:![0-9]+]], metadata !DIExpression()), !dbg [[DBG23:![0-9]+]]
22; CHECK-NEXT:    store i32 0, ptr [[I]], align 4, !dbg [[DBG23]], !tbaa [[TBAA24:![0-9]+]]
23; CHECK-NEXT:    br label [[FOR_COND:%.*]], !dbg [[DBG22]]
24; CHECK:       for.cond:
25; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG26:![0-9]+]], !tbaa [[TBAA24]]
26; CHECK-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG28:![0-9]+]], !tbaa [[TBAA18]]
27; CHECK-NEXT:    [[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4, !dbg [[DBG29:![0-9]+]], !tbaa [[TBAA24]]
28; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], [[TMP2]], !dbg [[DBG30:![0-9]+]]
29; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]], !dbg [[DBG31:![0-9]+]], !prof [[PROF32:![0-9]+]]
30; CHECK:       for.cond.cleanup:
31; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 4, ptr [[I]]) #[[ATTR3]], !dbg [[DBG33:![0-9]+]]
32; CHECK-NEXT:    br label [[FOR_END:%.*]]
33; CHECK:       for.body:
34; CHECK-NEXT:    [[TMP3:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG34:![0-9]+]], !tbaa [[TBAA18]]
35; CHECK-NEXT:    [[TMP4:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG35:![0-9]+]], !tbaa [[TBAA24]]
36; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP4]] to i64, !dbg [[DBG34]]
37; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 [[IDXPROM]], !dbg [[DBG34]]
38; CHECK-NEXT:    store i32 0, ptr [[ARRAYIDX]], align 4, !dbg [[DBG36:![0-9]+]], !tbaa [[TBAA24]]
39; CHECK-NEXT:    br label [[FOR_INC:%.*]], !dbg [[DBG34]]
40; CHECK:       for.inc:
41; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG37:![0-9]+]], !tbaa [[TBAA24]]
42; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP5]], 1, !dbg [[DBG37]]
43; CHECK-NEXT:    store i32 [[INC]], ptr [[I]], align 4, !dbg [[DBG37]], !tbaa [[TBAA24]]
44; CHECK-NEXT:    br label [[FOR_COND]], !dbg [[DBG33]], !llvm.loop [[LOOP38:![0-9]+]]
45; CHECK:       for.end:
46; CHECK-NEXT:    ret void, !dbg [[DBG40:![0-9]+]]
47;
48entry:
49  %A.addr = alloca ptr, align 8, !DIAssignID !62
50  %i = alloca i32, align 4
51  tail call void @llvm.dbg.assign(metadata i1 undef, metadata !13, metadata !DIExpression(), metadata !62, metadata ptr %A.addr, metadata !DIExpression()), !dbg !20
52  store ptr %A, ptr %A.addr, align 8, !tbaa !16
53  tail call void @llvm.dbg.declare(metadata ptr %A.addr, metadata !13, metadata !DIExpression()), !dbg !20
54  call void @llvm.lifetime.start.p0(i64 4, ptr %i) #3, !dbg !21
55  tail call void @llvm.dbg.declare(metadata ptr %i, metadata !14, metadata !DIExpression()), !dbg !22
56  store i32 0, ptr %i, align 4, !dbg !22, !tbaa !23
57  br label %for.cond, !dbg !21
58
59for.cond:                                         ; preds = %for.inc, %entry
60  %0 = load i32, ptr %i, align 4, !dbg !25, !tbaa !23
61  %1 = load ptr, ptr %A.addr, align 8, !dbg !27, !tbaa !16
62  %2 = load i32, ptr %1, align 4, !dbg !28, !tbaa !23
63  %cmp = icmp slt i32 %0, %2, !dbg !29
64  br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !30, !prof !61
65
66for.cond.cleanup:                                 ; preds = %for.cond
67  call void @llvm.lifetime.end.p0(i64 4, ptr %i) #3, !dbg !31
68  br label %for.end
69
70for.body:                                         ; preds = %for.cond
71  %3 = load ptr, ptr %A.addr, align 8, !dbg !32, !tbaa !16
72  %4 = load i32, ptr %i, align 4, !dbg !33, !tbaa !23
73  %idxprom = sext i32 %4 to i64, !dbg !32
74  %arrayidx = getelementptr inbounds i32, ptr %3, i64 %idxprom, !dbg !32
75  store i32 0, ptr %arrayidx, align 4, !dbg !34, !tbaa !23
76  br label %for.inc, !dbg !32
77
78for.inc:                                          ; preds = %for.body
79  %5 = load i32, ptr %i, align 4, !dbg !35, !tbaa !23
80  %inc = add nsw i32 %5, 1, !dbg !35
81  store i32 %inc, ptr %i, align 4, !dbg !35, !tbaa !23
82  br label %for.cond, !dbg !31, !llvm.loop !36
83
84for.end:                                          ; preds = %for.cond.cleanup
85  ret void, !dbg !38
86}
87
88; Function Attrs: nounwind readnone speculatable willreturn
89declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
90
91; Function Attrs: argmemonly nounwind willreturn
92declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2
93
94; Function Attrs: argmemonly nounwind willreturn
95declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2
96
97; Function Attrs: nounwind uwtable
98define dso_local void @bar(ptr %A) #0 !dbg !39 {
99; CHECK-LABEL: @bar(
100; CHECK-NEXT:  entry:
101; CHECK-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8
102; CHECK-NEXT:    [[I:%.*]] = alloca i32, align 4
103; CHECK-NEXT:    store ptr [[A:%.*]], ptr [[A_ADDR]], align 8, !tbaa [[TBAA18]]
104; CHECK-NEXT:    tail call void @llvm.dbg.declare(metadata ptr [[A_ADDR]], metadata [[META43:![0-9]+]], metadata !DIExpression()), !dbg [[DBG46:![0-9]+]]
105; CHECK-NEXT:    call void @llvm.lifetime.start.p0(i64 4, ptr [[I]]) #[[ATTR3]], !dbg [[DBG47:![0-9]+]]
106; CHECK-NEXT:    tail call void @llvm.dbg.declare(metadata ptr [[I]], metadata [[META44:![0-9]+]], metadata !DIExpression()), !dbg [[DBG48:![0-9]+]]
107; CHECK-NEXT:    store i32 0, ptr [[I]], align 4, !dbg [[DBG48]], !tbaa [[TBAA24]]
108; CHECK-NEXT:    br label [[FOR_COND:%.*]], !dbg [[DBG47]]
109; CHECK:       for.cond:
110; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG49:![0-9]+]], !tbaa [[TBAA24]]
111; CHECK-NEXT:    [[TMP1:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG51:![0-9]+]], !tbaa [[TBAA18]]
112; CHECK-NEXT:    [[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4, !dbg [[DBG52:![0-9]+]], !tbaa [[TBAA24]]
113; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[TMP0]], [[TMP2]], !dbg [[DBG53:![0-9]+]]
114; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]], !dbg [[DBG54:![0-9]+]]
115; CHECK:       for.cond.cleanup:
116; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 4, ptr [[I]]) #[[ATTR3]], !dbg [[DBG55:![0-9]+]]
117; CHECK-NEXT:    br label [[FOR_END:%.*]]
118; CHECK:       for.body:
119; CHECK-NEXT:    [[TMP3:%.*]] = load ptr, ptr [[A_ADDR]], align 8, !dbg [[DBG56:![0-9]+]], !tbaa [[TBAA18]]
120; CHECK-NEXT:    [[TMP4:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG57:![0-9]+]], !tbaa [[TBAA24]]
121; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[TMP4]] to i64, !dbg [[DBG56]]
122; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 [[IDXPROM]], !dbg [[DBG56]]
123; CHECK-NEXT:    store i32 0, ptr [[ARRAYIDX]], align 4, !dbg [[DBG58:![0-9]+]], !tbaa [[TBAA24]]
124; CHECK-NEXT:    br label [[FOR_INC:%.*]], !dbg [[DBG56]]
125; CHECK:       for.inc:
126; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[I]], align 4, !dbg [[DBG59:![0-9]+]], !tbaa [[TBAA24]]
127; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[TMP5]], 1, !dbg [[DBG59]]
128; CHECK-NEXT:    store i32 [[INC]], ptr [[I]], align 4, !dbg [[DBG59]], !tbaa [[TBAA24]]
129; CHECK-NEXT:    br label [[FOR_COND]], !dbg [[DBG55]], !llvm.loop [[LOOP60:![0-9]+]]
130; CHECK:       for.end:
131; CHECK-NEXT:    ret void, !dbg [[DBG62:![0-9]+]]
132;
133entry:
134  %A.addr = alloca ptr, align 8
135  %i = alloca i32, align 4
136  store ptr %A, ptr %A.addr, align 8, !tbaa !16
137  tail call void @llvm.dbg.declare(metadata ptr %A.addr, metadata !41, metadata !DIExpression()), !dbg !44
138  call void @llvm.lifetime.start.p0(i64 4, ptr %i) #3, !dbg !45
139  tail call void @llvm.dbg.declare(metadata ptr %i, metadata !42, metadata !DIExpression()), !dbg !46
140  store i32 0, ptr %i, align 4, !dbg !46, !tbaa !23
141  br label %for.cond, !dbg !45
142
143for.cond:                                         ; preds = %for.inc, %entry
144  %0 = load i32, ptr %i, align 4, !dbg !47, !tbaa !23
145  %1 = load ptr, ptr %A.addr, align 8, !dbg !49, !tbaa !16
146  %2 = load i32, ptr %1, align 4, !dbg !50, !tbaa !23
147  %cmp = icmp slt i32 %0, %2, !dbg !51
148  br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !52
149
150for.cond.cleanup:                                 ; preds = %for.cond
151  call void @llvm.lifetime.end.p0(i64 4, ptr %i) #3, !dbg !53
152  br label %for.end
153
154for.body:                                         ; preds = %for.cond
155  %3 = load ptr, ptr %A.addr, align 8, !dbg !54, !tbaa !16
156  %4 = load i32, ptr %i, align 4, !dbg !55, !tbaa !23
157  %idxprom = sext i32 %4 to i64, !dbg !54
158  %arrayidx = getelementptr inbounds i32, ptr %3, i64 %idxprom, !dbg !54
159  store i32 0, ptr %arrayidx, align 4, !dbg !56, !tbaa !23
160  br label %for.inc, !dbg !54
161
162for.inc:                                          ; preds = %for.body
163  %5 = load i32, ptr %i, align 4, !dbg !57, !tbaa !23
164  %inc = add nsw i32 %5, 1, !dbg !57
165  store i32 %inc, ptr %i, align 4, !dbg !57, !tbaa !23
166  br label %for.cond, !dbg !53, !llvm.loop !58
167
168for.end:                                          ; preds = %for.cond.cleanup
169  ret void, !dbg !60
170}
171
172declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
173
174attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "denormal-fp-math"="ieee,ieee" "denormal-fp-math-f32"="ieee,ieee" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
175attributes #1 = { nounwind readnone speculatable willreturn }
176attributes #2 = { argmemonly nounwind willreturn }
177attributes #3 = { nounwind }
178
179!llvm.dbg.cu = !{!0}
180!llvm.module.flags = !{!3, !4, !5}
181!llvm.ident = !{!6}
182
183!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 (git@github.com:llvm/llvm-project.git 1d5da8cd30fce1c0a2c2fa6ba656dbfaa36192c8)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
184!1 = !DIFile(filename: "various_ir_values.c", directory: "/data/build/llvm-project")
185!2 = !{}
186!3 = !{i32 7, !"Dwarf Version", i32 4}
187!4 = !{i32 2, !"Debug Info Version", i32 3}
188!5 = !{i32 1, !"wchar_size", i32 4}
189!6 = !{!"clang version 11.0.0 (git@github.com:llvm/llvm-project.git 1d5da8cd30fce1c0a2c2fa6ba656dbfaa36192c8)"}
190!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
191!8 = !DISubroutineType(types: !9)
192!9 = !{null, !10}
193!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
194!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
195!12 = !{!13, !14}
196!13 = !DILocalVariable(name: "A", arg: 1, scope: !7, file: !1, line: 1, type: !10)
197!14 = !DILocalVariable(name: "i", scope: !15, file: !1, line: 3, type: !11)
198!15 = distinct !DILexicalBlock(scope: !7, file: !1, line: 3, column: 3)
199!16 = !{!17, !17, i64 0}
200!17 = !{!"any pointer", !18, i64 0}
201!18 = !{!"omnipotent char", !19, i64 0}
202!19 = !{!"Simple C/C++ TBAA"}
203!20 = !DILocation(line: 1, column: 15, scope: !7)
204!21 = !DILocation(line: 3, column: 8, scope: !15)
205!22 = !DILocation(line: 3, column: 12, scope: !15)
206!23 = !{!24, !24, i64 0}
207!24 = !{!"int", !18, i64 0}
208!25 = !DILocation(line: 3, column: 19, scope: !26)
209!26 = distinct !DILexicalBlock(scope: !15, file: !1, line: 3, column: 3)
210!27 = !DILocation(line: 3, column: 24, scope: !26)
211!28 = !DILocation(line: 3, column: 23, scope: !26)
212!29 = !DILocation(line: 3, column: 21, scope: !26)
213!30 = !DILocation(line: 3, column: 3, scope: !15)
214!31 = !DILocation(line: 3, column: 3, scope: !26)
215!32 = !DILocation(line: 4, column: 5, scope: !26)
216!33 = !DILocation(line: 4, column: 7, scope: !26)
217!34 = !DILocation(line: 4, column: 10, scope: !26)
218!35 = !DILocation(line: 3, column: 27, scope: !26)
219!36 = distinct !{!36, !30, !37}
220!37 = !DILocation(line: 4, column: 12, scope: !15)
221!38 = !DILocation(line: 5, column: 1, scope: !7)
222!39 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 7, type: !8, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !40)
223!40 = !{!41, !42}
224!41 = !DILocalVariable(name: "A", arg: 1, scope: !39, file: !1, line: 7, type: !10)
225!42 = !DILocalVariable(name: "i", scope: !43, file: !1, line: 9, type: !11)
226!43 = distinct !DILexicalBlock(scope: !39, file: !1, line: 9, column: 3)
227!44 = !DILocation(line: 7, column: 15, scope: !39)
228!45 = !DILocation(line: 9, column: 8, scope: !43)
229!46 = !DILocation(line: 9, column: 12, scope: !43)
230!47 = !DILocation(line: 9, column: 19, scope: !48)
231!48 = distinct !DILexicalBlock(scope: !43, file: !1, line: 9, column: 3)
232!49 = !DILocation(line: 9, column: 24, scope: !48)
233!50 = !DILocation(line: 9, column: 23, scope: !48)
234!51 = !DILocation(line: 9, column: 21, scope: !48)
235!52 = !DILocation(line: 9, column: 3, scope: !43)
236!53 = !DILocation(line: 9, column: 3, scope: !48)
237!54 = !DILocation(line: 10, column: 5, scope: !48)
238!55 = !DILocation(line: 10, column: 7, scope: !48)
239!56 = !DILocation(line: 10, column: 10, scope: !48)
240!57 = !DILocation(line: 9, column: 27, scope: !48)
241!58 = distinct !{!58, !52, !59}
242!59 = !DILocation(line: 10, column: 12, scope: !43)
243!60 = !DILocation(line: 11, column: 1, scope: !39)
244!61 = !{!"branch_weights", i32 1, i32 1048575}
245!62 = distinct !DIAssignID()
246