1; RUN: opt -S -dse -dse-memoryssa-scanlimit=2 < %s | FileCheck %s
2; RUN: opt -S -strip-debug -dse -dse-memoryssa-scanlimit=2 < %s | FileCheck %s
3
4; Test case to check that DSE gets the same result even if we have a dbg value
5; between the memcpy.
6
7; This test case is less relevant for the MemorySSA backed version of DSE, as
8; debug values are not modeled in MemorySSA and are skipped regardless of the
9; exploration limit.
10
11target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
12target triple = "x86_64-unknown-linux-gnu"
13
14@g = common global [1 x i8] zeroinitializer, align 1, !dbg !0
15
16; Function Attrs: noinline nounwind uwtable
17define void @foo() #0 !dbg !14 {
18entry:
19  %i = alloca i8, align 1
20  store i8 1, i8* %i, align 1, !dbg !19
21  call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
22  call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
23  call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
24  call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
25  call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
26  call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
27  %0 = bitcast [1 x i8]* @g to i8*
28  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %i, i8* %0, i64 1, i1 false), !dbg !20
29  br label %bb2
30
31bb2:                                              ; preds = %0
32  ret void, !dbg !21
33}
34
35; Function Attrs: nounwind readnone speculatable
36declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
37
38; Function Attrs: argmemonly nounwind
39declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #2
40
41attributes #0 = { noinline nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "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"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
42attributes #1 = { nounwind readnone speculatable }
43attributes #2 = { argmemonly nounwind }
44
45!llvm.dbg.cu = !{!2}
46!llvm.module.flags = !{!10, !11, !12}
47!llvm.ident = !{!13}
48
49!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
50!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 3, type: !6, isLocal: false, isDefinition: true)
51!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
52!3 = !DIFile(filename: "foo.c", directory: "/bar")
53!4 = !{}
54!5 = !{!0}
55!6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 8, elements: !8)
56!7 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
57!8 = !{!9}
58!9 = !DISubrange(count: 1)
59!10 = !{i32 2, !"Dwarf Version", i32 4}
60!11 = !{i32 2, !"Debug Info Version", i32 3}
61!12 = !{i32 1, !"wchar_size", i32 4}
62!13 = !{!"clang version 6.0.0"}
63!14 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 5, type: !15, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: false, unit: !2, retainedNodes: !4)
64!15 = !DISubroutineType(types: !16)
65!16 = !{null}
66!17 = !DILocalVariable(name: "i", scope: !14, file: !3, line: 7, type: !7)
67!18 = !DILocation(line: 7, column: 10, scope: !14)
68!19 = !DILocation(line: 8, column: 7, scope: !14)
69!20 = !DILocation(line: 9, column: 5, scope: !14)
70!21 = !DILocation(line: 10, column: 1, scope: !14)
71
72; Check that the both the store and memcpy are removed because they both access
73; an alloca that is not read.
74; CHECK-LABEL: foo
75; CHECK-NOT:   store i8
76; CHECK-NOT:   call void @llvm.memcpy
77; CHECK:       ret void
78