Author: hans Date: Thu Jan 29 19:37:17 2015 New Revision: 227537 URL: http://llvm.org/viewvc/llvm-project?rev=227537&view=rev Log: 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 ------------------------------------------------------------------------ Modified: llvm/branches/release_36/ (props changed) llvm/branches/release_36/lib/Transforms/Scalar/GVN.cpp llvm/branches/release_36/test/Transforms/GVN/edge.ll Propchange: llvm/branches/release_36/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Jan 29 19:37:17 2015 @@ -1,3 +1,3 @@ /llvm/branches/Apple/Pertwee:110850,110961 /llvm/branches/type-system-rewrite:133420-134817 -/llvm/trunk:155241,226023,226029,226044,226046,226048,226058,226075,226170-226171,226182,226473,226664,226708,226711,226755,227005,227085,227250,227260-227261,227290,227294,227299-227300,227319,227339 +/llvm/trunk:155241,226023,226029,226044,226046,226048,226058,226075,226170-226171,226182,226473,226664,226708,226711,226755,227005,227085,227250,227260-227261,227290,227294,227299-227300,227319,227339,227491 Modified: llvm/branches/release_36/lib/Transforms/Scalar/GVN.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_36/lib/Transforms/Scalar/GVN.cpp?rev=227537&r1=227536&r2=227537&view=diff ============================================================================== --- llvm/branches/release_36/lib/Transforms/Scalar/GVN.cpp (original) +++ llvm/branches/release_36/lib/Transforms/Scalar/GVN.cpp Thu Jan 29 19:37:17 2015 @@ -2182,9 +2182,16 @@ bool GVN::propagateEquality(Value *LHS, // Handle the floating point versions of equality comparisons too. if ((isKnownTrue && Cmp->getPredicate() == CmpInst::FCMP_OEQ) || - (isKnownFalse && Cmp->getPredicate() == CmpInst::FCMP_UNE)) - Worklist.push_back(std::make_pair(Op0, Op1)); - + (isKnownFalse && Cmp->getPredicate() == CmpInst::FCMP_UNE)) { + // Floating point -0.0 and 0.0 compare equal, so we can't + // propagate a constant based on that comparison. + // FIXME: We should do this optimization if 'no signed zeros' is + // applicable via an instruction-level fast-math-flag or some other + // indicator that relaxed FP semantics are being used. + if (!isa<ConstantFP>(Op1) || !cast<ConstantFP>(Op1)->isZero()) + Worklist.push_back(std::make_pair(Op0, Op1)); + } + // If "A >= B" is known true, replace "A < B" with false everywhere. CmpInst::Predicate NotPred = Cmp->getInversePredicate(); Constant *NotVal = ConstantInt::get(Cmp->getType(), isKnownFalse); Modified: llvm/branches/release_36/test/Transforms/GVN/edge.ll URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_36/test/Transforms/GVN/edge.ll?rev=227537&r1=227536&r2=227537&view=diff ============================================================================== --- llvm/branches/release_36/test/Transforms/GVN/edge.ll (original) +++ llvm/branches/release_36/test/Transforms/GVN/edge.ll Thu Jan 29 19:37:17 2015 @@ -69,11 +69,11 @@ if: br label %return return: - %retval.0 = phi double [ %div, %if ], [ %x, %entry ] - ret double %retval.0 + %retval = phi double [ %div, %if ], [ %x, %entry ] + ret double %retval ; CHECK-LABEL: define double @fcmp_oeq( -; CHECK: %div = fdiv double %x, 2.000000e+00 +; CHECK: %div = fdiv double %x, 2.0 } define double @fcmp_une(double %x, double %y) { @@ -86,10 +86,46 @@ else: br label %return return: - %retval.0 = phi double [ %div, %else ], [ %x, %entry ] - ret double %retval.0 + %retval = phi double [ %div, %else ], [ %x, %entry ] + ret double %retval ; CHECK-LABEL: define double @fcmp_une( -; CHECK: %div = fdiv double %x, 2.000000e+00 +; CHECK: %div = fdiv double %x, 2.0 } +; PR22376 - We can't propagate zero constants because -0.0 +; compares equal to 0.0. If %y is -0.0 in this test case, +; we would produce the wrong sign on the infinity return value. +define double @fcmp_oeq_zero(double %x, double %y) { +entry: + %cmp = fcmp oeq double %y, 0.0 + br i1 %cmp, label %if, label %return + +if: + %div = fdiv double %x, %y + br label %return + +return: + %retval = phi double [ %div, %if ], [ %x, %entry ] + ret double %retval + +; CHECK-LABEL: define double @fcmp_oeq_zero( +; CHECK: %div = fdiv double %x, %y +} + +define double @fcmp_une_zero(double %x, double %y) { +entry: + %cmp = fcmp une double %y, -0.0 + br i1 %cmp, label %return, label %else + +else: + %div = fdiv double %x, %y + br label %return + +return: + %retval = phi double [ %div, %else ], [ %x, %entry ] + ret double %retval + +; CHECK-LABEL: define double @fcmp_une_zero( +; CHECK: %div = fdiv double %x, %y +} _______________________________________________ llvm-branch-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/llvm-branch-commits
