• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1;RUN: opt  -loop-unswitch -simplifycfg -S < %s | FileCheck %s
2
3define i32 @foo(i32 %a, i32 %b) {
4;CHECK-LABEL: foo
5entry:
6  br label %for.body.lr.ph
7
8for.body.lr.ph:                                   ; preds = %entry
9  %cmp0 = icmp sgt i32 %b, 0
10  br i1 %cmp0, label %for.body, label %for.cond.cleanup
11
12for.body:                                         ; preds = %for.inc, %for.body.lr.ph
13  %inc.i = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
14  %mul.i = phi i32 [ 3, %for.body.lr.ph ], [ %mul.p, %for.inc ]
15  %add.i = phi i32 [ %a, %for.body.lr.ph ], [ %add.p, %for.inc ]
16  %cmp1 = icmp eq i32 %a, 12345
17  br i1 %cmp1, label %if.then, label %if.else, !prof !0
18; CHECK: %cmp1 = icmp eq i32 %a, 12345
19; CHECK-NEXT: br i1 %cmp1, label %if.then.us, label %if.else, !prof !0
20if.then:                                          ; preds = %for.body
21; CHECK: if.then.us:
22; CHECK: add nsw i32 %{{.*}}, 123
23; CHECK: %exitcond.us = icmp eq i32 %inc.us, %b
24; CHECK: br i1 %exitcond.us, label %for.cond.cleanup, label %if.then.us
25  %add = add nsw i32 %add.i, 123
26  br label %for.inc
27
28if.else:                                          ; preds = %for.body
29  %mul = mul nsw i32 %mul.i, %b
30  br label %for.inc
31; CHECK: if.else:
32; CHECK: %mul = mul nsw i32 %mul.i, %b
33; CHECK: %inc = add nuw nsw i32 %inc.i, 1
34; CHECK: %exitcond = icmp eq i32 %inc, %b
35; CHECK: br i1 %exitcond, label %for.cond.cleanup, label %if.else
36for.inc:                                          ; preds = %if.then, %if.else
37  %mul.p = phi i32 [ %b, %if.then ], [ %mul, %if.else ]
38  %add.p = phi i32 [ %add, %if.then ], [ %a, %if.else ]
39  %inc = add nuw nsw i32 %inc.i, 1
40  %exitcond = icmp eq i32 %inc, %b
41  br i1 %exitcond, label %for.cond.cleanup, label %for.body
42
43for.cond.cleanup:                                 ; preds = %for.inc, %for.body.lr.ph
44  %t2 = phi i32 [ %b, %for.body.lr.ph ], [ %mul.p, %for.inc ]
45  %t1 = phi i32 [ %a, %for.body.lr.ph ], [ %add.p, %for.inc ]
46  %add3 = add nsw i32 %t2, %t1
47  ret i32 %add3
48}
49
50define void @foo_swapped(i32 %a, i32 %b) {
51;CHECK-LABEL: foo_swapped
52entry:
53  br label %for.body
54;CHECK: entry:
55;CHECK-NEXT: %cmp1 = icmp eq i32 1, 2
56;CHECK-NEXT: br i1 %cmp1, label %for.body, label %for.cond.cleanup.split, !prof !1
57;CHECK: for.body:
58for.body:                                         ; preds = %for.inc, %entry
59  %inc.i = phi i32 [ 0, %entry ], [ %inc, %if.then ]
60  %add.i = phi i32 [ 100, %entry ], [ %add, %if.then ]
61  %inc = add nuw nsw i32 %inc.i, 1
62  %cmp1 = icmp eq i32 1, 2
63  br i1 %cmp1, label %if.then, label  %for.cond.cleanup, !prof !0
64
65if.then:                                          ; preds = %for.body
66  %add = add nsw i32 %a, %add.i
67
68  %exitcond = icmp eq i32 %inc, %b
69  br i1 %exitcond, label %for.cond.cleanup, label %for.body
70
71for.cond.cleanup:                                 ; preds = %for.inc, %for.body.lr.ph, %for.body
72  ret void
73}
74!0 = !{!"branch_weights", i32 64, i32 4}
75
76;CHECK: !0 = !{!"branch_weights", i32 64, i32 4}
77;CHECK: !1 = !{!"branch_weights", i32 4, i32 64}
78