1 ; RUN: opt -early-cse -S < %s | FileCheck %s
2 ; RUN: opt -basicaa -early-cse-memssa -S < %s | FileCheck %s
3 ; Same as GVN/edge.ll, but updated to reflect EarlyCSE's less powerful
4 ; implementation. EarlyCSE currently doesn't exploit equality comparisons
7 define i32 @f1(i32 %x) {
8 ; CHECK-LABEL: define i32 @f1(
10 %cmp = icmp eq i32 %x, 0
11 br i1 %cmp, label %bb2, label %bb1
15 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
16 %foo = add i32 %cond, %x
19 ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
22 define i32 @f2(i32 %x) {
23 ; CHECK-LABEL: define i32 @f2(
25 %cmp = icmp ne i32 %x, 0
26 br i1 %cmp, label %bb1, label %bb2
30 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
31 %foo = add i32 %cond, %x
34 ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
37 define i32 @f3(i32 %x) {
38 ; CHECK-LABEL: define i32 @f3(
40 switch i32 %x, label %bb1 [ i32 0, label %bb2]
44 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
45 %foo = add i32 %cond, %x
48 ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]
52 define void @f4(i8 * %x) {
53 ; CHECK-LABEL: define void @f4(
55 %y = icmp eq i8* null, %x
56 br i1 %y, label %bb2, label %bb1
60 %zed = icmp eq i8* null, %x
62 ; CHECK: call void @g(i1 %y)
66 define double @fcmp_oeq_not_zero(double %x, double %y) {
68 %cmp = fcmp oeq double %y, 2.0
69 br i1 %cmp, label %if, label %return
72 %div = fdiv double %x, %y
76 %retval = phi double [ %div, %if ], [ %x, %entry ]
79 ; CHECK-LABEL: define double @fcmp_oeq_not_zero(
80 ; CHECK: %div = fdiv double %x, %y
83 define double @fcmp_une_not_zero(double %x, double %y) {
85 %cmp = fcmp une double %y, 2.0
86 br i1 %cmp, label %return, label %else
89 %div = fdiv double %x, %y
93 %retval = phi double [ %div, %else ], [ %x, %entry ]
96 ; CHECK-LABEL: define double @fcmp_une_not_zero(
97 ; CHECK: %div = fdiv double %x, %y
100 ; PR22376 - We can't propagate zero constants because -0.0
101 ; compares equal to 0.0. If %y is -0.0 in this test case,
102 ; we would produce the wrong sign on the infinity return value.
103 define double @fcmp_oeq_zero(double %x, double %y) {
105 %cmp = fcmp oeq double %y, 0.0
106 br i1 %cmp, label %if, label %return
109 %div = fdiv double %x, %y
113 %retval = phi double [ %div, %if ], [ %x, %entry ]
116 ; CHECK-LABEL: define double @fcmp_oeq_zero(
117 ; CHECK: %div = fdiv double %x, %y
120 define double @fcmp_une_zero(double %x, double %y) {
122 %cmp = fcmp une double %y, -0.0
123 br i1 %cmp, label %return, label %else
126 %div = fdiv double %x, %y
130 %retval = phi double [ %div, %else ], [ %x, %entry ]
133 ; CHECK-LABEL: define double @fcmp_une_zero(
134 ; CHECK: %div = fdiv double %x, %y
137 ; We also cannot propagate a value if it's not a constant.
138 ; This is because the value could be 0.0 or -0.0.
140 define double @fcmp_oeq_maybe_zero(double %x, double %y, double %z1, double %z2) {
142 %z = fadd double %z1, %z2
143 %cmp = fcmp oeq double %y, %z
144 br i1 %cmp, label %if, label %return
147 %div = fdiv double %x, %z
151 %retval = phi double [ %div, %if ], [ %x, %entry ]
154 ; CHECK-LABEL: define double @fcmp_oeq_maybe_zero(
155 ; CHECK: %div = fdiv double %x, %z
158 define double @fcmp_une_maybe_zero(double %x, double %y, double %z1, double %z2) {
160 %z = fadd double %z1, %z2
161 %cmp = fcmp une double %y, %z
162 br i1 %cmp, label %return, label %else
165 %div = fdiv double %x, %z
169 %retval = phi double [ %div, %else ], [ %x, %entry ]
172 ; CHECK-LABEL: define double @fcmp_une_maybe_zero(
173 ; CHECK: %div = fdiv double %x, %z