blob: 9229157a9b6ed984b9e22b7590bda4d8f6f4f498 [file] [log] [blame]
Florian Hahnc38c08b2020-07-08 08:42:55 +01001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
Florian Hahn36b18f82019-12-06 14:55:07 +00002; Test that the getelementptr generated when the dse pass determines that
3; a memset can be shortened has the debugloc carried over from the memset.
4
Florian Hahna0d946b2020-10-16 08:42:18 +01005; RUN: opt -S -march=native -dse < %s| FileCheck %s
Florian Hahn36b18f82019-12-06 14:55:07 +00006; CHECK: bitcast [5 x i64]* %{{[a-zA-Z_][a-zA-Z0-9_]*}} to i8*, !dbg
7; CHECK-NEXT: %{{[0-9]+}} = getelementptr inbounds i8, i8* %0, i64 32, !dbg ![[DBG:[0-9]+]]
Florian Hahn6dcf9ec2020-04-15 15:21:30 +01008; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 16 %1, i8 0, i64 8, i1 false), !dbg ![[DBG:[0-9]+]]
Florian Hahn36b18f82019-12-06 14:55:07 +00009; CHECK: ![[DBG]] = !DILocation(line: 2,
10
11; The test IR is generated by running:
12;
13; clang Debugify_Dead_Store_Elimination.cpp -Wno-c++11-narrowing -S \
14; -emit-llvm -O0 -w -Xclang -disable-O0-optnone -march=native -fdeclspec \
15; --target=x86_64-gnu-linux-unknown -Werror=unreachable-code -o -
16;
17; Where Debugify_Dead_Store_Elimination.cpp contains:
18;
19; int a() {
20; long b[]{2, 2, 2, 2, 0};
21; if (a())
22; ;
23; }
24
25
Florian Hahn6dcf9ec2020-04-15 15:21:30 +010026declare void @use([5 x i64]*)
27
Florian Hahn36b18f82019-12-06 14:55:07 +000028define dso_local i32 @_Z1av() !dbg !7 {
29entry:
30 %retval = alloca i32, align 4
31 %b = alloca [5 x i64], align 16
32 call void @llvm.dbg.declare(metadata [5 x i64]* %b, metadata !11, metadata !DIExpression()), !dbg !16
33 %0 = bitcast [5 x i64]* %b to i8*, !dbg !16
34 call void @llvm.memset.p0i8.i64(i8* align 16 %0, i8 0, i64 40, i1 false), !dbg !16
35 %1 = bitcast i8* %0 to [5 x i64]*, !dbg !16
36 %2 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i32 0, i32 0, !dbg !16
37 store i64 2, i64* %2, align 16, !dbg !16
38 %3 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i32 0, i32 1, !dbg !16
39 store i64 2, i64* %3, align 8, !dbg !16
40 %4 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i32 0, i32 2, !dbg !16
41 store i64 2, i64* %4, align 16, !dbg !16
42 %5 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i32 0, i32 3, !dbg !16
43 store i64 2, i64* %5, align 8, !dbg !16
Florian Hahn6dcf9ec2020-04-15 15:21:30 +010044 call void @use([5 x i64]* %b)
Florian Hahn36b18f82019-12-06 14:55:07 +000045 %call = call i32 @_Z1av(), !dbg !17
46 %tobool = icmp ne i32 %call, 0, !dbg !17
47 br i1 %tobool, label %if.then, label %if.end, !dbg !19
48
49if.then: ; preds = %entry
50 br label %if.end, !dbg !19
51
52if.end: ; preds = %if.then, %entry
53 call void @llvm.trap(), !dbg !20
54 unreachable, !dbg !20
55
56return: ; No predecessors!
57 %6 = load i32, i32* %retval, align 4, !dbg !21
58 ret i32 %6, !dbg !21
59}
60
61; Function Attrs: nounwind readnone speculatable
62declare void @llvm.dbg.declare(metadata, metadata, metadata)
63
64; Function Attrs: argmemonly nounwind
65declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg)
66
67; Function Attrs: cold noreturn nounwind
68declare void @llvm.trap()
69
70!llvm.module.flags = !{!3, !4, !5}
71!llvm.ident = !{!6}
72
73!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git eb1a156d7f7ba56ea8f9a26da36e6a93d1e98bda)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
74!1 = !DIFile(filename: "Debugify_Dead_Store_Elimination.cpp", directory: "")
75!2 = !{}
76!3 = !{i32 2, !"Dwarf Version", i32 4}
77!4 = !{i32 2, !"Debug Info Version", i32 3}
78!5 = !{i32 1, !"wchar_size", i32 4}
79!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git eb1a156d7f7ba56ea8f9a26da36e6a93d1e98bda)"}
80!7 = distinct !DISubprogram(name: "a", linkageName: "_Z1av", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
81!8 = !DISubroutineType(types: !9)
82!9 = !{!10}
83!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
84!11 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 2, type: !12)
85!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 320, elements: !14)
86!13 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
87!14 = !{!15}
88!15 = !DISubrange(count: 5)
89!16 = !DILocation(line: 2, column: 8, scope: !7)
90!17 = !DILocation(line: 3, column: 7, scope: !18)
91!18 = distinct !DILexicalBlock(scope: !7, file: !1, line: 3, column: 7)
92!19 = !DILocation(line: 3, column: 7, scope: !7)
93!20 = !DILocation(line: 3, column: 9, scope: !18)
94!21 = !DILocation(line: 5, column: 1, scope: !7)