• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -correlated-propagation -S | FileCheck %s
2
3; CHECK-LABEL: @simple(
4define i8 @simple(i1) {
5entry:
6  %s = select i1 %0, i8 0, i8 1
7  br i1 %0, label %then, label %else
8
9then:
10; CHECK: ret i8 0
11  %a = phi i8 [ %s, %entry ]
12  ret i8 %a
13
14else:
15; CHECK: ret i8 1
16  %b = phi i8 [ %s, %entry ]
17  ret i8 %b
18}
19
20; CHECK-LABEL: @loop(
21define void @loop(i32) {
22entry:
23  br label %loop
24
25loop:
26  %idx = phi i32 [ %0, %entry ], [ %sel, %loop ]
27; CHECK: %idx = phi i32 [ %0, %entry ], [ %2, %loop ]
28  %1 = icmp eq i32 %idx, 0
29  %2 = add i32 %idx, -1
30  %sel = select i1 %1, i32 0, i32 %2
31  br i1 %1, label %out, label %loop
32
33out:
34  ret void
35}
36
37; CHECK-LABEL: @not_correlated(
38define i8 @not_correlated(i1, i1) {
39entry:
40  %s = select i1 %0, i8 0, i8 1
41  br i1 %1, label %then, label %else
42
43then:
44; CHECK: ret i8 %s
45  %a = phi i8 [ %s, %entry ]
46  ret i8 %a
47
48else:
49; CHECK: ret i8 %s
50  %b = phi i8 [ %s, %entry ]
51  ret i8 %b
52}
53
54@c = global i32 0, align 4
55@b = global i32 0, align 4
56
57; CHECK-LABEL: @PR23752(
58define i32 @PR23752() {
59entry:
60  br label %for.body
61
62for.body:
63  %phi = phi i32 [ 0, %entry ], [ %sel, %for.body ]
64  %sel = select i1 icmp sgt (i32* @b, i32* @c), i32 %phi, i32 1
65  %cmp = icmp ne i32 %sel, 1
66  br i1 %cmp, label %for.body, label %if.end
67
68; CHECK:      %[[sel:.*]] = select i1 icmp sgt (i32* @b, i32* @c), i32 0, i32 1
69; CHECK-NEXT: %[[cmp:.*]] = icmp ne i32 %[[sel]], 1
70; CHECK-NEXT: br i1 %[[cmp]]
71
72if.end:
73  ret i32 %sel
74; CHECK: ret i32 1
75}
76