llvm-6502/test/Analysis/BlockFrequencyInfo/bad_input.ll
Diego Novillo 32d9020423 Remove 4,096 loop scale limitation.
Summary:
This is part 1 of fixes to address the problems described in
https://llvm.org/bugs/show_bug.cgi?id=22719.

The restriction to limit loop scales to 4,096 does not really prevent
overflows anymore, as the underlying algorithm has changed and does
not seem to suffer from this problem.

Additionally, artificially restricting loop scales to such a low number
skews frequency information, making loops of equal hotness appear to
have very different hotness properties.

The only loops that are artificially restricted to a scale of 4096 are
infinite loops (those loops with an exit mass of 0). This prevents
infinite loops from skewing the frequencies of other regions in the CFG.

At the end of propagation, frequencies are scaled to values that take no
more than 64 bits to represent. When the range of frequencies to be
represented fits within 61 bits, it pushes up the scaling factor to a
minimum of 8 to better distinguish small frequency values. Otherwise,
small frequency values are all saturated down at 1.

Tested on x86_64.

Reviewers: dexonsmith

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D8718

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233826 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-01 17:42:27 +00:00

52 lines
1.4 KiB
LLVM

; RUN: opt < %s -analyze -block-freq | FileCheck %s
declare void @g(i32 %x)
; CHECK-LABEL: Printing analysis {{.*}} for function 'branch_weight_0':
; CHECK-NEXT: block-frequency-info: branch_weight_0
define void @branch_weight_0(i32 %a) {
; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
entry:
br label %for.body
; Check that we get 1,4 instead of 0,3.
; CHECK-NEXT: for.body: float = 4.0,
for.body:
%i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
call void @g(i32 %i)
%inc = add i32 %i, 1
%cmp = icmp ugt i32 %inc, %a
br i1 %cmp, label %for.end, label %for.body, !prof !0
; CHECK-NEXT: for.end: float = 1.0, int = [[ENTRY]]
for.end:
ret void
}
!0 = !{!"branch_weights", i32 0, i32 3}
; CHECK-LABEL: Printing analysis {{.*}} for function 'infinite_loop'
; CHECK-NEXT: block-frequency-info: infinite_loop
define void @infinite_loop(i1 %x) {
; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
entry:
br i1 %x, label %for.body, label %for.end, !prof !1
; Check that the infinite loop is arbitrarily scaled to max out at 4096,
; giving 2048 here.
; CHECK-NEXT: for.body: float = 2048.0,
for.body:
%i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
call void @g(i32 %i)
%inc = add i32 %i, 1
br label %for.body
; Check that the exit weight is half of entry, since half is lost in the
; infinite loop above.
; CHECK-NEXT: for.end: float = 0.5,
for.end:
ret void
}
!1 = !{!"branch_weights", i32 1, i32 1}