brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · bc59ef6 Raw
91 lines · plain
1; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/discriminator.prof | opt -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s2 3; Original code4;5; 1   int foo(int i) {6; 2     int x = 0;7; 3     while (i < 100) {8; 4       if (i < 5) x--;9; 5       i++;10; 6     }11; 7     return x;12; 8   }13;14; In this test, if the loop is executed 100 times, the decrement operation15; at line 4 should only execute 5 times. This is reflected in the profile16; data for line offset 3.  In Inputs/discriminator.prof, we have:17;18; 3: 10019; 3.1: 520;21; This means that the predicate 'i < 5' (line 3) is executed 100 times,22; but the then branch (line 3.1) is only executed 5 times.23 24define i32 @foo(i32 %i) #0 !dbg !4 {25; CHECK: Printing analysis {{.*}} for function 'foo':26entry:27  %i.addr = alloca i32, align 428  %x = alloca i32, align 429  store i32 %i, ptr %i.addr, align 430  store i32 0, ptr %x, align 4, !dbg !1031  br label %while.cond, !dbg !1132 33while.cond:                                       ; preds = %if.end, %entry34  %0 = load i32, ptr %i.addr, align 4, !dbg !1235  %cmp = icmp slt i32 %0, 100, !dbg !1236  br i1 %cmp, label %while.body, label %while.end, !dbg !1237; CHECK: edge %while.cond -> %while.body probability is 0x7d83ba68 / 0x80000000 = 98.06% [HOT edge]38; CHECK: edge %while.cond -> %while.end probability is 0x027c4598 / 0x80000000 = 1.94%39 40while.body:                                       ; preds = %while.cond41  %1 = load i32, ptr %i.addr, align 4, !dbg !1442  %cmp1 = icmp slt i32 %1, 50, !dbg !1443  br i1 %cmp1, label %if.then, label %if.end, !dbg !1444; CHECK: edge %while.body -> %if.then probability is 0x07878788 / 0x80000000 = 5.88%45; CHECK: edge %while.body -> %if.end probability is 0x78787878 / 0x80000000 = 94.12% [HOT edge]46 47if.then:                                          ; preds = %while.body48  %2 = load i32, ptr %x, align 4, !dbg !1749  %dec = add nsw i32 %2, -1, !dbg !1750  store i32 %dec, ptr %x, align 4, !dbg !1751  br label %if.end, !dbg !1752 53if.end:                                           ; preds = %if.then, %while.body54  %3 = load i32, ptr %i.addr, align 4, !dbg !1955  %inc = add nsw i32 %3, 1, !dbg !1956  store i32 %inc, ptr %i.addr, align 4, !dbg !1957  br label %while.cond, !dbg !2058 59while.end:                                        ; preds = %while.cond60  %4 = load i32, ptr %x, align 4, !dbg !2161  ret i32 %4, !dbg !2162}63 64attributes #0 = {"use-sample-profile"}65 66!llvm.dbg.cu = !{!0}67!llvm.module.flags = !{!7, !8}68!llvm.ident = !{!9}69 70!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.5 ", isOptimized: false, emissionKind: NoDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)71!1 = !DIFile(filename: "discriminator.c", directory: ".")72!2 = !{}73!4 = distinct !DISubprogram(name: "foo", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, file: !1, scope: !5, type: !6, retainedNodes: !2)74!5 = !DIFile(filename: "discriminator.c", directory: ".")75!6 = !DISubroutineType(types: !2)76!7 = !{i32 2, !"Dwarf Version", i32 4}77!8 = !{i32 1, !"Debug Info Version", i32 3}78!9 = !{!"clang version 3.5 "}79!10 = !DILocation(line: 2, scope: !4)80!11 = !DILocation(line: 3, scope: !4)81!12 = !DILocation(line: 3, scope: !13)82!13 = !DILexicalBlockFile(discriminator: 2, file: !1, scope: !4)83!14 = !DILocation(line: 4, scope: !15)84!15 = distinct !DILexicalBlock(line: 4, column: 0, file: !1, scope: !16)85!16 = distinct !DILexicalBlock(line: 3, column: 0, file: !1, scope: !4)86!17 = !DILocation(line: 4, scope: !18)87!18 = !DILexicalBlockFile(discriminator: 2, file: !1, scope: !15)88!19 = !DILocation(line: 5, scope: !16)89!20 = !DILocation(line: 6, scope: !16)90!21 = !DILocation(line: 7, scope: !4)91