Index: llvm/lib/Transforms/Scalar/SROA.cpp =================================================================== --- llvm/lib/Transforms/Scalar/SROA.cpp +++ llvm/lib/Transforms/Scalar/SROA.cpp @@ -266,11 +266,19 @@ Inst->setMetadata(LLVMContext::MD_DIAssignID, NewID); } - Value = Value ? Value : DbgAssign->getValue(); + ::Value *NewValue = Value ? Value : DbgAssign->getValue(); auto *NewAssign = DIB.insertDbgAssign( - Inst, Value, DbgAssign->getVariable(), Expr, Dest, + Inst, NewValue, DbgAssign->getVariable(), Expr, Dest, DIExpression::get(Ctx, std::nullopt), DbgAssign->getDebugLoc()); + // If we've updated the value but the original dbg.assign has an arglist + // then kill it now - we can't use the requested new value. This should + // be a very rare situation, as it requires the value being stored to differ + // from the dbg.assign (i.e., the value has been represented differently + // in the debug intrinsic for some reason). + if (DbgAssign->hasArgList() && Value) + NewAssign->setKillLocation(); + // We could use more precision here at the cost of some additional (code) // complexity - if the original dbg.assign was adjacent to its store, we // could position this new dbg.assign adjacent to its store rather than the Index: llvm/test/DebugInfo/Generic/assignment-tracking/sroa/arglist.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/Generic/assignment-tracking/sroa/arglist.ll @@ -0,0 +1,75 @@ +; RUN: opt -passes=sroa -S %s -o - | FileCheck %s + +;; Check that a dbg.assign for a promoted variable becomes a kill location if +;; it used an arglist. + +; CHECK: if.then: +; CHECK-NEXT: dbg.value(metadata i32 poison, + +declare i8 @get_i8() + +define internal fastcc i64 @fun() !dbg !18 { +entry: + %codepoint = alloca i32, align 4, !DIAssignID !27 + call void @llvm.dbg.assign(metadata i1 poison, metadata !15, metadata !DIExpression(), metadata !27, metadata ptr %codepoint, metadata !DIExpression()), !dbg !26 + %0 = call i8 @get_i8() #2 + %1 = and i8 %0, 15 + %and14 = zext i8 %1 to i32 + %shl = shl nuw nsw i32 %and14, 12 + %2 = call i8 @get_i8() #2 + %3 = and i8 %2, 63 + %and21 = zext i8 %3 to i32 + %or22 = or i32 %shl, %and21 + %cmp = icmp ugt i32 %or22, 57343 + br i1 %cmp, label %if.then, label %if.else + +if.then: + store i32 %or22, ptr %codepoint, align 4, !DIAssignID !25 + call void @llvm.dbg.assign(metadata !DIArgList(i32 %shl, i32 %and21), metadata !15, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_or, DW_OP_stack_value), metadata !25, metadata ptr %codepoint, metadata !DIExpression()), !dbg !26 + br label %end + +if.else: + store i32 2, ptr %codepoint, align 4, !DIAssignID !28 + call void @llvm.dbg.assign(metadata i32 2, metadata !15, metadata !DIExpression(), metadata !28, metadata ptr %codepoint, metadata !DIExpression()), !dbg !26 + br label %end + +end: + %r = load i32, ptr %codepoint + %rr = sext i32 %r to i64 + ret i64 %rr +} + +declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!13, !14} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !3, imports: !2, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "reduce.cpp", directory: "/") +!2 = !{} +!3 = !{!4, !9} +!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) +!5 = distinct !DIGlobalVariable(scope: null, file: !1, line: 22, type: !6, isLocal: true, isDefinition: true) +!6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 24, elements: !2) +!7 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8) +!8 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression()) +!10 = distinct !DIGlobalVariable(scope: null, file: !11, line: 1245, type: !12, isLocal: true, isDefinition: true) +!11 = !DIFile(filename: "basic_string.h", directory: "") +!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 168, elements: !2) +!13 = !{i32 2, !"Debug Info Version", i32 3} +!14 = !{i32 7, !"debug-info-assignment-tracking", i1 true} +!15 = !DILocalVariable(name: "codepoint", scope: !16, file: !1, line: 10, type: !20) +!16 = distinct !DILexicalBlock(scope: !17, file: !1, line: 9, column: 43) +!17 = distinct !DILexicalBlock(scope: !18, file: !1, line: 7, column: 7) +!18 = distinct !DISubprogram(name: "fun", linkageName: "fun", scope: !1, file: !1, line: 4, type: !19, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) +!19 = distinct !DISubroutineType(types: !2) +!20 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint32_t", file: !21, line: 26, baseType: !22) +!21 = !DIFile(filename: "stdint-uintn.h", directory: "") +!22 = !DIDerivedType(tag: DW_TAG_typedef, name: "__uint32_t", file: !23, line: 41, baseType: !24) +!23 = !DIFile(filename: "types.h", directory: "") +!24 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) +!25 = distinct !DIAssignID() +!26 = !DILocation(line: 0, scope: !16) +!27 = distinct !DIAssignID() +!28 = distinct !DIAssignID()