1; RUN: opt -S -dse -enable-dse-memoryssa=false -memdep-block-scan-limit=3 < %s | FileCheck %s 2; RUN: opt -S -strip-debug -dse -enable-dse-memoryssa=false -memdep-block-scan-limit=3 < %s | FileCheck %s 3 4; Test case to check that the memory dependency analysis gets the same 5; result even if we have a dbg value between the memcpy and 6; store. The memory dependency is then used by DSE to remove the store. 7 8; We use -memdep-block-scan-limit=3 to be able to create a small test case. 9; Without it, we would need to squeeze in 100 instructions since the default 10; limit is 100. 11 12target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 13target triple = "x86_64-unknown-linux-gnu" 14 15@g = common global [1 x i8] zeroinitializer, align 1, !dbg !0 16 17; Function Attrs: noinline nounwind uwtable 18define void @foo() #0 !dbg !14 { 19entry: 20 %i = alloca i8, align 1 21 store i8 1, i8* %i, align 1, !dbg !19 22 call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !17, metadata !DIExpression()), !dbg !18 23 %0 = bitcast [1 x i8]* @g to i8* 24 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %i, i8* %0, i64 1, i1 false), !dbg !20 25 br label %bb2 26 27bb2: ; preds = %0 28 ret void, !dbg !21 29} 30 31; Function Attrs: nounwind readnone speculatable 32declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 33 34; Function Attrs: argmemonly nounwind 35declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #2 36 37attributes #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" } 38attributes #1 = { nounwind readnone speculatable } 39attributes #2 = { argmemonly nounwind } 40 41!llvm.dbg.cu = !{!2} 42!llvm.module.flags = !{!10, !11, !12} 43!llvm.ident = !{!13} 44 45!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 46!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 3, type: !6, isLocal: false, isDefinition: true) 47!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) 48!3 = !DIFile(filename: "foo.c", directory: "/bar") 49!4 = !{} 50!5 = !{!0} 51!6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 8, elements: !8) 52!7 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) 53!8 = !{!9} 54!9 = !DISubrange(count: 1) 55!10 = !{i32 2, !"Dwarf Version", i32 4} 56!11 = !{i32 2, !"Debug Info Version", i32 3} 57!12 = !{i32 1, !"wchar_size", i32 4} 58!13 = !{!"clang version 6.0.0"} 59!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) 60!15 = !DISubroutineType(types: !16) 61!16 = !{null} 62!17 = !DILocalVariable(name: "i", scope: !14, file: !3, line: 7, type: !7) 63!18 = !DILocation(line: 7, column: 10, scope: !14) 64!19 = !DILocation(line: 8, column: 7, scope: !14) 65!20 = !DILocation(line: 9, column: 5, scope: !14) 66!21 = !DILocation(line: 10, column: 1, scope: !14) 67 68; Check that the store is removed and that the memcpy is still there 69; CHECK-LABEL: foo 70; CHECK-NOT: store i8 71; CHECK: call void @llvm.memcpy 72; CHECK: ret void 73