diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h index db064e1f41f02..e522a268c83b1 100644 --- a/llvm/include/llvm/Transforms/Utils/Local.h +++ b/llvm/include/llvm/Transforms/Utils/Local.h @@ -347,9 +347,13 @@ void salvageDebugInfoForDbgValues(Instruction &I, /// Return = %a /// Ops = llvm::dwarf::DW_OP_LLVM_arg0 llvm::dwarf::DW_OP_add /// AdditionalValues = %b +/// +/// \param KeepType If enabled, only perform salvage that does not modify +/// the type of the value. Value *salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps, SmallVectorImpl &Ops, - SmallVectorImpl &AdditionalValues); + SmallVectorImpl &AdditionalValues, + bool KeepType = false); /// Point debug users of \p From to \p To or salvage them. Use this function /// only when replacing all uses of \p From with \p To, with a guarantee that diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 2f3ea2266e07f..4e96adec5908b 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2398,7 +2398,8 @@ void llvm::salvageDebugInfoForDbgValues( SmallVector Ops; unsigned LocNo = std::distance(DVRLocation.begin(), LocItr); uint64_t CurrentLocOps = SalvagedExpr->getNumLocationOperands(); - Op0 = salvageDebugInfoImpl(I, CurrentLocOps, Ops, AdditionalValues); + Op0 = salvageDebugInfoImpl(I, CurrentLocOps, Ops, AdditionalValues, + DVR->isDbgDeclare()); if (!Op0) break; SalvagedExpr = @@ -2600,11 +2601,15 @@ Value *getSalvageOpsForIcmpOp(ICmpInst *Icmp, uint64_t CurrentLocOps, Value *llvm::salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps, SmallVectorImpl &Ops, - SmallVectorImpl &AdditionalValues) { + SmallVectorImpl &AdditionalValues, + bool KeepType) { auto &M = *I.getModule(); auto &DL = M.getDataLayout(); if (auto *CI = dyn_cast(&I)) { + if (KeepType) + return nullptr; + Value *FromValue = CI->getOperand(0); // No-op casts are irrelevant for debug info. if (CI->isNoopCast(DL)) { diff --git a/llvm/test/Transforms/CodeGenPrepare/X86/cast-debuginfo-salvage.ll b/llvm/test/Transforms/CodeGenPrepare/X86/cast-debuginfo-salvage.ll new file mode 100644 index 0000000000000..f22942d55306f --- /dev/null +++ b/llvm/test/Transforms/CodeGenPrepare/X86/cast-debuginfo-salvage.ll @@ -0,0 +1,33 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +; RUN: opt -S -codegenprepare -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s + +; Make sure we don't produce something like #dbg_declare(i64 %arg) here. +define void @test(i64 %arg) { +; CHECK-LABEL: define void @test( +; CHECK-SAME: i64 [[ARG:%.*]]) { +; CHECK-NEXT: #dbg_declare(ptr poison, [[META4:![0-9]+]], !DIExpression(), [[META6:![0-9]+]]) +; CHECK-NEXT: ret void +; + %inttoptr = inttoptr i64 %arg to ptr + #dbg_declare(ptr %inttoptr, !4, !DIExpression(), !6) + ret void +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 21.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "test.cpp", directory: "/home/npopov/repos/llvm-project", checksumkind: CSK_MD5, checksum: "eabd3d442348430f50ca2f8c28d743e9") +!2 = !{} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !DILocalVariable(name: "c", scope: !5, file: !1, line: 26) +!5 = distinct !DISubprogram(name: "n<(lambda at test.cpp:39:14)>", linkageName: "_ZN1m1nIZN1o1pEvEUl1kE_EE5arrayT_i", scope: null, file: !1, line: 25, spFlags: DISPFlagDefinition, unit: !0) +!6 = !DILocation(line: 26, column: 11, scope: !5) +;. +; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: [[META2:![0-9]+]], globals: [[META2]], splitDebugInlining: false, nameTableKind: None) +; CHECK: [[META1]] = !DIFile(filename: "test.cpp", directory: {{.*}}) +; CHECK: [[META2]] = !{} +; CHECK: [[META4]] = !DILocalVariable(name: "c", scope: [[META5:![0-9]+]], file: [[META1]], line: 26) +; CHECK: [[META5]] = distinct !DISubprogram(name: "n<(lambda at test.cpp:39:14)>", linkageName: "_ZN1m1nIZN1o1pEvEUl1kE_EE5arrayT_i", scope: null, file: [[META1]], line: 25, spFlags: DISPFlagDefinition, unit: [[META0]]) +; CHECK: [[META6]] = !DILocation(line: 26, column: 11, scope: [[META5]]) +;.