llvm.org GIT mirror llvm / 0ee7686
Merging r230564: ------------------------------------------------------------------------ r230564 | spatel | 2015-02-25 17:46:08 -0500 (Wed, 25 Feb 2015) | 8 lines only propagate equality comparisons of FP values that we are certain are non-zero This is a follow-on to r227491 which tightens the check for propagating FP values. If a non-constant value happens to be a zero, we would hit the same bug as before. Bug noted and patch suggested by Eli Friedman. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@236499 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 4 years ago
2 changed file(s) with 50 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
21822182 // Handle the floating point versions of equality comparisons too.
21832183 if ((isKnownTrue && Cmp->getPredicate() == CmpInst::FCMP_OEQ) ||
21842184 (isKnownFalse && Cmp->getPredicate() == CmpInst::FCMP_UNE)) {
2185 // Floating point -0.0 and 0.0 compare equal, so we can't
2186 // propagate a constant based on that comparison.
2185
2186 // Floating point -0.0 and 0.0 compare equal, so we can only
2187 // propagate values if we know that we have a constant and that
2188 // its value is non-zero.
2189
21872190 // FIXME: We should do this optimization if 'no signed zeros' is
21882191 // applicable via an instruction-level fast-math-flag or some other
21892192 // indicator that relaxed FP semantics are being used.
2190 if (!isa(Op1) || !cast(Op1)->isZero())
2193
2194 if (isa(Op1) && !cast(Op1)->isZero())
21912195 Worklist.push_back(std::make_pair(Op0, Op1));
21922196 }
21932197
5858 ret void
5959 }
6060
61 define double @fcmp_oeq(double %x, double %y) {
61 define double @fcmp_oeq_not_zero(double %x, double %y) {
6262 entry:
6363 %cmp = fcmp oeq double %y, 2.0
6464 br i1 %cmp, label %if, label %return
7171 %retval = phi double [ %div, %if ], [ %x, %entry ]
7272 ret double %retval
7373
74 ; CHECK-LABEL: define double @fcmp_oeq(
74 ; CHECK-LABEL: define double @fcmp_oeq_not_zero(
7575 ; CHECK: %div = fdiv double %x, 2.0
7676 }
7777
78 define double @fcmp_une(double %x, double %y) {
78 define double @fcmp_une_not_zero(double %x, double %y) {
7979 entry:
8080 %cmp = fcmp une double %y, 2.0
8181 br i1 %cmp, label %return, label %else
8888 %retval = phi double [ %div, %else ], [ %x, %entry ]
8989 ret double %retval
9090
91 ; CHECK-LABEL: define double @fcmp_une(
91 ; CHECK-LABEL: define double @fcmp_une_not_zero(
9292 ; CHECK: %div = fdiv double %x, 2.0
9393 }
9494
128128 ; CHECK-LABEL: define double @fcmp_une_zero(
129129 ; CHECK: %div = fdiv double %x, %y
130130 }
131
132 ; We also cannot propagate a value if it's not a constant.
133 ; This is because the value could be 0.0 or -0.0.
134
135 define double @fcmp_oeq_maybe_zero(double %x, double %y, double %z1, double %z2) {
136 entry:
137 %z = fadd double %z1, %z2
138 %cmp = fcmp oeq double %y, %z
139 br i1 %cmp, label %if, label %return
140
141 if:
142 %div = fdiv double %x, %z
143 br label %return
144
145 return:
146 %retval = phi double [ %div, %if ], [ %x, %entry ]
147 ret double %retval
148
149 ; CHECK-LABEL: define double @fcmp_oeq_maybe_zero(
150 ; CHECK: %div = fdiv double %x, %z
151 }
152
153 define double @fcmp_une_maybe_zero(double %x, double %y, double %z1, double %z2) {
154 entry:
155 %z = fadd double %z1, %z2
156 %cmp = fcmp une double %y, %z
157 br i1 %cmp, label %return, label %else
158
159 else:
160 %div = fdiv double %x, %z
161 br label %return
162
163 return:
164 %retval = phi double [ %div, %else ], [ %x, %entry ]
165 ret double %retval
166
167 ; CHECK-LABEL: define double @fcmp_une_maybe_zero(
168 ; CHECK: %div = fdiv double %x, %z
169 }