Index: llvm/lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- llvm/lib/CodeGen/CodeGenPrepare.cpp +++ llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -2605,6 +2605,7 @@ /// trunc Opnd to Ty. TruncBuilder(Instruction *Opnd, Type *Ty) : TypePromotionAction(Opnd) { IRBuilder<> Builder(Opnd); + Builder.SetCurrentDebugLocation(DebugLoc()); Val = Builder.CreateTrunc(Opnd, Ty, "promoted"); LLVM_DEBUG(dbgs() << "Do: TruncBuilder: " << *Val << "\n"); } Index: llvm/test/Transforms/CodeGenPrepare/X86/promoted-trunc-loc.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/CodeGenPrepare/X86/promoted-trunc-loc.ll @@ -0,0 +1,65 @@ +; RUN: opt < %s -codegenprepare -S -mtriple=x86_64-unknown-unknown | FileCheck %s + +; Make sure the promoted trunc doesn't get a debug location associated. +; CHECK: %promoted = trunc i32 %or to i16 + +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.13.0" + +@b = global i16 0, align 2 + +declare void @bar(i64) + +define i32 @foo(i16 %kkk) !dbg !6 { +entry: + %t4 = load i16, i16* @b, align 2, !dbg !18 + call void @llvm.dbg.value(metadata i16 %t4, metadata !9, metadata !DIExpression()), !dbg !18 + %conv4 = zext i16 %t4 to i32, !dbg !19 + call void @llvm.dbg.value(metadata i32 %conv4, metadata !11, metadata !DIExpression()), !dbg !19 + %or = or i16 %kkk, %t4, !dbg !20 + call void @llvm.dbg.value(metadata i16 %or, metadata !13, metadata !DIExpression()), !dbg !20 + %c = sext i16 %or to i64, !dbg !21 + call void @llvm.dbg.value(metadata i64 %c, metadata !14, metadata !DIExpression()), !dbg !21 + call void @bar(i64 %c), !dbg !22 + %t5 = and i16 %or, 5, !dbg !23 + call void @llvm.dbg.value(metadata i16 %t5, metadata !16, metadata !DIExpression()), !dbg !23 + %z = zext i16 %t5 to i32, !dbg !24 + call void @llvm.dbg.value(metadata i32 %z, metadata !17, metadata !DIExpression()), !dbg !24 + ret i32 %z, !dbg !25 +} + +; Function Attrs: nounwind readnone speculatable willreturn +declare void @llvm.dbg.value(metadata, metadata, metadata) #0 + +attributes #0 = { nounwind readnone speculatable willreturn } + +!llvm.dbg.cu = !{!0} +!llvm.debugify = !{!3, !4} +!llvm.module.flags = !{!5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "../../llvm-project/llvm/test/Transforms/CodeGenPrepare/X86/multi-extension.ll", directory: "/") +!2 = !{} +!3 = !{i32 8} +!4 = !{i32 6} +!5 = !{i32 2, !"Debug Info Version", i32 3} +!6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8) +!7 = !DISubroutineType(types: !2) +!8 = !{!9, !11, !13, !14, !16, !17} +!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10) +!10 = !DIBasicType(name: "ty16", size: 16, encoding: DW_ATE_unsigned) +!11 = !DILocalVariable(name: "2", scope: !6, file: !1, line: 2, type: !12) +!12 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned) +!13 = !DILocalVariable(name: "3", scope: !6, file: !1, line: 3, type: !10) +!14 = !DILocalVariable(name: "4", scope: !6, file: !1, line: 4, type: !15) +!15 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned) +!16 = !DILocalVariable(name: "5", scope: !6, file: !1, line: 6, type: !10) +!17 = !DILocalVariable(name: "6", scope: !6, file: !1, line: 7, type: !12) +!18 = !DILocation(line: 1, column: 1, scope: !6) +!19 = !DILocation(line: 2, column: 1, scope: !6) +!20 = !DILocation(line: 3, column: 1, scope: !6) +!21 = !DILocation(line: 4, column: 1, scope: !6) +!22 = !DILocation(line: 5, column: 1, scope: !6) +!23 = !DILocation(line: 6, column: 1, scope: !6) +!24 = !DILocation(line: 7, column: 1, scope: !6) +!25 = !DILocation(line: 8, column: 1, scope: !6)