Index: lib/Transforms/Scalar/Scalarizer.cpp =================================================================== --- lib/Transforms/Scalar/Scalarizer.cpp +++ lib/Transforms/Scalar/Scalarizer.cpp @@ -341,8 +341,7 @@ MI != ME; ++MI) if (canTransferMetadata(MI->first)) New->setMetadata(MI->first, MI->second); - if (Op->getDebugLoc() && !New->getDebugLoc()) - New->setDebugLoc(Op->getDebugLoc()); + New->setDebugLoc(Op->getDebugLoc()); } } } Index: test/Transforms/Scalarizer/dbgloc-bug.ll =================================================================== --- test/Transforms/Scalarizer/dbgloc-bug.ll +++ /dev/null @@ -1,86 +0,0 @@ -; RUN: opt -S -march=x86 -scalarizer -o /dev/null %s - -; Reproducer for pr27938 -; https://llvm.org/bugs/show_bug.cgi?id=27938 - -@d = internal unnamed_addr global i1 false -@e = internal unnamed_addr global i16 0 -@a = global i16 0 -@b = global i16 0 - -; Function Attrs: noinline norecurse nounwind readonly -define i16 @f1() #0 !dbg !6 { - %_tmp1 = load i16, i16* @a, align 1, !dbg !10 - ret i16 %_tmp1, !dbg !10 -} - -; Function Attrs: noinline norecurse nounwind -define void @f2() #1 !dbg !11 { -bb1: - %.old = load i16, i16* @b, align 1, !dbg !14 - %_tmp3.old = icmp eq i16 %.old, 0, !dbg !14 - br i1 %_tmp3.old, label %bb3.preheader, label %bb1.bb8_crit_edge, !dbg !14 - -bb1.bb8_crit_edge: ; preds = %bb1 - %_tmp19.b.pre = load i1, i1* @d, align 1 - br label %bb8, !dbg !14 - -bb3.preheader: ; preds = %bb1 - %e.promoted = load i16, i16* @e, align 1, !dbg !16 - %_tmp7 = tail call i16 @f1(), !dbg !16 - %0 = insertelement <4 x i16> , i16 %e.promoted, i32 0 - %broadcast.splatinsert5 = insertelement <4 x i16> undef, i16 %_tmp7, i32 0 - %broadcast.splat6 = shufflevector <4 x i16> %broadcast.splatinsert5, <4 x i16> undef, <4 x i32> zeroinitializer - br label %vector.body - -vector.body: ; preds = %vector.body, %bb3.preheader - %index = phi i16 [ 0, %bb3.preheader ], [ %index.next, %vector.body ] - %vec.phi = phi <4 x i16> [ %0, %bb3.preheader ], [ %1, %vector.body ] - %1 = xor <4 x i16> %vec.phi, %broadcast.splat6, !dbg !16 - %index.next = add i16 %index, 4 - %2 = icmp eq i16 %index.next, -4 - br i1 %2, label %middle.block, label %vector.body - -middle.block: ; preds = %vector.body - %.lcssa = phi <4 x i16> [ %1, %vector.body ] - %rdx.shuf = shufflevector <4 x i16> %.lcssa, <4 x i16> undef, <4 x i32> , !dbg !16 - %bin.rdx = xor <4 x i16> %.lcssa, %rdx.shuf, !dbg !16 - br label %bb3 - -bb3: ; preds = %middle.block - %rdx.shuf7 = shufflevector <4 x i16> %bin.rdx, <4 x i16> undef, <4 x i32> , !dbg !16 - %bin.rdx8 = xor <4 x i16> %bin.rdx, %rdx.shuf7, !dbg !16 - %3 = extractelement <4 x i16> %bin.rdx8, i32 0, !dbg !16 - %_tmp10.2 = xor i16 %3, %_tmp7, !dbg !16 - store i1 true, i1* @d, align 1 - store i16 %_tmp10.2, i16* @e, align 1, !dbg !16 - br label %bb8 - -bb8: ; preds = %bb1.bb8_crit_edge, %bb3 - %_tmp19.b = phi i1 [ %_tmp19.b.pre, %bb1.bb8_crit_edge ], [ true, %bb3 ] - %_tmp19 = zext i1 %_tmp19.b to i16 - store i16 %_tmp19, i16* @b, align 1, !dbg !22 - ret void, !dbg !23 -} - -!llvm.dbg.cu = !{!0} -!llvm.module.flags = !{!3, !4} - -!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, retainedTypes: !2) -!1 = !DIFile(filename: "dbgloc-bug.c", directory: ".") -!2 = !{} -!3 = !{i32 2, !"Dwarf Version", i32 4} -!4 = !{i32 2, !"Debug Info Version", i32 3} -!6 = distinct !DISubprogram(name: "f1", scope: !1, file: !1, line: 9, type: !7, isLocal: false, isDefinition: true, scopeLine: 10, isOptimized: true, unit: !0, variables: !2) -!7 = !DISubroutineType(types: !8) -!8 = !{!9} -!9 = !DIBasicType(name: "short", size: 16, align: 16, encoding: DW_ATE_signed) -!10 = !DILocation(line: 11, column: 5, scope: !6) -!11 = distinct !DISubprogram(name: "f2", scope: !1, file: !1, line: 14, type: !12, isLocal: false, isDefinition: true, scopeLine: 15, isOptimized: true, unit: !0, variables: !2) -!12 = !DISubroutineType(types: !13) -!13 = !{null} -!14 = !DILocation(line: 19, column: 9, scope: !15) -!15 = !DILexicalBlock(scope: !11, file: !1, line: 17, column: 5) -!16 = !DILocation(line: 24, column: 9, scope: !15) -!22 = !DILocation(line: 27, column: 5, scope: !11) -!23 = !DILocation(line: 28, column: 1, scope: !11)