• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -simplifycfg -S | FileCheck %s
2
3define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
4entry:
5  br i1 %flag, label %if.then, label %if.else
6
7; CHECK-LABEL: test1
8; CHECK: add
9; CHECK: select
10; CHECK: icmp
11; CHECK-NOT: br
12if.then:
13  %cmp = icmp uge i32 %blksA, %nblks
14  %frombool1 = zext i1 %cmp to i8
15  br label %if.end
16
17if.else:
18  %add = add i32 %nblks, %blksB
19  %cmp2 = icmp ule i32 %add, %blksA
20  %frombool3 = zext i1 %cmp2 to i8
21  br label %if.end
22
23if.end:
24  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]
25  %tobool4 = icmp ne i8 %obeys.0, 0
26  ret i1 %tobool4
27}
28
29define zeroext i1 @test2(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
30entry:
31  br i1 %flag, label %if.then, label %if.else
32
33; CHECK-LABEL: test2
34; CHECK: add
35; CHECK: select
36; CHECK: icmp
37; CHECK-NOT: br
38if.then:
39  %cmp = icmp uge i32 %blksA, %nblks
40  %frombool1 = zext i1 %cmp to i8
41  br label %if.end
42
43if.else:
44  %add = add i32 %nblks, %blksB
45  %cmp2 = icmp uge i32 %blksA, %add
46  %frombool3 = zext i1 %cmp2 to i8
47  br label %if.end
48
49if.end:
50  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]
51  %tobool4 = icmp ne i8 %obeys.0, 0
52  ret i1 %tobool4
53}
54
55declare i32 @foo(i32, i32) nounwind readnone
56
57define i32 @test3(i1 zeroext %flag, i32 %x, i32 %y) {
58entry:
59  br i1 %flag, label %if.then, label %if.else
60
61if.then:
62  %x0 = call i32 @foo(i32 %x, i32 0) nounwind readnone
63  %y0 = call i32 @foo(i32 %x, i32 1) nounwind readnone
64  br label %if.end
65
66if.else:
67  %x1 = call i32 @foo(i32 %y, i32 0) nounwind readnone
68  %y1 = call i32 @foo(i32 %y, i32 1) nounwind readnone
69  br label %if.end
70
71if.end:
72  %xx = phi i32 [ %x0, %if.then ], [ %x1, %if.else ]
73  %yy = phi i32 [ %y0, %if.then ], [ %y1, %if.else ]
74  %ret = add i32 %xx, %yy
75  ret i32 %ret
76}
77
78; CHECK-LABEL: test3
79; CHECK: select
80; CHECK: call
81; CHECK: call
82; CHECK: add
83; CHECK-NOT: br
84