2014-01-10 23:23:51 +00:00
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/calls.prof | opt -analyze -branch-prob | FileCheck %s
; Original C++ test case
;
; #include <stdio.h>
;
; int sum(int x, int y) {
; return x + y;
; }
;
; int main() {
; int s, i = 0;
; while (i++ < 20000 * 20000)
; if (i != 100) s = sum(i, s); else s = 30;
; printf("sum is %d\n", s);
; return 0;
; }
2014-10-22 12:59:00 +00:00
;
; Note that this test is missing the llvm.dbg.cu annotation. This emulates
; the effect of the user having only used -fprofile-sample-use without
; -gmlt when invoking the driver. In those cases, we need to track source
; location information but we do not have to generate debug info in the
; final binary.
2014-01-10 23:23:51 +00:00
@.str = private unnamed_addr constant [ 11 x i8 ] c "sum is %d\0A\00" , align 1
; Function Attrs: nounwind uwtable
define i32 @_Z3sumii ( i32 %x , i32 %y ) {
entry:
%x.addr = alloca i32 , align 4
%y.addr = alloca i32 , align 4
store i32 %x , i32 * %x.addr , align 4
store i32 %y , i32 * %y.addr , align 4
2015-02-27 21:17:42 +00:00
%0 = load i32 , i32 * %x.addr , align 4 , !dbg !11
%1 = load i32 , i32 * %y.addr , align 4 , !dbg !11
2014-01-10 23:23:51 +00:00
%add = add nsw i32 %0 , %1 , !dbg !11
ret i32 %add , !dbg !11
}
; Function Attrs: uwtable
define i32 @main ( ) {
entry:
%retval = alloca i32 , align 4
%s = alloca i32 , align 4
%i = alloca i32 , align 4
store i32 0 , i32 * %retval
store i32 0 , i32 * %i , align 4 , !dbg !12
br label %while.cond , !dbg !13
while.cond: ; preds = %if.end, %entry
2015-02-27 21:17:42 +00:00
%0 = load i32 , i32 * %i , align 4 , !dbg !14
2014-03-10 22:41:28 +00:00
%inc = add nsw i32 %0 , 1 , !dbg !14
store i32 %inc , i32 * %i , align 4 , !dbg !14
%cmp = icmp slt i32 %0 , 400000000 , !dbg !14
br i1 %cmp , label %while.body , label %while.end , !dbg !14
; CHECK: edge while.cond -> while.body probability is 5391 / 5392 = 99.9815% [HOT edge]
; CHECK: edge while.cond -> while.end probability is 1 / 5392 = 0.018546%
2014-01-10 23:23:51 +00:00
while.body: ; preds = %while.cond
2015-02-27 21:17:42 +00:00
%1 = load i32 , i32 * %i , align 4 , !dbg !16
2014-03-10 22:41:28 +00:00
%cmp1 = icmp ne i32 %1 , 100 , !dbg !16
br i1 %cmp1 , label %if.then , label %if.else , !dbg !16
; Without discriminator information, the profiler used to think that
; both branches out of while.body had the same weight. In reality,
; the edge while.body->if.then is taken most of the time.
;
; CHECK: edge while.body -> if.then probability is 5752 / 5753 = 99.9826% [HOT edge]
; CHECK: edge while.body -> if.else probability is 1 / 5753 = 0.0173822%
2014-01-10 23:23:51 +00:00
if.then: ; preds = %while.body
2015-02-27 21:17:42 +00:00
%2 = load i32 , i32 * %i , align 4 , !dbg !18
%3 = load i32 , i32 * %s , align 4 , !dbg !18
2014-03-10 22:41:28 +00:00
%call = call i32 @_Z3sumii ( i32 %2 , i32 %3 ) , !dbg !18
store i32 %call , i32 * %s , align 4 , !dbg !18
br label %if.end , !dbg !18
2014-01-10 23:23:51 +00:00
if.else: ; preds = %while.body
2014-03-10 22:41:28 +00:00
store i32 30 , i32 * %s , align 4 , !dbg !20
2014-01-10 23:23:51 +00:00
br label %if.end
if.end: ; preds = %if.else, %if.then
2014-03-10 22:41:28 +00:00
br label %while.cond , !dbg !22
2014-01-10 23:23:51 +00:00
while.end: ; preds = %while.cond
2015-02-27 21:17:42 +00:00
%4 = load i32 , i32 * %s , align 4 , !dbg !24
2014-03-10 22:41:28 +00:00
%call2 = call i32 ( i8 * , . . . ) * @printf ( i8 * getelementptr inbounds ( [ 11 x i8 ] * @.str , i32 0 , i32 0 ) , i32 %4 ) , !dbg !24
ret i32 0 , !dbg !25
2014-01-10 23:23:51 +00:00
}
2014-03-10 22:41:28 +00:00
declare i32 @printf ( i8 * , . . . ) #2
2014-01-10 23:23:51 +00:00
!llvm.module.flags = ! { !8 , !9 }
!llvm.ident = ! { !10 }
2015-03-03 17:24:31 +00:00
!0 = !MDCompileUnit ( language: D W _ L A N G _ C _ p l u s _ p l u s , producer: "clang version 3.5 " , isOptimized: false , emissionKind: 0 , file: !1 , enums: !2 , retainedTypes: !2 , subprograms: !3 , globals: !2 , imports: !2 )
!1 = !MDFile ( filename: "calls.cc" , directory: "." )
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
!2 = ! { }
!3 = ! { !4 , !7 }
2015-03-03 17:24:31 +00:00
!4 = !MDSubprogram ( name: "sum" , line: 3 , isLocal: false , isDefinition: true , virtualIndex: 6 , flags: D I F l a g P r o t o t y p e d , isOptimized: false , scopeLine: 3 , file: !1 , scope: !5 , type: !6 , function: i32 ( i32 , i32 ) * @_Z3sumii , variables: !2 )
!5 = !MDFile ( filename: "calls.cc" , directory: "." )
!6 = !MDSubroutineType ( types: !2 )
!7 = !MDSubprogram ( name: "main" , line: 7 , isLocal: false , isDefinition: true , virtualIndex: 6 , flags: D I F l a g P r o t o t y p e d , isOptimized: false , scopeLine: 7 , file: !1 , scope: !5 , type: !6 , function: i32 ( ) * @main , variables: !2 )
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
!8 = ! { i32 2 , !"Dwarf Version" , i32 4 }
2015-03-03 17:24:31 +00:00
!9 = ! { i32 1 , !"Debug Info Version" , i32 3 }
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224257 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-15 19:07:53 +00:00
!10 = ! { !"clang version 3.5 " }
2015-01-14 22:27:36 +00:00
!11 = !MDLocation ( line: 4 , scope: !4 )
!12 = !MDLocation ( line: 8 , scope: !7 )
!13 = !MDLocation ( line: 9 , scope: !7 )
!14 = !MDLocation ( line: 9 , scope: !15 )
2015-03-03 17:24:31 +00:00
!15 = !MDLexicalBlockFile ( discriminator: 1 , file: !1 , scope: !7 )
2015-01-14 22:27:36 +00:00
!16 = !MDLocation ( line: 10 , scope: !17 )
2015-03-03 17:24:31 +00:00
!17 = distinct !MDLexicalBlock ( line: 10 , column: 0 , file: !1 , scope: !7 )
2015-01-14 22:27:36 +00:00
!18 = !MDLocation ( line: 10 , scope: !19 )
2015-03-03 17:24:31 +00:00
!19 = !MDLexicalBlockFile ( discriminator: 1 , file: !1 , scope: !17 )
2015-01-14 22:27:36 +00:00
!20 = !MDLocation ( line: 10 , scope: !21 )
2015-03-03 17:24:31 +00:00
!21 = !MDLexicalBlockFile ( discriminator: 2 , file: !1 , scope: !17 )
2015-01-14 22:27:36 +00:00
!22 = !MDLocation ( line: 10 , scope: !23 )
2015-03-03 17:24:31 +00:00
!23 = !MDLexicalBlockFile ( discriminator: 3 , file: !1 , scope: !17 )
2015-01-14 22:27:36 +00:00
!24 = !MDLocation ( line: 11 , scope: !7 )
!25 = !MDLocation ( line: 12 , scope: !7 )