1; RUN: opt -S -sroa -o - %s | FileCheck %s
2
3; SROA should split the alloca in two new ones, each with its own dbg.declare.
4; The original alloca and dbg.declare should be removed.
5
6define void @f1() {
7entry:
8  %0 = alloca [9 x i32]
9  call void @llvm.dbg.declare(metadata [9 x i32]* %0, metadata !11, metadata !DIExpression()), !dbg !17
10  %1 = bitcast [9 x i32]* %0 to i8*
11  call void @llvm.memset.p0i8.i64(i8* align 16 %1, i8 0, i64 36, i1 true)
12  %2 = getelementptr [9 x i32], [9 x i32]* %0, i32 0, i32 0
13  store volatile i32 1, i32* %2
14  ret void
15}
16
17; Function Attrs: nounwind readnone speculatable
18declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
19
20; Function Attrs: argmemonly nounwind
21declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1) #0
22
23attributes #0 = { argmemonly nounwind }
24attributes #1 = { nounwind readnone speculatable }
25
26!llvm.dbg.cu = !{!0}
27!llvm.module.flags = !{!3, !4, !5}
28!llvm.ident = !{!6}
29
30!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
31!1 = !DIFile(filename: "foo.c", directory: "/bar")
32!2 = !{}
33!3 = !{i32 2, !"Dwarf Version", i32 4}
34!4 = !{i32 2, !"Debug Info Version", i32 3}
35!5 = !{i32 1, !"wchar_size", i32 4}
36!6 = !{!"clang version 6.0.0"}
37!7 = distinct !DISubprogram(name: "f1", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !10)
38!8 = !DISubroutineType(types: !9)
39!9 = !{null}
40!10 = !{!11}
41!11 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 3, type: !12)
42!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 288, elements: !15)
43!13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !14)
44!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
45!15 = !{!16}
46!16 = !DISubrange(count: 9)
47!17 = !DILocation(line: 3, column: 18, scope: !7)
48
49; CHECK-NOT:  = alloca [9 x i32]
50; CHECK-NOT:  call void @llvm.dbg.declare(metadata [9 x i32]*
51
52; CHECK:      %[[VAR1:.*]] = alloca i32
53; CHECK-NEXT: %[[VAR2:.*]] = alloca [8 x i32]
54; CHECK-NEXT: call void @llvm.dbg.declare(metadata i32* %[[VAR1]]
55; CHECK-NEXT: call void @llvm.dbg.declare(metadata [8 x i32]* %[[VAR2]]
56
57; CHECK-NOT:  = alloca [9 x i32]
58; CHECK-NOT:  call void @llvm.dbg.declare(metadata [9 x i32]*
59
60