1 ;RUN: opt -loop-unswitch -enable-new-pm=0 -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s
3 define i32 @foo(i32 %a, i32 %b) {
6 br label %for.body.lr.ph
8 for.body.lr.ph: ; preds = %entry
9 %cmp0 = icmp sgt i32 %b, 0
10 br i1 %cmp0, label %for.body, label %for.cond.cleanup
12 for.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 %for.body.us, label %for.body, !prof !0
20 if.then: ; preds = %for.body
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 %for.body.us
25 %add = add nsw i32 %add.i, 123
28 if.else: ; preds = %for.body
29 %mul = mul nsw i32 %mul.i, %b
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 %for.body
36 for.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
43 for.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
50 define void @foo_swapped(i32 %a, i32 %b) {
51 ;CHECK-LABEL: foo_swapped
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
58 for.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
65 if.then: ; preds = %for.body
66 %add = add nsw i32 %a, %add.i
68 %exitcond = icmp eq i32 %inc, %b
69 br i1 %exitcond, label %for.cond.cleanup, label %for.body
71 for.cond.cleanup: ; preds = %for.inc, %for.body.lr.ph, %for.body
74 !0 = !{!"branch_weights", i32 64, i32 4}
76 ;CHECK: !0 = !{!"branch_weights", i32 64, i32 4}
77 ;CHECK: !1 = !{!"branch_weights", i32 4, i32 64}