342 lines · plain
1; RUN: opt -passes=inline %s -S -o - \2; RUN: | FileCheck %s3 4;; $ cat test.cpp5;; __attribute__((always_inline))6;; static void a(int* p2, int v2) { *p2 = v2; }7;;8;; __attribute__((always_inline))9;; void b(int* p1, int v1) { a(p1, v1); }10;;11;; int f1() {12;; int f1_local;13;; a(&f1_local, 1);14;; return f1_local;15;; }16;;17;; int f2() {18;; int f2_local[2];19;; a(f2_local, 2);20;; return f2_local[0];21;; }22;;23;; int f3() {24;; int f3_local[2];25;; a(f3_local + 1, 3);26;; return f3_local[1];27;; }28;;29;; int f4(int f4_param) {30;; a(&f4_param, 4);31;; return f4_param;32;; }33;;34;; int f5(int f5_param) {35;; int &f5_alias = f5_param;36;; a(&f5_alias, 5);37;; return f5_param;38;; }39;;40;; int f6() {41;; int f6_local;42;; b(&f6_local, 6);43;; return f6_local;44;; }45;;46;; IR generated with:47;; $ clang++ -Xclang -disable-llvm-passes test.cpp -g -O2 -o - -S -emit-llvm \48;; | opt -passes=declare-to-assign,sroa -o - -S49;;50;; Check that inlined stores are tracked as assignments. FileCheck directives51;; inline.52 53source_filename = "test.cpp"54define dso_local void @_Z1bPii(ptr %p1, i32 %v1) #0 !dbg !7 {55entry:56 call void @llvm.dbg.assign(metadata i1 undef, metadata !13, metadata !DIExpression(), metadata !15, metadata ptr undef, metadata !DIExpression()), !dbg !1657 call void @llvm.dbg.assign(metadata i1 undef, metadata !14, metadata !DIExpression(), metadata !17, metadata ptr undef, metadata !DIExpression()), !dbg !1658 call void @llvm.dbg.assign(metadata ptr %p1, metadata !13, metadata !DIExpression(), metadata !18, metadata ptr undef, metadata !DIExpression()), !dbg !1659 call void @llvm.dbg.assign(metadata i32 %v1, metadata !14, metadata !DIExpression(), metadata !19, metadata ptr undef, metadata !DIExpression()), !dbg !1660 call void @_ZL1aPii(ptr %p1, i32 %v1), !dbg !2061 ret void, !dbg !2162}63 64define internal void @_ZL1aPii(ptr %p2, i32 %v2) #2 !dbg !22 {65entry:66 call void @llvm.dbg.assign(metadata i1 undef, metadata !24, metadata !DIExpression(), metadata !26, metadata ptr undef, metadata !DIExpression()), !dbg !2767 call void @llvm.dbg.assign(metadata i1 undef, metadata !25, metadata !DIExpression(), metadata !28, metadata ptr undef, metadata !DIExpression()), !dbg !2768 call void @llvm.dbg.assign(metadata ptr %p2, metadata !24, metadata !DIExpression(), metadata !29, metadata ptr undef, metadata !DIExpression()), !dbg !2769 call void @llvm.dbg.assign(metadata i32 %v2, metadata !25, metadata !DIExpression(), metadata !30, metadata ptr undef, metadata !DIExpression()), !dbg !2770 store i32 %v2, ptr %p2, align 4, !dbg !3171 ret void, !dbg !3672}73 74;; Store directly to local with one level of inlining. Also record f1_dbg to75;; check that the dbg.assign gets the correct scope after inlining. This check76;; isn't repeated for the other functions.77;; int f1() {78;; int f1_local;79;; a(&f1_local, 1);80;; return f1_local;81;; }82;;83; CHECK-LABEL: define dso_local i32 @_Z2f1v()84; CHECK: store i32 1, ptr %f1_local, align 4,{{.*}} !DIAssignID ![[ID_1:[0-9]+]]85; CHECK-NEXT: #dbg_assign(i32 1, ![[f1_local:[0-9]+]], !DIExpression(), ![[ID_1]], ptr %f1_local, !DIExpression(), ![[f1_dbg:[0-9]+]]86define dso_local i32 @_Z2f1v() #3 !dbg !37 {87entry:88 %f1_local = alloca i32, align 4, !DIAssignID !4289 call void @llvm.dbg.assign(metadata i1 undef, metadata !41, metadata !DIExpression(), metadata !42, metadata ptr %f1_local, metadata !DIExpression()), !dbg !4390 %0 = bitcast ptr %f1_local to ptr, !dbg !4491 call void @llvm.lifetime.start.p0(i64 4, ptr %0) #5, !dbg !4492 call void @_ZL1aPii(ptr %f1_local, i32 1), !dbg !4593 %1 = load i32, ptr %f1_local, align 4, !dbg !4694 %2 = bitcast ptr %f1_local to ptr, !dbg !4795 call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5, !dbg !4796 ret i32 %1, !dbg !4897}98 99;; Store directly to fragment of local at its base address.100;; int f2() {101;; int f2_local[2];102;; a(f2_local, 2);103;; return f2_local[0];104;; }105;;106; CHECK-LABEL: define dso_local i32 @_Z2f2v()107; CHECK: store i32 2, ptr %arraydecay, align 4,{{.*}} !DIAssignID ![[ID_2:[0-9]+]]108; CHECK-NEXT: #dbg_assign(i32 2, ![[f2_local:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 32), ![[ID_2]], ptr %arraydecay, !DIExpression(),109define dso_local i32 @_Z2f2v() #3 !dbg !49 {110entry:111 %f2_local = alloca [2 x i32], align 4, !DIAssignID !55112 call void @llvm.dbg.assign(metadata i1 undef, metadata !51, metadata !DIExpression(), metadata !55, metadata ptr %f2_local, metadata !DIExpression()), !dbg !56113 %0 = bitcast ptr %f2_local to ptr, !dbg !57114 call void @llvm.lifetime.start.p0(i64 8, ptr %0) #5, !dbg !57115 %arraydecay = getelementptr inbounds [2 x i32], ptr %f2_local, i64 0, i64 0, !dbg !58116 call void @_ZL1aPii(ptr %arraydecay, i32 2), !dbg !59117 %arrayidx = getelementptr inbounds [2 x i32], ptr %f2_local, i64 0, i64 0, !dbg !60118 %1 = load i32, ptr %arrayidx, align 4, !dbg !60119 %2 = bitcast ptr %f2_local to ptr, !dbg !61120 call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5, !dbg !61121 ret i32 %1, !dbg !62122}123 124;; Store to fragment of local using rvalue offset as argument.125;; int f3() {126;; int f3_local[2];127;; a(f3_local + 1, 3);128;; return f3_local[1];129;; }130; CHECK-LABEL: define dso_local i32 @_Z2f3v()131; CHECK: store i32 3, ptr %add.ptr, align 4,{{.*}} !DIAssignID ![[ID_3:[0-9]+]]132; CHECK-NEXT: #dbg_assign(i32 3, ![[f3_local:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 32, 32), ![[ID_3]], ptr %add.ptr, !DIExpression(),133define dso_local i32 @_Z2f3v() #3 !dbg !63 {134entry:135 %f3_local = alloca [2 x i32], align 4, !DIAssignID !66136 call void @llvm.dbg.assign(metadata i1 undef, metadata !65, metadata !DIExpression(), metadata !66, metadata ptr %f3_local, metadata !DIExpression()), !dbg !67137 %0 = bitcast ptr %f3_local to ptr, !dbg !68138 call void @llvm.lifetime.start.p0(i64 8, ptr %0) #5, !dbg !68139 %arraydecay = getelementptr inbounds [2 x i32], ptr %f3_local, i64 0, i64 0, !dbg !69140 %add.ptr = getelementptr inbounds i32, ptr %arraydecay, i64 1, !dbg !70141 call void @_ZL1aPii(ptr %add.ptr, i32 3), !dbg !71142 %arrayidx = getelementptr inbounds [2 x i32], ptr %f3_local, i64 0, i64 1, !dbg !72143 %1 = load i32, ptr %arrayidx, align 4, !dbg !72144 %2 = bitcast ptr %f3_local to ptr, !dbg !73145 call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5, !dbg !73146 ret i32 %1, !dbg !74147}148 149;; Store to parameter directly.150;; int f4(int f4_param) {151;; a(&f4_param, 4);152;; return f4_param;153;; }154; CHECK-LABEL: define dso_local i32 @_Z2f4i(i32 %f4_param)155; CHECK: store i32 4, ptr %f4_param.addr, align 4,{{.*}} !DIAssignID ![[ID_4:[0-9]+]]156; CHECK-NEXT: #dbg_assign(i32 4, ![[f4_param:[0-9]+]], !DIExpression(), ![[ID_4]], ptr %f4_param.addr, !DIExpression(),157define dso_local i32 @_Z2f4i(i32 %f4_param) #3 !dbg !75 {158entry:159 %f4_param.addr = alloca i32, align 4, !DIAssignID !80160 call void @llvm.dbg.assign(metadata i1 undef, metadata !79, metadata !DIExpression(), metadata !80, metadata ptr %f4_param.addr, metadata !DIExpression()), !dbg !81161 store i32 %f4_param, ptr %f4_param.addr, align 4, !DIAssignID !82162 call void @llvm.dbg.assign(metadata i32 %f4_param, metadata !79, metadata !DIExpression(), metadata !82, metadata ptr %f4_param.addr, metadata !DIExpression()), !dbg !81163 call void @_ZL1aPii(ptr %f4_param.addr, i32 4), !dbg !83164 %0 = load i32, ptr %f4_param.addr, align 4, !dbg !84165 ret i32 %0, !dbg !85166}167 168;; Store through an alias.169;; int f5(int f5_param) {170;; int &f5_alias = f5_param;171;; a(&f5_alias, 5);172;; return f5_param;173;; }174; CHECK-LABEL: define dso_local i32 @_Z2f5i(i32 %f5_param)175; CHECK: store i32 5, ptr %f5_param.addr, align 4,{{.*}}!DIAssignID ![[ID_5:[0-9]+]]176; CHECK-NEXT: #dbg_assign(i32 5, ![[f5_param:[0-9]+]], !DIExpression(), ![[ID_5]], ptr %f5_param.addr, !DIExpression(),177define dso_local i32 @_Z2f5i(i32 %f5_param) #3 !dbg !86 {178entry:179 %f5_param.addr = alloca i32, align 4, !DIAssignID !91180 call void @llvm.dbg.assign(metadata i1 undef, metadata !88, metadata !DIExpression(), metadata !91, metadata ptr %f5_param.addr, metadata !DIExpression()), !dbg !92181 call void @llvm.dbg.assign(metadata i1 undef, metadata !89, metadata !DIExpression(), metadata !93, metadata ptr undef, metadata !DIExpression()), !dbg !92182 store i32 %f5_param, ptr %f5_param.addr, align 4, !DIAssignID !94183 call void @llvm.dbg.assign(metadata i32 %f5_param, metadata !88, metadata !DIExpression(), metadata !94, metadata ptr %f5_param.addr, metadata !DIExpression()), !dbg !92184 call void @llvm.dbg.assign(metadata ptr %f5_param.addr, metadata !89, metadata !DIExpression(), metadata !95, metadata ptr undef, metadata !DIExpression()), !dbg !92185 call void @_ZL1aPii(ptr %f5_param.addr, i32 5), !dbg !96186 %0 = load i32, ptr %f5_param.addr, align 4, !dbg !97187 ret i32 %0, !dbg !98188}189 190;; int f6() {191;; int f6_local;192;; b(&f6_local, 6);193;; return f6_local;194;; }195; CHECK-LABEL: define dso_local i32 @_Z2f6v()196; CHECK: store i32 6, ptr %f6_local, align 4,{{.*}} !DIAssignID ![[ID_6:[0-9]+]]197; CHECK-NEXT: #dbg_assign(i32 6, ![[f6_local:[0-9]+]], !DIExpression(), ![[ID_6]], ptr %f6_local, !DIExpression(),198define dso_local i32 @_Z2f6v() #3 !dbg !99 {199entry:200 %f6_local = alloca i32, align 4, !DIAssignID !102201 call void @llvm.dbg.assign(metadata i1 undef, metadata !101, metadata !DIExpression(), metadata !102, metadata ptr %f6_local, metadata !DIExpression()), !dbg !103202 %0 = bitcast ptr %f6_local to ptr, !dbg !104203 call void @llvm.lifetime.start.p0(i64 4, ptr %0) #5, !dbg !104204 call void @_Z1bPii(ptr %f6_local, i32 6), !dbg !105205 %1 = load i32, ptr %f6_local, align 4, !dbg !106206 %2 = bitcast ptr %f6_local to ptr, !dbg !107207 call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5, !dbg !107208 ret i32 %1, !dbg !108209}210 211declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)212declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)213declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)214 215; CHECK-DAG: ![[f1_local]] = !DILocalVariable(name: "f1_local",216; CHECK-DAG: ![[f2_local]] = !DILocalVariable(name: "f2_local",217; CHECK-DAG: ![[f3_local]] = !DILocalVariable(name: "f3_local",218; CHECK-DAG: ![[f4_param]] = !DILocalVariable(name: "f4_param",219; CHECK-DAG: ![[f5_param]] = !DILocalVariable(name: "f5_param",220; CHECK-DAG: ![[f6_local]] = !DILocalVariable(name: "f6_local",221 222; CHECK-DAG: ![[f1_dbg]] = !DILocation(line: 0, scope: ![[f1_scope:[0-9]+]])223; CHECK-DAG: ![[f1_scope]] = distinct !DISubprogram(name: "f1",224 225; CHECK-DAG: [[ID_1]] = distinct !DIAssignID()226; CHECK-DAG: [[ID_2]] = distinct !DIAssignID()227; CHECK-DAG: [[ID_3]] = distinct !DIAssignID()228; CHECK-DAG: [[ID_4]] = distinct !DIAssignID()229; CHECK-DAG: [[ID_5]] = distinct !DIAssignID()230; CHECK-DAG: [[ID_6]] = distinct !DIAssignID()231 232!llvm.dbg.cu = !{!0}233!llvm.module.flags = !{!3, !4, !5, !1000}234!llvm.ident = !{!6}235 236!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)237!1 = !DIFile(filename: "test.cpp", directory: "/")238!2 = !{}239!3 = !{i32 7, !"Dwarf Version", i32 4}240!4 = !{i32 2, !"Debug Info Version", i32 3}241!5 = !{i32 1, !"wchar_size", i32 4}242!6 = !{!"clang version 12.0.0)"}243!7 = distinct !DISubprogram(name: "b", linkageName: "_Z1bPii", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)244!8 = !DISubroutineType(types: !9)245!9 = !{null, !10, !11}246!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)247!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)248!12 = !{!13, !14}249!13 = !DILocalVariable(name: "p1", arg: 1, scope: !7, file: !1, line: 5, type: !10)250!14 = !DILocalVariable(name: "v1", arg: 2, scope: !7, file: !1, line: 5, type: !11)251!15 = distinct !DIAssignID()252!16 = !DILocation(line: 0, scope: !7)253!17 = distinct !DIAssignID()254!18 = distinct !DIAssignID()255!19 = distinct !DIAssignID()256!20 = !DILocation(line: 5, column: 27, scope: !7)257!21 = !DILocation(line: 5, column: 38, scope: !7)258!22 = distinct !DISubprogram(name: "a", linkageName: "_ZL1aPii", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !23)259!23 = !{!24, !25}260!24 = !DILocalVariable(name: "p2", arg: 1, scope: !22, file: !1, line: 2, type: !10)261!25 = !DILocalVariable(name: "v2", arg: 2, scope: !22, file: !1, line: 2, type: !11)262!26 = distinct !DIAssignID()263!27 = !DILocation(line: 0, scope: !22)264!28 = distinct !DIAssignID()265!29 = distinct !DIAssignID()266!30 = distinct !DIAssignID()267!31 = !DILocation(line: 2, column: 38, scope: !22)268!36 = !DILocation(line: 2, column: 44, scope: !22)269!37 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1v", scope: !1, file: !1, line: 7, type: !38, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !40)270!38 = !DISubroutineType(types: !39)271!39 = !{!11}272!40 = !{!41}273!41 = !DILocalVariable(name: "f1_local", scope: !37, file: !1, line: 8, type: !11)274!42 = distinct !DIAssignID()275!43 = !DILocation(line: 0, scope: !37)276!44 = !DILocation(line: 8, column: 3, scope: !37)277!45 = !DILocation(line: 9, column: 3, scope: !37)278!46 = !DILocation(line: 10, column: 10, scope: !37)279!47 = !DILocation(line: 11, column: 1, scope: !37)280!48 = !DILocation(line: 10, column: 3, scope: !37)281!49 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 13, type: !38, scopeLine: 13, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !50)282!50 = !{!51}283!51 = !DILocalVariable(name: "f2_local", scope: !49, file: !1, line: 14, type: !52)284!52 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 64, elements: !53)285!53 = !{!54}286!54 = !DISubrange(count: 2)287!55 = distinct !DIAssignID()288!56 = !DILocation(line: 0, scope: !49)289!57 = !DILocation(line: 14, column: 3, scope: !49)290!58 = !DILocation(line: 15, column: 5, scope: !49)291!59 = !DILocation(line: 15, column: 3, scope: !49)292!60 = !DILocation(line: 16, column: 10, scope: !49)293!61 = !DILocation(line: 17, column: 1, scope: !49)294!62 = !DILocation(line: 16, column: 3, scope: !49)295!63 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !1, file: !1, line: 19, type: !38, scopeLine: 19, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !64)296!64 = !{!65}297!65 = !DILocalVariable(name: "f3_local", scope: !63, file: !1, line: 20, type: !52)298!66 = distinct !DIAssignID()299!67 = !DILocation(line: 0, scope: !63)300!68 = !DILocation(line: 20, column: 3, scope: !63)301!69 = !DILocation(line: 21, column: 5, scope: !63)302!70 = !DILocation(line: 21, column: 14, scope: !63)303!71 = !DILocation(line: 21, column: 3, scope: !63)304!72 = !DILocation(line: 22, column: 10, scope: !63)305!73 = !DILocation(line: 23, column: 1, scope: !63)306!74 = !DILocation(line: 22, column: 3, scope: !63)307!75 = distinct !DISubprogram(name: "f4", linkageName: "_Z2f4i", scope: !1, file: !1, line: 25, type: !76, scopeLine: 25, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !78)308!76 = !DISubroutineType(types: !77)309!77 = !{!11, !11}310!78 = !{!79}311!79 = !DILocalVariable(name: "f4_param", arg: 1, scope: !75, file: !1, line: 25, type: !11)312!80 = distinct !DIAssignID()313!81 = !DILocation(line: 0, scope: !75)314!82 = distinct !DIAssignID()315!83 = !DILocation(line: 26, column: 3, scope: !75)316!84 = !DILocation(line: 27, column: 10, scope: !75)317!85 = !DILocation(line: 27, column: 3, scope: !75)318!86 = distinct !DISubprogram(name: "f5", linkageName: "_Z2f5i", scope: !1, file: !1, line: 30, type: !76, scopeLine: 30, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !87)319!87 = !{!88, !89}320!88 = !DILocalVariable(name: "f5_param", arg: 1, scope: !86, file: !1, line: 30, type: !11)321!89 = !DILocalVariable(name: "f5_alias", scope: !86, file: !1, line: 31, type: !90)322!90 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !11, size: 64)323!91 = distinct !DIAssignID()324!92 = !DILocation(line: 0, scope: !86)325!93 = distinct !DIAssignID()326!94 = distinct !DIAssignID()327!95 = distinct !DIAssignID()328!96 = !DILocation(line: 32, column: 3, scope: !86)329!97 = !DILocation(line: 33, column: 10, scope: !86)330!98 = !DILocation(line: 33, column: 3, scope: !86)331!99 = distinct !DISubprogram(name: "f6", linkageName: "_Z2f6v", scope: !1, file: !1, line: 36, type: !38, scopeLine: 36, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !100)332!100 = !{!101}333!101 = !DILocalVariable(name: "f6_local", scope: !99, file: !1, line: 37, type: !11)334!102 = distinct !DIAssignID()335!103 = !DILocation(line: 0, scope: !99)336!104 = !DILocation(line: 37, column: 3, scope: !99)337!105 = !DILocation(line: 38, column: 3, scope: !99)338!106 = !DILocation(line: 39, column: 10, scope: !99)339!107 = !DILocation(line: 40, column: 1, scope: !99)340!108 = !DILocation(line: 39, column: 3, scope: !99)341!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}342