llvm.org GIT mirror llvm / 76a77fb
Merging r227491: ------------------------------------------------------------------------ r227491 | spatel | 2015-01-29 12:51:49 -0800 (Thu, 29 Jan 2015) | 13 lines [GVN] don't propagate equality comparisons of FP zero (PR22376) In http://reviews.llvm.org/D6911, we allowed GVN to propagate FP equalities to allow some simple value range optimizations. But that introduced a bug when comparing to -0.0 or 0.0: these compare equal even though they are not bitwise identical. This patch disallows propagating zero constants in equality comparisons. Fixes: http://llvm.org/bugs/show_bug.cgi?id=22376 Differential Revision: http://reviews.llvm.org/D7257 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@227537 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 5 years ago
2 changed file(s) with 52 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
21812181
21822182 // Handle the floating point versions of equality comparisons too.
21832183 if ((isKnownTrue && Cmp->getPredicate() == CmpInst::FCMP_OEQ) ||
2184 (isKnownFalse && Cmp->getPredicate() == CmpInst::FCMP_UNE))
2185 Worklist.push_back(std::make_pair(Op0, Op1));
2186
2184 (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.
2187 // FIXME: We should do this optimization if 'no signed zeros' is
2188 // applicable via an instruction-level fast-math-flag or some other
2189 // indicator that relaxed FP semantics are being used.
2190 if (!isa(Op1) || !cast(Op1)->isZero())
2191 Worklist.push_back(std::make_pair(Op0, Op1));
2192 }
2193
21872194 // If "A >= B" is known true, replace "A < B" with false everywhere.
21882195 CmpInst::Predicate NotPred = Cmp->getInversePredicate();
21892196 Constant *NotVal = ConstantInt::get(Cmp->getType(), isKnownFalse);
6868 br label %return
6969
7070 return:
71 %retval.0 = phi double [ %div, %if ], [ %x, %entry ]
72 ret double %retval.0
71 %retval = phi double [ %div, %if ], [ %x, %entry ]
72 ret double %retval
7373
7474 ; CHECK-LABEL: define double @fcmp_oeq(
75 ; CHECK: %div = fdiv double %x, 2.000000e+00
75 ; CHECK: %div = fdiv double %x, 2.0
7676 }
7777
7878 define double @fcmp_une(double %x, double %y) {
8585 br label %return
8686
8787 return:
88 %retval.0 = phi double [ %div, %else ], [ %x, %entry ]
89 ret double %retval.0
88 %retval = phi double [ %div, %else ], [ %x, %entry ]
89 ret double %retval
9090
9191 ; CHECK-LABEL: define double @fcmp_une(
92 ; CHECK: %div = fdiv double %x, 2.000000e+00
92 ; CHECK: %div = fdiv double %x, 2.0
9393 }
9494
95 ; PR22376 - We can't propagate zero constants because -0.0
96 ; compares equal to 0.0. If %y is -0.0 in this test case,
97 ; we would produce the wrong sign on the infinity return value.
98 define double @fcmp_oeq_zero(double %x, double %y) {
99 entry:
100 %cmp = fcmp oeq double %y, 0.0
101 br i1 %cmp, label %if, label %return
102
103 if:
104 %div = fdiv double %x, %y
105 br label %return
106
107 return:
108 %retval = phi double [ %div, %if ], [ %x, %entry ]
109 ret double %retval
110
111 ; CHECK-LABEL: define double @fcmp_oeq_zero(
112 ; CHECK: %div = fdiv double %x, %y
113 }
114
115 define double @fcmp_une_zero(double %x, double %y) {
116 entry:
117 %cmp = fcmp une double %y, -0.0
118 br i1 %cmp, label %return, label %else
119
120 else:
121 %div = fdiv double %x, %y
122 br label %return
123
124 return:
125 %retval = phi double [ %div, %else ], [ %x, %entry ]
126 ret double %retval
127
128 ; CHECK-LABEL: define double @fcmp_une_zero(
129 ; CHECK: %div = fdiv double %x, %y
130 }