• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -analyze -branch-prob | FileCheck %s
2; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
3
4; Since neither of while.body's out-edges is an exit or a back edge,
5; calcLoopBranchHeuristics should return early without setting the weights.
6; calcFloatingPointHeuristics, which is run later, sets the weights.
7;
8; CHECK: edge while.body -> if.then probability is 0x50000000 / 0x80000000 = 62.50%
9; CHECK: edge while.body -> if.else probability is 0x30000000 / 0x80000000 = 37.50%
10
11define void @foo1(i32 %n, i32* nocapture %b, i32* nocapture %c, i32* nocapture %d, float* nocapture readonly %f0, float* nocapture readonly %f1) {
12entry:
13  %tobool8 = icmp eq i32 %n, 0
14  br i1 %tobool8, label %while.end, label %while.body.lr.ph
15
16while.body.lr.ph:
17  %0 = sext i32 %n to i64
18  br label %while.body
19
20while.body:
21  %indvars.iv = phi i64 [ %0, %while.body.lr.ph ], [ %indvars.iv.next, %if.end ]
22  %b.addr.011 = phi i32* [ %b, %while.body.lr.ph ], [ %b.addr.1, %if.end ]
23  %d.addr.010 = phi i32* [ %d, %while.body.lr.ph ], [ %incdec.ptr4, %if.end ]
24  %c.addr.09 = phi i32* [ %c, %while.body.lr.ph ], [ %c.addr.1, %if.end ]
25  %indvars.iv.next = add nsw i64 %indvars.iv, -1
26  %arrayidx = getelementptr inbounds float, float* %f0, i64 %indvars.iv.next
27  %1 = load float, float* %arrayidx, align 4
28  %arrayidx2 = getelementptr inbounds float, float* %f1, i64 %indvars.iv.next
29  %2 = load float, float* %arrayidx2, align 4
30  %cmp = fcmp une float %1, %2
31  br i1 %cmp, label %if.then, label %if.else
32
33if.then:
34  %incdec.ptr = getelementptr inbounds i32, i32* %b.addr.011, i64 1
35  %3 = load i32, i32* %b.addr.011, align 4
36  %add = add nsw i32 %3, 12
37  store i32 %add, i32* %b.addr.011, align 4
38  br label %if.end
39
40if.else:
41  %incdec.ptr3 = getelementptr inbounds i32, i32* %c.addr.09, i64 1
42  %4 = load i32, i32* %c.addr.09, align 4
43  %sub = add nsw i32 %4, -13
44  store i32 %sub, i32* %c.addr.09, align 4
45  br label %if.end
46
47if.end:
48  %c.addr.1 = phi i32* [ %c.addr.09, %if.then ], [ %incdec.ptr3, %if.else ]
49  %b.addr.1 = phi i32* [ %incdec.ptr, %if.then ], [ %b.addr.011, %if.else ]
50  %incdec.ptr4 = getelementptr inbounds i32, i32* %d.addr.010, i64 1
51  store i32 14, i32* %d.addr.010, align 4
52  %5 = trunc i64 %indvars.iv.next to i32
53  %tobool = icmp eq i32 %5, 0
54  br i1 %tobool, label %while.end, label %while.body
55
56while.end:
57  ret void
58}
59
60