diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -1693,6 +1693,7 @@ continue; if (IV.getConstantRange().isAllNonNegative()) { auto *ZExt = new ZExtInst(ExtOp, Inst.getType(), "", &Inst); + ZExt->setDebugLoc(Inst.getDebugLoc()); InsertedValues.insert(ZExt); Inst.replaceAllUsesWith(ZExt); Solver.removeLatticeValueFor(&Inst); diff --git a/llvm/test/Transforms/SCCP/sccp_preserve_debugloc.ll b/llvm/test/Transforms/SCCP/sccp_preserve_debugloc.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/SCCP/sccp_preserve_debugloc.ll @@ -0,0 +1,62 @@ +; RUN: opt -sccp -S < %s | FileCheck %s +; COM: check whether the debug location is preserved +; CHECK: %{{[a-zA-Z0-9_]*}} = zext i32 %tmp9 to i64, !dbg !{{[0-9]*}} +source_filename = "abc.ll" +target triple = "x86_64-unknown-linux-gnu" + +define void @foo(i64* %arg) !dbg !6 { +bb: + %tmp = zext i8 undef to i32, !dbg !8 + %tmp1 = getelementptr inbounds i64, i64* %arg, i32 0, !dbg !9 + %tmp2 = load i64, i64* %tmp1, align 8, !dbg !10 + switch i32 %tmp, label %bb20 [ + i32 1, label %bb3 + i32 2, label %bb4 + i32 4, label %bb19 + ], !dbg !11 + +bb3: ; preds = %bb + unreachable, !dbg !12 + +bb4: ; preds = %bb + %tmp5 = add i64 %tmp2, 3, !dbg !13 + %tmp6 = and i64 %tmp5, 3, !dbg !14 + %tmp7 = sub i64 3, %tmp6, !dbg !15 + %tmp8 = shl i64 %tmp7, 1, !dbg !16 + %tmp9 = trunc i64 %tmp8 to i32, !dbg !17 + %tmp10 = sext i32 %tmp9 to i64, !dbg !18 + unreachable, !dbg !19 + +bb19: ; preds = %bb + unreachable, !dbg !20 + +bb20: ; preds = %bb + ret void, !dbg !21 +} + +!llvm.module.flags = !{!0} +!llvm.dbg.cu = !{!1} +!llvm.debugify = !{!4, !5} + +!0 = !{i32 2, !"Debug Info Version", i32 3} +!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3) +!2 = !DIFile(filename: "bugpoint-reduced-simplified.bc", directory: "/") +!3 = !{} +!4 = !{i32 14} +!5 = !{i32 0} +!6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !2, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !1, retainedNodes: !3) +!7 = !DISubroutineType(types: !3) +!8 = !DILocation(line: 1, column: 1, scope: !6) +!9 = !DILocation(line: 2, column: 1, scope: !6) +!10 = !DILocation(line: 3, column: 1, scope: !6) +!11 = !DILocation(line: 4, column: 1, scope: !6) +!12 = !DILocation(line: 5, column: 1, scope: !6) +!13 = !DILocation(line: 6, column: 1, scope: !6) +!14 = !DILocation(line: 7, column: 1, scope: !6) +!15 = !DILocation(line: 8, column: 1, scope: !6) +!16 = !DILocation(line: 9, column: 1, scope: !6) +!17 = !DILocation(line: 10, column: 1, scope: !6) +!18 = !DILocation(line: 11, column: 1, scope: !6) +!19 = !DILocation(line: 12, column: 1, scope: !6) +!20 = !DILocation(line: 13, column: 1, scope: !6) +!21 = !DILocation(line: 14, column: 1, scope: !6)