• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -early-cse -S < %s | FileCheck %s
2; Same as GVN/edge.ll, but updated to reflect EarlyCSE's less powerful
3; implementation.  EarlyCSE currently doesn't exploit equality comparisons
4; against constants.
5
6define i32 @f1(i32 %x) {
7  ; CHECK-LABEL: define i32 @f1(
8bb0:
9  %cmp = icmp eq i32 %x, 0
10  br i1 %cmp, label %bb2, label %bb1
11bb1:
12  br label %bb2
13bb2:
14  %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
15  %foo = add i32 %cond, %x
16  ret i32 %foo
17  ; CHECK: bb2:
18  ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
19}
20
21define i32 @f2(i32 %x) {
22  ; CHECK-LABEL: define i32 @f2(
23bb0:
24  %cmp = icmp ne i32 %x, 0
25  br i1 %cmp, label %bb1, label %bb2
26bb1:
27  br label %bb2
28bb2:
29  %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
30  %foo = add i32 %cond, %x
31  ret i32 %foo
32  ; CHECK: bb2:
33  ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
34}
35
36define i32 @f3(i32 %x) {
37  ; CHECK-LABEL: define i32 @f3(
38bb0:
39  switch i32 %x, label %bb1 [ i32 0, label %bb2]
40bb1:
41  br label %bb2
42bb2:
43  %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
44  %foo = add i32 %cond, %x
45  ret i32 %foo
46  ; CHECK: bb2:
47  ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
48}
49
50declare void @g(i1)
51define void @f4(i8 * %x)  {
52; CHECK-LABEL: define void @f4(
53bb0:
54  %y = icmp eq i8* null, %x
55  br i1 %y, label %bb2, label %bb1
56bb1:
57  br label %bb2
58bb2:
59  %zed = icmp eq i8* null, %x
60  call void @g(i1 %zed)
61; CHECK: call void @g(i1 %y)
62  ret void
63}
64
65define double @fcmp_oeq_not_zero(double %x, double %y) {
66entry:
67  %cmp = fcmp oeq double %y, 2.0
68  br i1 %cmp, label %if, label %return
69
70if:
71  %div = fdiv double %x, %y
72  br label %return
73
74return:
75  %retval = phi double [ %div, %if ], [ %x, %entry ]
76  ret double %retval
77
78; CHECK-LABEL: define double @fcmp_oeq_not_zero(
79; CHECK: %div = fdiv double %x, %y
80}
81
82define double @fcmp_une_not_zero(double %x, double %y) {
83entry:
84  %cmp = fcmp une double %y, 2.0
85  br i1 %cmp, label %return, label %else
86
87else:
88  %div = fdiv double %x, %y
89  br label %return
90
91return:
92  %retval = phi double [ %div, %else ], [ %x, %entry ]
93  ret double %retval
94
95; CHECK-LABEL: define double @fcmp_une_not_zero(
96; CHECK: %div = fdiv double %x, %y
97}
98
99; PR22376 - We can't propagate zero constants because -0.0
100; compares equal to 0.0. If %y is -0.0 in this test case,
101; we would produce the wrong sign on the infinity return value.
102define double @fcmp_oeq_zero(double %x, double %y) {
103entry:
104  %cmp = fcmp oeq double %y, 0.0
105  br i1 %cmp, label %if, label %return
106
107if:
108  %div = fdiv double %x, %y
109  br label %return
110
111return:
112  %retval = phi double [ %div, %if ], [ %x, %entry ]
113  ret double %retval
114
115; CHECK-LABEL: define double @fcmp_oeq_zero(
116; CHECK: %div = fdiv double %x, %y
117}
118
119define double @fcmp_une_zero(double %x, double %y) {
120entry:
121  %cmp = fcmp une double %y, -0.0
122  br i1 %cmp, label %return, label %else
123
124else:
125  %div = fdiv double %x, %y
126  br label %return
127
128return:
129  %retval = phi double [ %div, %else ], [ %x, %entry ]
130  ret double %retval
131
132; CHECK-LABEL: define double @fcmp_une_zero(
133; CHECK: %div = fdiv double %x, %y
134}
135
136; We also cannot propagate a value if it's not a constant.
137; This is because the value could be 0.0 or -0.0.
138
139define double @fcmp_oeq_maybe_zero(double %x, double %y, double %z1, double %z2) {
140entry:
141 %z = fadd double %z1, %z2
142 %cmp = fcmp oeq double %y, %z
143 br i1 %cmp, label %if, label %return
144
145if:
146 %div = fdiv double %x, %z
147 br label %return
148
149return:
150 %retval = phi double [ %div, %if ], [ %x, %entry ]
151 ret double %retval
152
153; CHECK-LABEL: define double @fcmp_oeq_maybe_zero(
154; CHECK: %div = fdiv double %x, %z
155}
156
157define double @fcmp_une_maybe_zero(double %x, double %y, double %z1, double %z2) {
158entry:
159 %z = fadd double %z1, %z2
160 %cmp = fcmp une double %y, %z
161 br i1 %cmp, label %return, label %else
162
163else:
164 %div = fdiv double %x, %z
165 br label %return
166
167return:
168 %retval = phi double [ %div, %else ], [ %x, %entry ]
169 ret double %retval
170
171; CHECK-LABEL: define double @fcmp_une_maybe_zero(
172; CHECK: %div = fdiv double %x, %z
173}
174