1; RUN: llc < %s | FileCheck %s 2 3; Reduced manually from C source: 4; unsigned __attribute__((noinline, optnone)) useslot(unsigned v) { return v; } 5; void __attribute__((noinline)) f(unsigned cell_offset, unsigned *page_start_) { 6; unsigned cell = page_start_[0]; 7; while (cell) { 8; unsigned bit_offset = cell_offset ? __builtin_ctz(cell) : 32; 9; unsigned bit_mask = 1U << bit_offset; 10; unsigned slot = (cell_offset + bit_offset) << /*log2(sizeof(void*))*/ 3; 11; cell ^= bit_mask + page_start_[slot]; 12; } 13; } 14; int main() { 15; static unsigned pages[32] = {1, 2, 3, 4, 5, 6, 7}; 16; f(3, &pages[0]); 17; } 18 19; We had a bug where the DBG_VALUE instruction for bit_offset would be emitted 20; at the end of the basic block, long after its actual program point. What's 21; interesting in this example is that the !range metadata produces an AssertSext 22; DAG node that gets replaced during ISel. This leads to an unordered SDDbgValue 23; vector, which has to be sorted by IR order before it is processed in parallel 24; with the Orders insertion point vector. 25 26; CHECK-LABEL: f: # @f 27; CHECK: .LBB0_2: # %while.body 28; CHECK: movl $32, %ecx 29; CHECK: testl {{.*}} 30; CHECK: jne .LBB0_4 31; CHECK: # %bb.3: # %if.then 32; CHECK: callq if_then 33; CHECK: movl %eax, %ecx 34; CHECK: .LBB0_4: # %if.end 35; Check that this DEBUG_VALUE comes before the left shift. 36; CHECK: #DEBUG_VALUE: bit_offset <- $ecx 37; CHECK: .cv_loc 0 1 8 28 # t.c:8:28 38; CHECK: movl $1, %[[reg:[^ ]*]] 39; CHECK: shll %cl, %[[reg]] 40 41; ModuleID = 't.c' 42source_filename = "t.c" 43target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" 44target triple = "x86_64-pc-windows-msvc19.0.24215" 45 46; Function Attrs: nounwind readnone speculatable 47declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 48 49declare i32 @if_then() 50 51; Function Attrs: noinline nounwind readonly uwtable 52define void @f(i32 %cell_offset, i32* nocapture %page_start_) local_unnamed_addr #0 !dbg !31 { 53entry: 54 %0 = load i32, i32* %page_start_, align 4, !dbg !45 55 %tobool14 = icmp eq i32 %0, 0, !dbg !47 56 br i1 %tobool14, label %while.end, label %while.body, !dbg !47 57 58while.body: ; preds = %while.body.lr.ph, %while.body 59 %cell.015 = phi i32 [ %0, %entry ], [ %xor, %if.end ] 60 %tobool1 = icmp eq i32 %cell_offset, 0 61 br i1 %tobool1, label %if.then, label %if.end 62 63if.then: 64 %1 = call i32 @if_then(), !dbg !48, !range !49 65 br label %if.end 66 67if.end: 68 %cond = phi i32 [ %1, %if.then ], [ 32, %while.body ] 69 tail call void @llvm.dbg.value(metadata i32 %cond, metadata !39, metadata !DIExpression()), !dbg !51 70 %shl = shl i32 1, %cond, !dbg !52 71 %add = add i32 %cond, %cell_offset, !dbg !54 72 %shl2 = shl i32 %add, 3, !dbg !55 73 %idxprom = zext i32 %shl2 to i64, !dbg !57 74 %arrayidx3 = getelementptr inbounds i32, i32* %page_start_, i64 %idxprom, !dbg !57 75 %2 = load i32, i32* %arrayidx3, align 4, !dbg !57 76 %add4 = add i32 %2, %shl, !dbg !58 77 %xor = xor i32 %add4, %cell.015, !dbg !59 78 tail call void @llvm.dbg.value(metadata i32 %xor, metadata !38, metadata !DIExpression()), !dbg !46 79 %tobool = icmp eq i32 %xor, 0, !dbg !47 80 br i1 %tobool, label %while.end, label %while.body, !dbg !47, !llvm.loop !60 81 82while.end: ; preds = %while.body, %entry 83 ret void, !dbg !62 84} 85 86; Function Attrs: nounwind readnone speculatable 87declare i32 @llvm.cttz.i32(i32, i1) #1 88 89; Function Attrs: nounwind readnone speculatable 90declare void @llvm.dbg.value(metadata, metadata, metadata) #1 91 92attributes #0 = { noinline nounwind readonly uwtable } 93attributes #1 = { nounwind readnone speculatable } 94 95!llvm.dbg.cu = !{!0} 96!llvm.module.flags = !{!14, !15, !16, !17} 97!llvm.ident = !{!18} 98 99!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3) 100!1 = !DIFile(filename: "t.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "f80d0003faf76554dfdec6c95da285cc") 101!2 = !{} 102!3 = !{!4} 103!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) 104!5 = distinct !DIGlobalVariable(name: "pages", scope: !6, file: !1, line: 18, type: !10, isLocal: true, isDefinition: true) 105!6 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 17, type: !7, isLocal: false, isDefinition: true, scopeLine: 17, isOptimized: true, unit: !0, retainedNodes: !2) 106!7 = !DISubroutineType(types: !8) 107!8 = !{!9} 108!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 109!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 1024, elements: !12) 110!11 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) 111!12 = !{!13} 112!13 = !DISubrange(count: 32) 113!14 = !{i32 2, !"CodeView", i32 1} 114!15 = !{i32 2, !"Debug Info Version", i32 3} 115!16 = !{i32 1, !"wchar_size", i32 2} 116!17 = !{i32 7, !"PIC Level", i32 2} 117!18 = !{!"clang version 6.0.0 "} 118!31 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 4, type: !32, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !35) 119!32 = !DISubroutineType(types: !33) 120!33 = !{null, !11, !34} 121!34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) 122!35 = !{!36, !37, !38, !39, !41, !42} 123!36 = !DILocalVariable(name: "page_start_", arg: 2, scope: !31, file: !1, line: 4, type: !34) 124!37 = !DILocalVariable(name: "cell_offset", arg: 1, scope: !31, file: !1, line: 4, type: !11) 125!38 = !DILocalVariable(name: "cell", scope: !31, file: !1, line: 5, type: !11) 126!39 = !DILocalVariable(name: "bit_offset", scope: !40, file: !1, line: 7, type: !11) 127!40 = distinct !DILexicalBlock(scope: !31, file: !1, line: 6, column: 16) 128!41 = !DILocalVariable(name: "bit_mask", scope: !40, file: !1, line: 8, type: !11) 129!42 = !DILocalVariable(name: "slot", scope: !40, file: !1, line: 9, type: !11) 130!43 = !DILocation(line: 4, column: 66, scope: !31) 131!44 = !DILocation(line: 4, column: 43, scope: !31) 132!45 = !DILocation(line: 5, column: 19, scope: !31) 133!46 = !DILocation(line: 5, column: 12, scope: !31) 134!47 = !DILocation(line: 6, column: 3, scope: !31) 135!48 = !DILocation(line: 7, column: 41, scope: !40) 136!49 = !{i32 0, i32 33} 137!50 = !DILocation(line: 7, column: 27, scope: !40) 138!51 = !DILocation(line: 7, column: 14, scope: !40) 139!52 = !DILocation(line: 8, column: 28, scope: !40) 140!53 = !DILocation(line: 8, column: 14, scope: !40) 141!54 = !DILocation(line: 9, column: 34, scope: !40) 142!55 = !DILocation(line: 9, column: 48, scope: !40) 143!56 = !DILocation(line: 9, column: 14, scope: !40) 144!57 = !DILocation(line: 13, column: 24, scope: !40) 145!58 = !DILocation(line: 13, column: 22, scope: !40) 146!59 = !DILocation(line: 13, column: 10, scope: !40) 147!60 = distinct !{!60, !47, !61} 148!61 = !DILocation(line: 14, column: 3, scope: !31) 149!62 = !DILocation(line: 15, column: 1, scope: !31) 150