Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -41,6 +41,7 @@ #include "llvm/IR/ConstantRange.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DebugInfo.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" @@ -1890,9 +1891,15 @@ } // Finally nuke all instructions apart from the common instruction. - for (auto *I : Insts) - if (I != I0) - I->eraseFromParent(); + for (auto *I : Insts) { + if (I == I0) + continue; + // The remaining uses are debug users, replace those with the common inst. + // In most (all?) cases this just introduces a use-before-def. + assert(I->user_empty() && "I unexpectedly still has non-dbg users"); + I->replaceAllUsesWith(I0); + I->eraseFromParent(); + } return true; } @@ -2521,6 +2528,7 @@ // Insert a select of the value of the speculated store. if (SpeculatedStoreValue) { IRBuilder Builder(BI); + Value *OrigV = SpeculatedStore->getValueOperand(); Value *TrueV = SpeculatedStore->getValueOperand(); Value *FalseV = SpeculatedStoreValue; if (Invert) @@ -2530,6 +2538,35 @@ SpeculatedStore->setOperand(0, S); SpeculatedStore->applyMergedLocation(BI->getDebugLoc(), SpeculatedStore->getDebugLoc()); + // The value stored is still conditional, but the store itself is now + // unconditonally run, so we must be sure that any linked dbg.assign + // intrinsics are tracking the new stored value (the result of the + // select). If we don't, and the store were to be removed by another pass + // (e.g. DSE), then we'd eventually end up emitting a location describing + // the conditional value, unconditionally. + // + // === Before this transformation === + // pred: + // store %one, %x.dest, !DIAssignID !1 + // dbg.assign %one, "x", ..., !1, ... + // br %cond if.then + // + // if.then: + // store %two, %x.dest, !DIAssignID !2 + // dbg.assign %two, "x", ..., !2, ... + // + // === After this transformation === + // pred: + // store %one, %x.dest, !DIAssignID !1 + // dbg.assign %one, "x", ..., !1 + /// ... + // %merge = select %cond, %two, %one + // store %merge, %x.dest, !DIAssignID !2 + // dbg.assign %merge, "x", ..., !2 + for (auto *DAI : at::getAssignmentMarkers(SpeculatedStore)) { + if (any_of(DAI->location_ops(), [&](Value *V) { return V == OrigV; })) + DAI->replaceVariableLocationOp(OrigV, S); + } } // Metadata can be dependent on the condition we are hoisting above. @@ -2539,8 +2576,11 @@ // Similarly strip attributes that maybe dependent on condition we are // hoisting above. for (auto &I : *ThenBB) { - if (!SpeculatedStoreValue || &I != SpeculatedStore) - I.setDebugLoc(DebugLoc()); + if (!SpeculatedStoreValue || &I != SpeculatedStore) { + // Don't update the DILocation of dbg.assign intrinsics. + if (!isa(&I)) + I.setDebugLoc(DebugLoc()); + } I.dropUndefImplyingAttrsAndUnknownMetadata(); } @@ -2574,8 +2614,12 @@ // Remove speculated dbg intrinsics. // FIXME: Is it possible to do this in a more elegant way? Moving/merging the // dbg value for the different flows and inserting it after the select. - for (Instruction *I : SpeculatedDbgIntrinsics) - I->eraseFromParent(); + for (Instruction *I : SpeculatedDbgIntrinsics) { + // We still want to know that an assignment took place so don't remove + // dbg.assign intrinsics. + if (!isa(I)) + I->eraseFromParent(); + } ++NumSpeculations; return true; Index: llvm/test/DebugInfo/Generic/assignment-tracking/simplifycfg/empty-block.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/Generic/assignment-tracking/simplifycfg/empty-block.ll @@ -0,0 +1,143 @@ +; RUN: opt -S %s -simplifycfg -o - -experimental-assignment-tracking | FileCheck %s + +;; $ cat test.cpp +;; class a {}; +;; void operator*(a, float &); +;; class b { +;; public: +;; a c; +;; }; +;; int d; +;; class e { +;; b g[3]; +;; float f; +;; void i(); +;; }; +;; void e::i() { +;; float h; +;; g[d].c *h; +;; if (h) +;; h = f; +;; else +;; h = f; +;; } +;; Generated by grabbing IR before simplifycfg in: +;; $ clang++ -O2 -g -c test.cpp -Xclang -fexperimental-assignment-tracking + +;; if.then and if.else each only have a dbg.assign and br instruction. +;; SimplifyCFG will remove these blocks. Check that the dbg.assign intrinsics +;; are sunk into the succ beforehand. + +; CHECK: entry: +;; -- alloca dbg.assign +; CHECK: call void @llvm.dbg.assign(metadata i1 undef +;; -- sunk dbg.assigns +; CHECK: call void @llvm.dbg.assign(metadata float undef, metadata ![[var:[0-9]+]], metadata !DIExpression(), metadata ![[id:[0-9]+]], metadata float* %h, metadata !DIExpression()), !dbg +; CHECK-NEXT: call void @llvm.dbg.assign(metadata float undef, metadata ![[var]], metadata !DIExpression(), metadata ![[id]], metadata float* %h, metadata !DIExpression()), !dbg +; CHECK-NEXT: %storemerge.in = getelementptr +; CHECK-NEXT: %storemerge = load float +; CHECK-NEXT: store float %storemerge, float* %h, align 4{{.+}}!DIAssignID ![[id]] +; CHECK: ret void + +%class.e = type { [3 x %class.b], float } +%class.b = type { %class.a } +%class.a = type { i8 } + +@d = dso_local local_unnamed_addr global i32 0, align 4, !dbg !0 + +; Function Attrs: uwtable +define dso_local void @_ZN1e1iEv(%class.e* %this) local_unnamed_addr #0 align 2 !dbg !11 { +entry: + %h = alloca float, align 4, !DIAssignID !32 + call void @llvm.dbg.assign(metadata i1 undef, metadata !31, metadata !DIExpression(), metadata !32, metadata float* %h, metadata !DIExpression()), !dbg !33 + %0 = bitcast float* %h to i8*, !dbg !34 + call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #4, !dbg !34 + call void @_Zml1aRf(float* nonnull align 4 dereferenceable(4) %h), !dbg !35 + %1 = load float, float* %h, align 4, !dbg !36, !tbaa !38 + %tobool = fcmp une float %1, 0.000000e+00, !dbg !36 + br i1 %tobool, label %if.then, label %if.else, !dbg !42 + +if.then: ; preds = %entry + call void @llvm.dbg.assign(metadata float undef, metadata !31, metadata !DIExpression(), metadata !43, metadata float* %h, metadata !DIExpression()), !dbg !33 + br label %if.end, !dbg !44 + +if.else: ; preds = %entry + call void @llvm.dbg.assign(metadata float undef, metadata !31, metadata !DIExpression(), metadata !43, metadata float* %h, metadata !DIExpression()), !dbg !33 + br label %if.end + +if.end: ; preds = %if.else, %if.then + %storemerge.in = getelementptr inbounds %class.e, %class.e* %this, i64 0, i32 1, !dbg !45 + %storemerge = load float, float* %storemerge.in, align 4, !dbg !45, !tbaa !46 + store float %storemerge, float* %h, align 4, !dbg !45, !tbaa !38, !DIAssignID !43 + call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %0) #4, !dbg !48 + ret void, !dbg !48 +} + +; Function Attrs: argmemonly nofree nosync nounwind willreturn +declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1 + +declare !dbg !49 dso_local void @_Zml1aRf(float* nonnull align 4 dereferenceable(4)) local_unnamed_addr #2 + +; Function Attrs: argmemonly nofree nosync nounwind willreturn +declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1 + +; Function Attrs: nofree nosync nounwind readnone speculatable willreturn +declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #3 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!7, !8, !9} +!llvm.ident = !{!10} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "d", scope: !2, file: !3, line: 7, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "test.cpp", directory: "/") +!4 = !{} +!5 = !{!0} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = !{i32 7, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{i32 1, !"wchar_size", i32 4} +!10 = !{!"clang version 12.0.0"} +!11 = distinct !DISubprogram(name: "i", linkageName: "_ZN1e1iEv", scope: !12, file: !3, line: 13, type: !25, scopeLine: 13, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, declaration: !24, retainedNodes: !28) +!12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "e", file: !3, line: 8, size: 64, flags: DIFlagTypePassByValue, elements: !13, identifier: "_ZTS1e") +!13 = !{!14, !22, !24} +!14 = !DIDerivedType(tag: DW_TAG_member, name: "g", scope: !12, file: !3, line: 9, baseType: !15, size: 24) +!15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !16, size: 24, elements: !20) +!16 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "b", file: !3, line: 3, size: 8, flags: DIFlagTypePassByValue, elements: !17, identifier: "_ZTS1b") +!17 = !{!18} +!18 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !16, file: !3, line: 5, baseType: !19, size: 8, flags: DIFlagPublic) +!19 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "a", file: !3, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !4, identifier: "_ZTS1a") +!20 = !{!21} +!21 = !DISubrange(count: 3) +!22 = !DIDerivedType(tag: DW_TAG_member, name: "f", scope: !12, file: !3, line: 10, baseType: !23, size: 32, offset: 32) +!23 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float) +!24 = !DISubprogram(name: "i", linkageName: "_ZN1e1iEv", scope: !12, file: !3, line: 11, type: !25, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized) +!25 = !DISubroutineType(types: !26) +!26 = !{null, !27} +!27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!28 = !{!29, !31} +!29 = !DILocalVariable(name: "this", arg: 1, scope: !11, type: !30, flags: DIFlagArtificial | DIFlagObjectPointer) +!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64) +!31 = !DILocalVariable(name: "h", scope: !11, file: !3, line: 14, type: !23) +!32 = distinct !DIAssignID() +!33 = !DILocation(line: 0, scope: !11) +!34 = !DILocation(line: 14, column: 3, scope: !11) +!35 = !DILocation(line: 15, column: 10, scope: !11) +!36 = !DILocation(line: 16, column: 7, scope: !37) +!37 = distinct !DILexicalBlock(scope: !11, file: !3, line: 16, column: 7) +!38 = !{!39, !39, i64 0} +!39 = !{!"float", !40, i64 0} +!40 = !{!"omnipotent char", !41, i64 0} +!41 = !{!"Simple C++ TBAA"} +!42 = !DILocation(line: 16, column: 7, scope: !11) +!43 = distinct !DIAssignID() +!44 = !DILocation(line: 17, column: 5, scope: !37) +!45 = !DILocation(line: 0, scope: !37) +!46 = !{!47, !39, i64 4} +!47 = !{!"_ZTS1e", !40, i64 0, !39, i64 4} +!48 = !DILocation(line: 20, column: 1, scope: !11) +!49 = !DISubprogram(name: "operator*", linkageName: "_Zml1aRf", scope: !3, file: !3, line: 2, type: !50, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4) +!50 = !DISubroutineType(types: !51) +!51 = !{null, !19, !52} +!52 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !23, size: 64) Index: llvm/test/DebugInfo/Generic/assignment-tracking/simplifycfg/sink-erase.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/Generic/assignment-tracking/simplifycfg/sink-erase.ll @@ -0,0 +1,137 @@ +; RUN: opt %s -S -o - -experimental-assignment-tracking | FileCheck %s + +;; Reduced from function cpmx_calc_new_bk in +;; MultiSource/Benchmarks/mafft/tddis.c in the llvm test suite. +;; +;; $ cat reduce.cpp +;; int a; +;; void b() { +;; int c = 0; +;; for (; c < 6; c++) +;; for (; a;) +;; ; +;; } +;; +;; IR grabbed before simplifycfg in: +;; clang++ -O2 -g -Xclang -fexperimental-assignment-tracking +;; +;; simplifycfg will transform this cfg into: +;; +;; [entry] +;; | | +---+ +;; | v v | +;; | [for.cond1]-+ +;; v +;; [for.inc.split.5] +;; +;; Check that there is only one dbg.assign (for c) in the final block. +; CHECK: for.inc.split.5: +; CHECK-COUNT-1: call void @llvm.dbg.assign + +@a = dso_local local_unnamed_addr global i32 0, align 4, !dbg !0 + +; Function Attrs: norecurse nounwind readonly uwtable mustprogress +define dso_local void @_Z1bv() local_unnamed_addr #0 !dbg !11 { +entry: + call void @llvm.dbg.assign(metadata i1 undef, metadata !15, metadata !DIExpression(), metadata !16, metadata i32* undef, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.assign(metadata i32 0, metadata !15, metadata !DIExpression(), metadata !18, metadata i32* undef, metadata !DIExpression()), !dbg !17 + %.pr = load i32, i32* @a, align 4, !tbaa !19 + %tobool.not = icmp eq i32 %.pr, 0 + call void @llvm.dbg.value(metadata i32 0, metadata !15, metadata !DIExpression()), !dbg !17 + br i1 %tobool.not, label %for.inc.split, label %for.cond1.preheader, !dbg !23 + +for.cond1.preheader: ; preds = %for.inc.split.4.for.cond1.preheader_crit_edge, %for.inc.split.3.for.cond1.preheader_crit_edge, %for.inc.split.2.for.cond1.preheader_crit_edge, %for.inc.split.1.for.cond1.preheader_crit_edge, %for.inc.split.for.cond1.preheader_crit_edge, %entry + br label %for.cond1, !dbg !28 + +for.cond1: ; preds = %for.cond1.preheader, %for.cond1 + br label %for.cond1, !dbg !28 + +for.inc.split: ; preds = %entry + call void @llvm.dbg.assign(metadata i32 1, metadata !15, metadata !DIExpression(), metadata !29, metadata i32* undef, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 1, metadata !15, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 1, metadata !15, metadata !DIExpression()), !dbg !17 + br i1 true, label %for.inc.split.1, label %for.inc.split.for.cond1.preheader_crit_edge, !dbg !23 + +for.inc.split.for.cond1.preheader_crit_edge: ; preds = %for.inc.split + br label %for.cond1.preheader, !dbg !23 + +for.inc.split.1: ; preds = %for.inc.split + call void @llvm.dbg.assign(metadata i32 2, metadata !15, metadata !DIExpression(), metadata !29, metadata i32* undef, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 2, metadata !15, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 2, metadata !15, metadata !DIExpression()), !dbg !17 + br i1 true, label %for.inc.split.2, label %for.inc.split.1.for.cond1.preheader_crit_edge, !dbg !23 + +for.inc.split.1.for.cond1.preheader_crit_edge: ; preds = %for.inc.split.1 + br label %for.cond1.preheader, !dbg !23 + +for.inc.split.2: ; preds = %for.inc.split.1 + call void @llvm.dbg.assign(metadata i32 3, metadata !15, metadata !DIExpression(), metadata !29, metadata i32* undef, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 3, metadata !15, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 3, metadata !15, metadata !DIExpression()), !dbg !17 + br i1 true, label %for.inc.split.3, label %for.inc.split.2.for.cond1.preheader_crit_edge, !dbg !23 + +for.inc.split.2.for.cond1.preheader_crit_edge: ; preds = %for.inc.split.2 + br label %for.cond1.preheader, !dbg !23 + +for.inc.split.3: ; preds = %for.inc.split.2 + call void @llvm.dbg.assign(metadata i32 4, metadata !15, metadata !DIExpression(), metadata !29, metadata i32* undef, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 4, metadata !15, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 4, metadata !15, metadata !DIExpression()), !dbg !17 + br i1 true, label %for.inc.split.4, label %for.inc.split.3.for.cond1.preheader_crit_edge, !dbg !23 + +for.inc.split.3.for.cond1.preheader_crit_edge: ; preds = %for.inc.split.3 + br label %for.cond1.preheader, !dbg !23 + +for.inc.split.4: ; preds = %for.inc.split.3 + call void @llvm.dbg.assign(metadata i32 5, metadata !15, metadata !DIExpression(), metadata !29, metadata i32* undef, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 5, metadata !15, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 5, metadata !15, metadata !DIExpression()), !dbg !17 + br i1 true, label %for.inc.split.5, label %for.inc.split.4.for.cond1.preheader_crit_edge, !dbg !23 + +for.inc.split.4.for.cond1.preheader_crit_edge: ; preds = %for.inc.split.4 + br label %for.cond1.preheader, !dbg !23 + +for.inc.split.5: ; preds = %for.inc.split.4 + call void @llvm.dbg.assign(metadata i32 6, metadata !15, metadata !DIExpression(), metadata !29, metadata i32* undef, metadata !DIExpression()), !dbg !17 + call void @llvm.dbg.value(metadata i32 6, metadata !15, metadata !DIExpression()), !dbg !17 + ret void, !dbg !30 +} + +declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #1 +declare void @llvm.dbg.value(metadata, metadata, metadata) #1 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!7, !8, !9} +!llvm.ident = !{!10} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "reduce.cpp", directory: "/") +!4 = !{} +!5 = !{!0} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = !{i32 7, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{i32 1, !"wchar_size", i32 4} +!10 = !{!"clang version 12.0.0"} +!11 = distinct !DISubprogram(name: "b", linkageName: "_Z1bv", scope: !3, file: !3, line: 2, type: !12, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !14) +!12 = !DISubroutineType(types: !13) +!13 = !{null} +!14 = !{!15} +!15 = !DILocalVariable(name: "c", scope: !11, file: !3, line: 3, type: !6) +!16 = distinct !DIAssignID() +!17 = !DILocation(line: 0, scope: !11) +!18 = distinct !DIAssignID() +!19 = !{!20, !20, i64 0} +!20 = !{!"int", !21, i64 0} +!21 = !{!"omnipotent char", !22, i64 0} +!22 = !{!"Simple C++ TBAA"} +!23 = !DILocation(line: 5, column: 12, scope: !24) +!24 = distinct !DILexicalBlock(scope: !25, file: !3, line: 5, column: 5) +!25 = distinct !DILexicalBlock(scope: !26, file: !3, line: 5, column: 5) +!26 = distinct !DILexicalBlock(scope: !27, file: !3, line: 4, column: 3) +!27 = distinct !DILexicalBlock(scope: !11, file: !3, line: 4, column: 3) +!28 = !DILocation(line: 5, column: 5, scope: !25) +!29 = distinct !DIAssignID() +!30 = !DILocation(line: 7, column: 1, scope: !11) Index: llvm/test/DebugInfo/Generic/assignment-tracking/simplifycfg/speculated-store.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/Generic/assignment-tracking/simplifycfg/speculated-store.ll @@ -0,0 +1,86 @@ +; RUN: opt -simplifycfg %s -S -experimental-assignment-tracking \ +; RUN: | FileCheck %s + +;; Ensure that we correctly update the value component of dbg.assign intrinsics +;; after merging a conditional block with a store its the predecessor. The +;; value stored is still conditional, but the store itself is now +;; unconditionally run, so we must be sure that any linked dbg.assign intrinsics +;; are tracking the new stored value (the result of the select). If we don't, +;; and the store were to be removed by another pass (e.g. DSE), then we'd +;; eventually end up emitting a location describing the conditional value, +;; unconditionally. + +;; Created from the following source and command, with dbg.assign and DIAssignID +;; metadata added and some other metadata removed by hand: +;; $ cat test.c +;; int a; +;; void b() { +;; int c = 0; +;; if (a) +;; c = 1; +;; } +;; $ clang -O2 -g -emit-llvm -S test.c -Xclang -fexperimental-assignment-tracking + +; CHECK: %[[SELECT:.*]] = select i1 %tobool +; CHECK-NEXT: store i32 %[[SELECT]], i32* %c{{.*}}, !DIAssignID ![[ID:[0-9]+]] +; CHECK-NEXT: call void @llvm.dbg.assign(metadata i32 %[[SELECT]], metadata ![[VAR_C:[0-9]+]], metadata !DIExpression(), metadata ![[ID]], metadata i32* %c, metadata !DIExpression()), !dbg +; CHECK: ![[VAR_C]] = !DILocalVariable(name: "c", + +@a = dso_local global i32 0, align 4, !dbg !0 + +define dso_local void @b() !dbg !11 { +entry: + %c = alloca i32, align 4 + %0 = bitcast i32* %c to i8*, !dbg !16 + call void @llvm.lifetime.start.p0i8(i64 4, i8* %0), !dbg !16 + store i32 0, i32* %c, align 4, !dbg !17, !DIAssignID !36 + call void @llvm.dbg.assign(metadata i32 0, metadata !15, metadata !DIExpression(), metadata !36, metadata i32* %c, metadata !DIExpression()), !dbg !17 + %1 = load i32, i32* @a, align 4, !dbg !22 + %tobool = icmp ne i32 %1, 0, !dbg !22 + br i1 %tobool, label %if.then, label %if.end, !dbg !24 + +if.then: ; preds = %entry + store i32 1, i32* %c, align 4, !dbg !25, !DIAssignID !37 + call void @llvm.dbg.assign(metadata i32 1, metadata !15, metadata !DIExpression(), metadata !37, metadata i32* %c, metadata !DIExpression()), !dbg !17 + br label %if.end, !dbg !26 + +if.end: ; preds = %if.then, %entry + %2 = bitcast i32* %c to i8*, !dbg !27 + call void @llvm.lifetime.end.p0i8(i64 4, i8* %2), !dbg !27 + ret void, !dbg !27 +} + +declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) +declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) +declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!7, !8, !9} +!llvm.ident = !{!10} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "test.c", directory: "/") +!4 = !{} +!5 = !{!0} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = !{i32 7, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{i32 1, !"wchar_size", i32 4} +!10 = !{!"clang version 12.0.0"} +!11 = distinct !DISubprogram(name: "b", scope: !3, file: !3, line: 2, type: !12, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !14) +!12 = !DISubroutineType(types: !13) +!13 = !{null} +!14 = !{!15} +!15 = !DILocalVariable(name: "c", scope: !11, file: !3, line: 3, type: !6) +!16 = !DILocation(line: 3, column: 3, scope: !11) +!17 = !DILocation(line: 3, column: 7, scope: !11) +!22 = !DILocation(line: 4, column: 7, scope: !23) +!23 = distinct !DILexicalBlock(scope: !11, file: !3, line: 4, column: 7) +!24 = !DILocation(line: 4, column: 7, scope: !11) +!25 = !DILocation(line: 5, column: 7, scope: !23) +!26 = !DILocation(line: 5, column: 5, scope: !23) +!27 = !DILocation(line: 6, column: 1, scope: !11) +!36 = distinct !DIAssignID() +!37 = distinct !DIAssignID()