Index: lib/CodeGen/LivePhysRegs.cpp =================================================================== --- lib/CodeGen/LivePhysRegs.cpp +++ lib/CodeGen/LivePhysRegs.cpp @@ -70,6 +70,8 @@ /// Simulates liveness when stepping backwards over an instruction(bundle): /// Remove Defs, add uses. This is the recommended way of calculating liveness. void LivePhysRegs::stepBackward(const MachineInstr &MI) { + if (MI.isDebugValue()) + return; // Remove defined registers and regmask kills from the set. removeDefs(MI); Index: test/CodeGen/X86/dbg-changes-codegen-branch-folding2.ll =================================================================== --- test/CodeGen/X86/dbg-changes-codegen-branch-folding2.ll +++ test/CodeGen/X86/dbg-changes-codegen-branch-folding2.ll @@ -0,0 +1,209 @@ +; RUN: llc -mtriple=x86_64-linux < %s | FileCheck %s -check-prefixes CHECK,DEBUG +; RUN: opt -strip-debug < %s | llc -mtriple=x86_64-linux | FileCheck %s +; Previously, -g was influencing branch-folding to +; move code. This was because operands in a DBG_VALUE instruction were being +; accounted for when calling 'LivePhysRegs::stepBackward()'. +; +; Original reproducer, compiled with: +; clang++ -emit-llvm -S -O2 -g +; +; // Reproducer: +; typedef signed __attribute__((ext_vector_type(32))) schar32; +; schar32 i, b; +; char32_t a; +; schar32 fn1() { +; char c = 1; +; volatile char d; +; for (char h = 0; h < 13 && c >= d; ++h) +; c *= h; +; bool e = c > a; +; schar32 f = 2 % b, g = e ? f : i; +; return g; +; } + +; CHECK-LABEL: # %bb.12: +; DEBUG: .loc 1 7 32 +; CHECK-NEXT: cmpb $0, {{-[0-9]+}}(%rsp) +; DEBUG-NEXT: .Ltmp{{[0-9]+}}: +; DEBUG-NEXT: .loc 1 7 3 +; CHECK-NEXT: jg .LBB0_15 +; DEBUG-NEXT: .Ltmp{{[0-9]+}}: +; CHECK-LABEL: # %bb.14 + +@i = dso_local local_unnamed_addr global <32 x i32> zeroinitializer, align 128, !dbg !0 +@b = dso_local local_unnamed_addr global <32 x i32> zeroinitializer, align 128, !dbg !6 +@a = dso_local local_unnamed_addr global i32 0, align 4, !dbg !13 + +define dso_local <32 x i32> @_Z3fn1v() local_unnamed_addr !dbg !20 { + %1 = alloca i8, align 1 + call void @llvm.dbg.value(metadata i8 1, metadata !24, metadata !DIExpression()), !dbg !34 + call void @llvm.dbg.value(metadata i8* %1, metadata !26, metadata !DIExpression()), !dbg !35 + call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %1), !dbg !36 + call void @llvm.dbg.value(metadata i8 0, metadata !28, metadata !DIExpression()), !dbg !37 + call void @llvm.dbg.value(metadata i32 0, metadata !28, metadata !DIExpression()), !dbg !37 + %2 = load volatile i8, i8* %1, align 1, !dbg !38 + call void @llvm.dbg.value(metadata i8 %2, metadata !26, metadata !DIExpression()), !dbg !35 + %3 = icmp sgt i8 %2, 1, !dbg !40 + br i1 %3, label %4, label %12, !dbg !41 + +;