1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile 2>&1 | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile 2>&1 | FileCheck %s 3*9880d681SAndroid Build Coastguard Worker; 4*9880d681SAndroid Build Coastguard Worker; Original test case. 5*9880d681SAndroid Build Coastguard Worker; 6*9880d681SAndroid Build Coastguard Worker; 1 #include <stdlib.h> 7*9880d681SAndroid Build Coastguard Worker; 2 8*9880d681SAndroid Build Coastguard Worker; 3 long long foo() { 9*9880d681SAndroid Build Coastguard Worker; 4 long long int sum = 0; 10*9880d681SAndroid Build Coastguard Worker; 5 for (int i = 0; i < 500000000; i++) 11*9880d681SAndroid Build Coastguard Worker; 6 if (i < 1000) 12*9880d681SAndroid Build Coastguard Worker; 7 sum -= i; 13*9880d681SAndroid Build Coastguard Worker; 8 else 14*9880d681SAndroid Build Coastguard Worker; 9 sum += -i * rand(); 15*9880d681SAndroid Build Coastguard Worker; 10 return sum; 16*9880d681SAndroid Build Coastguard Worker; 11 } 17*9880d681SAndroid Build Coastguard Worker; 12 18*9880d681SAndroid Build Coastguard Worker; 13 int main() { return foo() > 0; } 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker; We are expecting foo() to be inlined in main() (almost all the cycles are 21*9880d681SAndroid Build Coastguard Worker; spent inside foo). 22*9880d681SAndroid Build Coastguard Worker; CHECK: remark: remarks.cc:13:21: inlined hot callee '_Z3foov' with 623868 samples into 'main' 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Worker; The back edge for the loop is the hottest edge in the loop subgraph. 25*9880d681SAndroid Build Coastguard Worker; CHECK: remark: remarks.cc:6:9: most popular destination for conditional branches at remarks.cc:5:3 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker; The predicate almost always chooses the 'else' branch. 28*9880d681SAndroid Build Coastguard Worker; CHECK: remark: remarks.cc:9:15: most popular destination for conditional branches at remarks.cc:6:9 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable 31*9880d681SAndroid Build Coastguard Workerdefine i64 @_Z3foov() #0 !dbg !4 { 32*9880d681SAndroid Build Coastguard Workerentry: 33*9880d681SAndroid Build Coastguard Worker %sum = alloca i64, align 8 34*9880d681SAndroid Build Coastguard Worker %i = alloca i32, align 4 35*9880d681SAndroid Build Coastguard Worker %0 = bitcast i64* %sum to i8*, !dbg !19 36*9880d681SAndroid Build Coastguard Worker call void @llvm.lifetime.start(i64 8, i8* %0) #4, !dbg !19 37*9880d681SAndroid Build Coastguard Worker call void @llvm.dbg.declare(metadata i64* %sum, metadata !9, metadata !20), !dbg !21 38*9880d681SAndroid Build Coastguard Worker store i64 0, i64* %sum, align 8, !dbg !21, !tbaa !22 39*9880d681SAndroid Build Coastguard Worker %1 = bitcast i32* %i to i8*, !dbg !26 40*9880d681SAndroid Build Coastguard Worker call void @llvm.lifetime.start(i64 4, i8* %1) #4, !dbg !26 41*9880d681SAndroid Build Coastguard Worker call void @llvm.dbg.declare(metadata i32* %i, metadata !10, metadata !20), !dbg !27 42*9880d681SAndroid Build Coastguard Worker store i32 0, i32* %i, align 4, !dbg !27, !tbaa !28 43*9880d681SAndroid Build Coastguard Worker br label %for.cond, !dbg !26 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Workerfor.cond: ; preds = %for.inc, %entry 46*9880d681SAndroid Build Coastguard Worker %2 = load i32, i32* %i, align 4, !dbg !30, !tbaa !28 47*9880d681SAndroid Build Coastguard Worker %cmp = icmp slt i32 %2, 500000000, !dbg !34 48*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !35 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Workerfor.cond.cleanup: ; preds = %for.cond 51*9880d681SAndroid Build Coastguard Worker %3 = bitcast i32* %i to i8*, !dbg !36 52*9880d681SAndroid Build Coastguard Worker call void @llvm.lifetime.end(i64 4, i8* %3) #4, !dbg !36 53*9880d681SAndroid Build Coastguard Worker br label %for.end 54*9880d681SAndroid Build Coastguard Worker 55*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %for.cond 56*9880d681SAndroid Build Coastguard Worker %4 = load i32, i32* %i, align 4, !dbg !38, !tbaa !28 57*9880d681SAndroid Build Coastguard Worker %cmp1 = icmp slt i32 %4, 1000, !dbg !40 58*9880d681SAndroid Build Coastguard Worker br i1 %cmp1, label %if.then, label %if.else, !dbg !41 59*9880d681SAndroid Build Coastguard Worker 60*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %for.body 61*9880d681SAndroid Build Coastguard Worker %5 = load i32, i32* %i, align 4, !dbg !42, !tbaa !28 62*9880d681SAndroid Build Coastguard Worker %conv = sext i32 %5 to i64, !dbg !42 63*9880d681SAndroid Build Coastguard Worker %6 = load i64, i64* %sum, align 8, !dbg !43, !tbaa !22 64*9880d681SAndroid Build Coastguard Worker %sub = sub nsw i64 %6, %conv, !dbg !43 65*9880d681SAndroid Build Coastguard Worker store i64 %sub, i64* %sum, align 8, !dbg !43, !tbaa !22 66*9880d681SAndroid Build Coastguard Worker br label %if.end, !dbg !44 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Workerif.else: ; preds = %for.body 69*9880d681SAndroid Build Coastguard Worker %7 = load i32, i32* %i, align 4, !dbg !45, !tbaa !28 70*9880d681SAndroid Build Coastguard Worker %sub2 = sub nsw i32 0, %7, !dbg !46 71*9880d681SAndroid Build Coastguard Worker %call = call i32 @rand() #4, !dbg !47 72*9880d681SAndroid Build Coastguard Worker %mul = mul nsw i32 %sub2, %call, !dbg !48 73*9880d681SAndroid Build Coastguard Worker %conv3 = sext i32 %mul to i64, !dbg !46 74*9880d681SAndroid Build Coastguard Worker %8 = load i64, i64* %sum, align 8, !dbg !49, !tbaa !22 75*9880d681SAndroid Build Coastguard Worker %add = add nsw i64 %8, %conv3, !dbg !49 76*9880d681SAndroid Build Coastguard Worker store i64 %add, i64* %sum, align 8, !dbg !49, !tbaa !22 77*9880d681SAndroid Build Coastguard Worker br label %if.end 78*9880d681SAndroid Build Coastguard Worker 79*9880d681SAndroid Build Coastguard Workerif.end: ; preds = %if.else, %if.then 80*9880d681SAndroid Build Coastguard Worker br label %for.inc, !dbg !50 81*9880d681SAndroid Build Coastguard Worker 82*9880d681SAndroid Build Coastguard Workerfor.inc: ; preds = %if.end 83*9880d681SAndroid Build Coastguard Worker %9 = load i32, i32* %i, align 4, !dbg !51, !tbaa !28 84*9880d681SAndroid Build Coastguard Worker %inc = add nsw i32 %9, 1, !dbg !51 85*9880d681SAndroid Build Coastguard Worker store i32 %inc, i32* %i, align 4, !dbg !51, !tbaa !28 86*9880d681SAndroid Build Coastguard Worker br label %for.cond, !dbg !52 87*9880d681SAndroid Build Coastguard Worker 88*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.cond.cleanup 89*9880d681SAndroid Build Coastguard Worker %10 = load i64, i64* %sum, align 8, !dbg !53, !tbaa !22 90*9880d681SAndroid Build Coastguard Worker %11 = bitcast i64* %sum to i8*, !dbg !54 91*9880d681SAndroid Build Coastguard Worker call void @llvm.lifetime.end(i64 8, i8* %11) #4, !dbg !54 92*9880d681SAndroid Build Coastguard Worker ret i64 %10, !dbg !55 93*9880d681SAndroid Build Coastguard Worker} 94*9880d681SAndroid Build Coastguard Worker 95*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind argmemonly 96*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.lifetime.start(i64, i8* nocapture) #1 97*9880d681SAndroid Build Coastguard Worker 98*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone 99*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.dbg.declare(metadata, metadata, metadata) #2 100*9880d681SAndroid Build Coastguard Worker 101*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind 102*9880d681SAndroid Build Coastguard Workerdeclare i32 @rand() #3 103*9880d681SAndroid Build Coastguard Worker 104*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind argmemonly 105*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.lifetime.end(i64, i8* nocapture) #1 106*9880d681SAndroid Build Coastguard Worker 107*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable 108*9880d681SAndroid Build Coastguard Workerdefine i32 @main() #0 !dbg !13 { 109*9880d681SAndroid Build Coastguard Workerentry: 110*9880d681SAndroid Build Coastguard Worker %retval = alloca i32, align 4 111*9880d681SAndroid Build Coastguard Worker store i32 0, i32* %retval, align 4 112*9880d681SAndroid Build Coastguard Worker %call = call i64 @_Z3foov(), !dbg !56 113*9880d681SAndroid Build Coastguard Worker %cmp = icmp sgt i64 %call, 0, !dbg !57 114*9880d681SAndroid Build Coastguard Worker %conv = zext i1 %cmp to i32, !dbg !56 115*9880d681SAndroid Build Coastguard Worker ret i32 %conv, !dbg !58 116*9880d681SAndroid Build Coastguard Worker} 117*9880d681SAndroid Build Coastguard Worker 118*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } 119*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind argmemonly } 120*9880d681SAndroid Build Coastguard Workerattributes #2 = { nounwind readnone } 121*9880d681SAndroid Build Coastguard Workerattributes #3 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } 122*9880d681SAndroid Build Coastguard Workerattributes #4 = { nounwind } 123*9880d681SAndroid Build Coastguard Worker 124*9880d681SAndroid Build Coastguard Worker!llvm.dbg.cu = !{!0} 125*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!16, !17} 126*9880d681SAndroid Build Coastguard Worker!llvm.ident = !{!18} 127*9880d681SAndroid Build Coastguard Worker 128*9880d681SAndroid Build Coastguard Worker!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 251041) (llvm/trunk 251053)", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, enums: !2) 129*9880d681SAndroid Build Coastguard Worker!1 = !DIFile(filename: "remarks.cc", directory: ".") 130*9880d681SAndroid Build Coastguard Worker!2 = !{} 131*9880d681SAndroid Build Coastguard Worker!4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !8) 132*9880d681SAndroid Build Coastguard Worker!5 = !DISubroutineType(types: !6) 133*9880d681SAndroid Build Coastguard Worker!6 = !{!7} 134*9880d681SAndroid Build Coastguard Worker!7 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed) 135*9880d681SAndroid Build Coastguard Worker!8 = !{!9, !10} 136*9880d681SAndroid Build Coastguard Worker!9 = !DILocalVariable(name: "sum", scope: !4, file: !1, line: 4, type: !7) 137*9880d681SAndroid Build Coastguard Worker!10 = !DILocalVariable(name: "i", scope: !11, file: !1, line: 5, type: !12) 138*9880d681SAndroid Build Coastguard Worker!11 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5, column: 3) 139*9880d681SAndroid Build Coastguard Worker!12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 140*9880d681SAndroid Build Coastguard Worker!13 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 13, type: !14, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2) 141*9880d681SAndroid Build Coastguard Worker!14 = !DISubroutineType(types: !15) 142*9880d681SAndroid Build Coastguard Worker!15 = !{!12} 143*9880d681SAndroid Build Coastguard Worker!16 = !{i32 2, !"Dwarf Version", i32 4} 144*9880d681SAndroid Build Coastguard Worker!17 = !{i32 2, !"Debug Info Version", i32 3} 145*9880d681SAndroid Build Coastguard Worker!18 = !{!"clang version 3.8.0 (trunk 251041) (llvm/trunk 251053)"} 146*9880d681SAndroid Build Coastguard Worker!19 = !DILocation(line: 4, column: 3, scope: !4) 147*9880d681SAndroid Build Coastguard Worker!20 = !DIExpression() 148*9880d681SAndroid Build Coastguard Worker!21 = !DILocation(line: 4, column: 17, scope: !4) 149*9880d681SAndroid Build Coastguard Worker!22 = !{!23, !23, i64 0} 150*9880d681SAndroid Build Coastguard Worker!23 = !{!"long long", !24, i64 0} 151*9880d681SAndroid Build Coastguard Worker!24 = !{!"omnipotent char", !25, i64 0} 152*9880d681SAndroid Build Coastguard Worker!25 = !{!"Simple C/C++ TBAA"} 153*9880d681SAndroid Build Coastguard Worker!26 = !DILocation(line: 5, column: 8, scope: !11) 154*9880d681SAndroid Build Coastguard Worker!27 = !DILocation(line: 5, column: 12, scope: !11) 155*9880d681SAndroid Build Coastguard Worker!28 = !{!29, !29, i64 0} 156*9880d681SAndroid Build Coastguard Worker!29 = !{!"int", !24, i64 0} 157*9880d681SAndroid Build Coastguard Worker!30 = !DILocation(line: 5, column: 19, scope: !31) 158*9880d681SAndroid Build Coastguard Worker!31 = !DILexicalBlockFile(scope: !32, file: !1, discriminator: 3) 159*9880d681SAndroid Build Coastguard Worker!32 = !DILexicalBlockFile(scope: !33, file: !1, discriminator: 1) 160*9880d681SAndroid Build Coastguard Worker!33 = distinct !DILexicalBlock(scope: !11, file: !1, line: 5, column: 3) 161*9880d681SAndroid Build Coastguard Worker!34 = !DILocation(line: 5, column: 21, scope: !33) 162*9880d681SAndroid Build Coastguard Worker!35 = !DILocation(line: 5, column: 3, scope: !11) 163*9880d681SAndroid Build Coastguard Worker!36 = !DILocation(line: 5, column: 3, scope: !37) 164*9880d681SAndroid Build Coastguard Worker!37 = !DILexicalBlockFile(scope: !33, file: !1, discriminator: 2) 165*9880d681SAndroid Build Coastguard Worker!38 = !DILocation(line: 6, column: 9, scope: !39) 166*9880d681SAndroid Build Coastguard Worker!39 = distinct !DILexicalBlock(scope: !33, file: !1, line: 6, column: 9) 167*9880d681SAndroid Build Coastguard Worker!40 = !DILocation(line: 6, column: 11, scope: !39) 168*9880d681SAndroid Build Coastguard Worker!41 = !DILocation(line: 6, column: 9, scope: !33) 169*9880d681SAndroid Build Coastguard Worker!42 = !DILocation(line: 7, column: 14, scope: !39) 170*9880d681SAndroid Build Coastguard Worker!43 = !DILocation(line: 7, column: 11, scope: !39) 171*9880d681SAndroid Build Coastguard Worker!44 = !DILocation(line: 7, column: 7, scope: !39) 172*9880d681SAndroid Build Coastguard Worker!45 = !DILocation(line: 9, column: 15, scope: !39) 173*9880d681SAndroid Build Coastguard Worker!46 = !DILocation(line: 9, column: 14, scope: !39) 174*9880d681SAndroid Build Coastguard Worker!47 = !DILocation(line: 9, column: 19, scope: !39) 175*9880d681SAndroid Build Coastguard Worker!48 = !DILocation(line: 9, column: 17, scope: !39) 176*9880d681SAndroid Build Coastguard Worker!49 = !DILocation(line: 9, column: 11, scope: !39) 177*9880d681SAndroid Build Coastguard Worker!50 = !DILocation(line: 6, column: 13, scope: !39) 178*9880d681SAndroid Build Coastguard Worker!51 = !DILocation(line: 5, column: 35, scope: !33) 179*9880d681SAndroid Build Coastguard Worker!52 = !DILocation(line: 5, column: 3, scope: !33) 180*9880d681SAndroid Build Coastguard Worker!53 = !DILocation(line: 10, column: 10, scope: !4) 181*9880d681SAndroid Build Coastguard Worker!54 = !DILocation(line: 11, column: 1, scope: !4) 182*9880d681SAndroid Build Coastguard Worker!55 = !DILocation(line: 10, column: 3, scope: !4) 183*9880d681SAndroid Build Coastguard Worker!56 = !DILocation(line: 13, column: 21, scope: !13) 184*9880d681SAndroid Build Coastguard Worker!57 = !DILocation(line: 13, column: 27, scope: !13) 185*9880d681SAndroid Build Coastguard Worker!58 = !DILocation(line: 13, column: 14, scope: !13) 186