xref: /llvm-project/llvm/test/Transforms/GVNHoist/hoist-merge-geps.ll (revision 79ba323bdd0843275019e16b6e9b35133677c514)
1; RUN: opt -S -passes=gvn-hoist < %s | FileCheck %s
2
3define dso_local void @func(i32 noundef %a, ptr noundef %b) !dbg !10 {
4; Check the merged debug location of hoisted GEP
5; CHECK: entry
6; CHECK: %{{[a-zA-Z0-9_]*}} = getelementptr {{.*}} !dbg [[MERGED_DL:![0-9]+]]
7; CHECK: [[MERGED_DL]] = !DILocation(line: 0, scope: !{{[0-9]+}})
8entry:
9  tail call void @llvm.dbg.value(metadata i32 %a, metadata !16, metadata !DIExpression()), !dbg !17
10  tail call void @llvm.dbg.value(metadata ptr %b, metadata !18, metadata !DIExpression()), !dbg !17
11  %tobool = icmp ne i32 %a, 0, !dbg !19
12  br i1 %tobool, label %if.then, label %if.else, !dbg !21
13
14if.then:                                          ; preds = %entry
15  %arrayidx = getelementptr inbounds i32, ptr %b, i64 1, !dbg !22
16  store i32 1, ptr %arrayidx, align 4, !dbg !24
17  br label %if.end, !dbg !25
18
19if.else:                                          ; preds = %entry
20  %arrayidx1 = getelementptr inbounds i32, ptr %b, i64 1, !dbg !26
21  store i32 1, ptr %arrayidx1, align 4, !dbg !28
22  br label %if.end
23
24if.end:                                           ; preds = %if.else, %if.then
25  ret void, !dbg !29
26}
27
28declare void @llvm.dbg.declare(metadata, metadata, metadata)
29
30declare void @llvm.dbg.value(metadata, metadata, metadata)
31
32!llvm.dbg.cu = !{!0}
33!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
34
35!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 19.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
36!1 = !DIFile(filename: "main.c", directory: "/root/llvm-test/GVNHoist")
37!2 = !{i32 7, !"Dwarf Version", i32 5}
38!3 = !{i32 2, !"Debug Info Version", i32 3}
39!4 = !{i32 1, !"wchar_size", i32 4}
40!5 = !{i32 8, !"PIC Level", i32 2}
41!6 = !{i32 7, !"PIE Level", i32 2}
42!7 = !{i32 7, !"uwtable", i32 2}
43!8 = !{i32 7, !"frame-pointer", i32 2}
44!10 = distinct !DISubprogram(name: "func", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !15)
45!11 = !DISubroutineType(types: !12)
46!12 = !{null, !13, !14}
47!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
48!14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
49!15 = !{}
50!16 = !DILocalVariable(name: "a", arg: 1, scope: !10, file: !1, line: 1, type: !13)
51!17 = !DILocation(line: 0, scope: !10)
52!18 = !DILocalVariable(name: "b", arg: 2, scope: !10, file: !1, line: 1, type: !14)
53!19 = !DILocation(line: 2, column: 9, scope: !20)
54!20 = distinct !DILexicalBlock(scope: !10, file: !1, line: 2, column: 9)
55!21 = !DILocation(line: 2, column: 9, scope: !10)
56!22 = !DILocation(line: 3, column: 9, scope: !23)
57!23 = distinct !DILexicalBlock(scope: !20, file: !1, line: 2, column: 12)
58!24 = !DILocation(line: 3, column: 14, scope: !23)
59!25 = !DILocation(line: 4, column: 5, scope: !23)
60!26 = !DILocation(line: 5, column: 9, scope: !27)
61!27 = distinct !DILexicalBlock(scope: !20, file: !1, line: 4, column: 12)
62!28 = !DILocation(line: 5, column: 14, scope: !27)
63!29 = !DILocation(line: 7, column: 1, scope: !10)
64