Index: lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- lib/Transforms/Utils/SimplifyCFG.cpp +++ lib/Transforms/Utils/SimplifyCFG.cpp @@ -1245,6 +1245,9 @@ I2->eraseFromParent(); Changed = true; + if (!isa(I1) && I1->getDebugLoc() != I2->getDebugLoc()) + I1->setDebugLoc(nullptr); + I1 = &*BB1_Itr++; I2 = &*BB2_Itr++; // Skip debug info if it is not identical. Index: test/Transforms/SimplifyCFG/remove-debug.ll =================================================================== --- /dev/null +++ test/Transforms/SimplifyCFG/remove-debug.ll @@ -0,0 +1,81 @@ +; RUN: opt < %s -simplifycfg -S | FileCheck %s + +; CHECK: line: 6 +; CHECK-NOT: line: 7 +; CHECK: line: 8 +; CHECK: line: 9 +; CHECK-NOT: line: 10 +; CHECK: line: 11 + +; Checks if the debug info for hoisted "x = i" is removed +; int x; +; void bar(); +; void baz(); +; +; void foo(int i) { +; if (i == 0) { +; x = i; +; bar(); +; } else { +; x = i; +; baz(); +; } +; } + +target triple = "x86_64-unknown-linux-gnu" + +@x = global i32 0, align 4 + +; Function Attrs: uwtable +define void @_Z3fooi(i32) #0 !dbg !6 { + %2 = alloca i32, align 4 + store i32 %0, i32* %2, align 4, !tbaa !8 + %3 = load i32, i32* %2, align 4, !dbg !12, !tbaa !8 + %4 = icmp eq i32 %3, 0, !dbg !13 + br i1 %4, label %5, label %7, !dbg !12 + +;