1; RUN: opt %s -o - -S --passes=instcombine | FileCheck %s 2; RUN: opt %s -o - -S --passes=instcombine --try-experimental-debuginfo-iterators | FileCheck %s 3; 4; CHECK-LABEL: for.body: 5; CHECK-NEXT: %sub.ptr.rhs.cast.i.i = ptrtoint ptr %call2.i.i to i64, 6; CHECK-NEXT: #dbg_value(i64 %sub.ptr.rhs.cast.i.i, !{{[0-9]*}}, !DIExpression(DW_OP_LLVM_convert, 64, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_constu, 1, DW_OP_minus, DW_OP_stack_value) 7; 8;; The code below is representative of a common situation: where we've had a 9;; loop be completely optimised out, leaving dbg.values representing the 10;; assignments for it, including a rotated assignment to the loop counter. 11;; Below, it's the two dbg.values in the entry block, assigning first the 12;; value of %conv.i, then the value of %conv.i minus one. 13;; 14;; When instcombine sinks %conv.i, it's critical that if it sinks a dbg.value 15;; with it, it sinks the most recent assignment. Otherwise it will re-order the 16;; assignments below, and a fall counter assignment will continue on from the 17;; end of the optimised-out loop. 18;; 19;; The check lines test that when the trunc sinks (along with the ptrtoint), 20;; we get the dbg.value with a DW_OP_minus in it. 21 22; ModuleID = 'tmp.ll' 23source_filename = "tmp.ll" 24target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" 25target triple = "x86_64-unknown-linux-gnu" 26 27declare void @llvm.dbg.value(metadata, metadata, metadata) 28declare void @llvm.dbg.declare(metadata, metadata, metadata) 29 30define void @_ZN4llvm16MCObjectStreamer15EmitInstructionERKNS_6MCInstE(i1 %tobool.not) local_unnamed_addr { 31entry: 32 %call2.i.i = load volatile ptr, ptr null, align 8, !dbg !4 33 %sub.ptr.rhs.cast.i.i = ptrtoint ptr %call2.i.i to i64, !dbg !4 34 %conv.i = trunc i64 %sub.ptr.rhs.cast.i.i to i32, !dbg !4 35 tail call void @llvm.dbg.value(metadata i32 %conv.i, metadata !16, metadata !DIExpression()), !dbg !18 36 tail call void @llvm.dbg.value(metadata i32 %conv.i, metadata !16, metadata !DIExpression(DW_OP_constu, 1, DW_OP_minus, DW_OP_stack_value)), !dbg !18 37 br i1 %tobool.not, label %common.ret, label %for.body 38 39common.ret: ; preds = %for.body, %entry 40 ret void 41 42for.body: ; preds = %entry 43 %call2 = call ptr @_ZNK4llvm6MCInst10getOperandEj(i32 %conv.i) 44 br label %common.ret 45} 46 47declare i32 @_ZNK4llvm6MCInst14getNumOperandsEv() 48 49declare ptr @_ZNK4llvm6MCInst10getOperandEj(i32) local_unnamed_addr 50 51declare i64 @_ZNK4llvm25SmallVectorTemplateCommonINS_9MCOperandEvE4sizeEv() 52 53!llvm.dbg.cu = !{!0} 54!llvm.module.flags = !{!3} 55 56!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, splitDebugInlining: false, nameTableKind: None) 57!1 = !DIFile(filename: "foo.cpp", directory: ".") 58!2 = !{} 59!3 = !{i32 2, !"Debug Info Version", i32 3} 60!4 = !DILocation(line: 197, column: 26, scope: !5) 61!5 = distinct !DILexicalBlock(scope: !7, file: !6, line: 197, column: 3) 62!6 = !DIFile(filename: "foo.cpp", directory: ".") 63!7 = distinct !DISubprogram(name: "EmitInstruction", linkageName: "_ZN4llvm16MCObjectStreamer15EmitInstructionERKNS_6MCInstE", scope: !8, file: !6, line: 195, type: !13, scopeLine: 195, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !15, retainedNodes: !2) 64!8 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "MCObjectStreamer", scope: !10, file: !9, line: 33, size: 2432, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !2, vtableHolder: !11) 65!9 = !DIFile(filename: "bar.h", directory: ".") 66!10 = !DINamespace(name: "llvm", scope: null) 67!11 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "MCStreamer", scope: !10, file: !12, line: 108, size: 2240, flags: DIFlagFwdDecl | DIFlagNonTrivial, identifier: "_ZTSN4llvm10MCStreamerE") 68!12 = !DIFile(filename: "baz.h", directory: ".") 69!13 = distinct !DISubroutineType(types: !14) 70!14 = !{null} 71!15 = !DISubprogram(name: "EmitInstruction", linkageName: "_ZN4llvm16MCObjectStreamer15EmitInstructionERKNS_6MCInstE", scope: !8, file: !9, line: 88, type: !13, scopeLine: 88, containingType: !8, virtualIndex: 86, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagVirtual | DISPFlagOptimized) 72!16 = !DILocalVariable(name: "i", scope: !5, file: !6, line: 197, type: !17) 73!17 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) 74!18 = !DILocation(line: 0, scope: !5) 75