blob: aff08a63d506e55af8bd188bd89b931397dbfeb6 [file] [log] [blame]
Akira Hatanaka5638b892014-04-14 16:56:19 +00001; RUN: opt < %s -analyze -branch-prob | FileCheck %s
2
3; Since neither of while.body's out-edges is an exit or a back edge,
4; calcLoopBranchHeuristics should return early without setting the weights.
5; calcFloatingPointHeuristics, which is run later, sets the weights.
6;
7; CHECK: edge while.body -> if.then probability is 20 / 32 = 62.5%
8; CHECK: edge while.body -> if.else probability is 12 / 32 = 37.5%
9
10define void @foo1(i32 %n, i32* nocapture %b, i32* nocapture %c, i32* nocapture %d, float* nocapture readonly %f0, float* nocapture readonly %f1) {
11entry:
12 %tobool8 = icmp eq i32 %n, 0
13 br i1 %tobool8, label %while.end, label %while.body.lr.ph
14
15while.body.lr.ph:
16 %0 = sext i32 %n to i64
17 br label %while.body
18
19while.body:
20 %indvars.iv = phi i64 [ %0, %while.body.lr.ph ], [ %indvars.iv.next, %if.end ]
21 %b.addr.011 = phi i32* [ %b, %while.body.lr.ph ], [ %b.addr.1, %if.end ]
22 %d.addr.010 = phi i32* [ %d, %while.body.lr.ph ], [ %incdec.ptr4, %if.end ]
23 %c.addr.09 = phi i32* [ %c, %while.body.lr.ph ], [ %c.addr.1, %if.end ]
24 %indvars.iv.next = add nsw i64 %indvars.iv, -1
David Blaikie79e6c742015-02-27 19:29:02 +000025 %arrayidx = getelementptr inbounds float, float* %f0, i64 %indvars.iv.next
David Blaikiea79ac142015-02-27 21:17:42 +000026 %1 = load float, float* %arrayidx, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000027 %arrayidx2 = getelementptr inbounds float, float* %f1, i64 %indvars.iv.next
David Blaikiea79ac142015-02-27 21:17:42 +000028 %2 = load float, float* %arrayidx2, align 4
Akira Hatanaka5638b892014-04-14 16:56:19 +000029 %cmp = fcmp une float %1, %2
30 br i1 %cmp, label %if.then, label %if.else
31
32if.then:
David Blaikie79e6c742015-02-27 19:29:02 +000033 %incdec.ptr = getelementptr inbounds i32, i32* %b.addr.011, i64 1
David Blaikiea79ac142015-02-27 21:17:42 +000034 %3 = load i32, i32* %b.addr.011, align 4
Akira Hatanaka5638b892014-04-14 16:56:19 +000035 %add = add nsw i32 %3, 12
36 store i32 %add, i32* %b.addr.011, align 4
37 br label %if.end
38
39if.else:
David Blaikie79e6c742015-02-27 19:29:02 +000040 %incdec.ptr3 = getelementptr inbounds i32, i32* %c.addr.09, i64 1
David Blaikiea79ac142015-02-27 21:17:42 +000041 %4 = load i32, i32* %c.addr.09, align 4
Akira Hatanaka5638b892014-04-14 16:56:19 +000042 %sub = add nsw i32 %4, -13
43 store i32 %sub, i32* %c.addr.09, align 4
44 br label %if.end
45
46if.end:
47 %c.addr.1 = phi i32* [ %c.addr.09, %if.then ], [ %incdec.ptr3, %if.else ]
48 %b.addr.1 = phi i32* [ %incdec.ptr, %if.then ], [ %b.addr.011, %if.else ]
David Blaikie79e6c742015-02-27 19:29:02 +000049 %incdec.ptr4 = getelementptr inbounds i32, i32* %d.addr.010, i64 1
Akira Hatanaka5638b892014-04-14 16:56:19 +000050 store i32 14, i32* %d.addr.010, align 4
51 %5 = trunc i64 %indvars.iv.next to i32
52 %tobool = icmp eq i32 %5, 0
53 br i1 %tobool, label %while.end, label %while.body
54
55while.end:
56 ret void
57}
58