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_4: 28; Check that this DEBUG_VALUE comes before the left shift. 29; CHECK: #DEBUG_VALUE: bit_offset <- $ecx 30; CHECK: .cv_loc 0 1 8 28 # t.c:8:28 31; CHECK: movl $1, %[[reg:[^ ]*]] 32; CHECK: shll %cl, %[[reg]] 33; CHECK: .LBB0_2: # %while.body 34; CHECK: movl $32, %ecx 35; CHECK: testl {{.*}} 36; CHECK: jne .LBB0_4 37; CHECK: # %bb.3: # %if.then 38; CHECK: callq if_then 39; CHECK: movl %eax, %ecx 40; CHECK: jmp .LBB0_4 41 42; ModuleID = 't.c' 43source_filename = "t.c" 44target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" 45target triple = "x86_64-pc-windows-msvc19.0.24215" 46 47; Function Attrs: nounwind readnone speculatable 48declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 49 50declare i32 @if_then() 51 52; Function Attrs: noinline nounwind readonly uwtable 53define void @f(i32 %cell_offset, i32* nocapture %page_start_) local_unnamed_addr #0 !dbg !31 { 54entry: 55 %0 = load i32, i32* %page_start_, align 4, !dbg !45 56 %tobool14 = icmp eq i32 %0, 0, !dbg !47 57 br i1 %tobool14, label %while.end, label %while.body, !dbg !47 58 59while.body: ; preds = %while.body.lr.ph, %while.body 60 %cell.015 = phi i32 [ %0, %entry ], [ %xor, %if.end ] 61 %tobool1 = icmp eq i32 %cell_offset, 0 62 br i1 %tobool1, label %if.then, label %if.end 63 64if.then: 65 %1 = call i32 @if_then(), !dbg !48, !range !49 66 br label %if.end 67 68if.end: 69 %cond = phi i32 [ %1, %if.then ], [ 32, %while.body ] 70 tail call void @llvm.dbg.value(metadata i32 %cond, metadata !39, metadata !DIExpression()), !dbg !51 71 %shl = shl i32 1, %cond, !dbg !52 72 %add = add i32 %cond, %cell_offset, !dbg !54 73 %shl2 = shl i32 %add, 3, !dbg !55 74 %idxprom = zext i32 %shl2 to i64, !dbg !57 75 %arrayidx3 = getelementptr inbounds i32, i32* %page_start_, i64 %idxprom, !dbg !57 76 %2 = load i32, i32* %arrayidx3, align 4, !dbg !57 77 %add4 = add i32 %2, %shl, !dbg !58 78 %xor = xor i32 %add4, %cell.015, !dbg !59 79 tail call void @llvm.dbg.value(metadata i32 %xor, metadata !38, metadata !DIExpression()), !dbg !46 80 %tobool = icmp eq i32 %xor, 0, !dbg !47 81 br i1 %tobool, label %while.end, label %while.body, !dbg !47, !llvm.loop !60 82 83while.end: ; preds = %while.body, %entry 84 ret void, !dbg !62 85} 86 87; Function Attrs: nounwind readnone speculatable 88declare i32 @llvm.cttz.i32(i32, i1) #1 89 90; Function Attrs: nounwind readnone speculatable 91declare void @llvm.dbg.value(metadata, metadata, metadata) #1 92 93attributes #0 = { noinline nounwind readonly uwtable } 94attributes #1 = { nounwind readnone speculatable } 95 96!llvm.dbg.cu = !{!0} 97!llvm.module.flags = !{!14, !15, !16, !17} 98!llvm.ident = !{!18} 99 100!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) 101!1 = !DIFile(filename: "t.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "f80d0003faf76554dfdec6c95da285cc") 102!2 = !{} 103!3 = !{!4} 104!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) 105!5 = distinct !DIGlobalVariable(name: "pages", scope: !6, file: !1, line: 18, type: !10, isLocal: true, isDefinition: true) 106!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) 107!7 = !DISubroutineType(types: !8) 108!8 = !{!9} 109!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 110!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 1024, elements: !12) 111!11 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) 112!12 = !{!13} 113!13 = !DISubrange(count: 32) 114!14 = !{i32 2, !"CodeView", i32 1} 115!15 = !{i32 2, !"Debug Info Version", i32 3} 116!16 = !{i32 1, !"wchar_size", i32 2} 117!17 = !{i32 7, !"PIC Level", i32 2} 118!18 = !{!"clang version 6.0.0 "} 119!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) 120!32 = !DISubroutineType(types: !33) 121!33 = !{null, !11, !34} 122!34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) 123!35 = !{!36, !37, !38, !39, !41, !42} 124!36 = !DILocalVariable(name: "page_start_", arg: 2, scope: !31, file: !1, line: 4, type: !34) 125!37 = !DILocalVariable(name: "cell_offset", arg: 1, scope: !31, file: !1, line: 4, type: !11) 126!38 = !DILocalVariable(name: "cell", scope: !31, file: !1, line: 5, type: !11) 127!39 = !DILocalVariable(name: "bit_offset", scope: !40, file: !1, line: 7, type: !11) 128!40 = distinct !DILexicalBlock(scope: !31, file: !1, line: 6, column: 16) 129!41 = !DILocalVariable(name: "bit_mask", scope: !40, file: !1, line: 8, type: !11) 130!42 = !DILocalVariable(name: "slot", scope: !40, file: !1, line: 9, type: !11) 131!43 = !DILocation(line: 4, column: 66, scope: !31) 132!44 = !DILocation(line: 4, column: 43, scope: !31) 133!45 = !DILocation(line: 5, column: 19, scope: !31) 134!46 = !DILocation(line: 5, column: 12, scope: !31) 135!47 = !DILocation(line: 6, column: 3, scope: !31) 136!48 = !DILocation(line: 7, column: 41, scope: !40) 137!49 = !{i32 0, i32 33} 138!50 = !DILocation(line: 7, column: 27, scope: !40) 139!51 = !DILocation(line: 7, column: 14, scope: !40) 140!52 = !DILocation(line: 8, column: 28, scope: !40) 141!53 = !DILocation(line: 8, column: 14, scope: !40) 142!54 = !DILocation(line: 9, column: 34, scope: !40) 143!55 = !DILocation(line: 9, column: 48, scope: !40) 144!56 = !DILocation(line: 9, column: 14, scope: !40) 145!57 = !DILocation(line: 13, column: 24, scope: !40) 146!58 = !DILocation(line: 13, column: 22, scope: !40) 147!59 = !DILocation(line: 13, column: 10, scope: !40) 148!60 = distinct !{!60, !47, !61} 149!61 = !DILocation(line: 14, column: 3, scope: !31) 150!62 = !DILocation(line: 15, column: 1, scope: !31) 151