[llvm-branch-commits] [llvm-branch] r236499 - Merging r230564:
Tom Stellard
thomas.stellard at amd.com
Tue May 5 07:43:00 PDT 2015
Author: tstellar
Date: Tue May 5 09:43:00 2015
New Revision: 236499
URL: http://llvm.org/viewvc/llvm-project?rev=236499&view=rev
Log:
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.
------------------------------------------------------------------------
Modified:
llvm/branches/release_36/lib/Transforms/Scalar/GVN.cpp
llvm/branches/release_36/test/Transforms/GVN/edge.ll
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=236499&r1=236498&r2=236499&view=diff
==============================================================================
--- llvm/branches/release_36/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/branches/release_36/lib/Transforms/Scalar/GVN.cpp Tue May 5 09:43:00 2015
@@ -2183,12 +2183,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)) {
- // Floating point -0.0 and 0.0 compare equal, so we can't
- // propagate a constant based on that comparison.
+
+ // Floating point -0.0 and 0.0 compare equal, so we can only
+ // propagate values if we know that we have a constant and that
+ // its value is non-zero.
+
// 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())
+
+ if (isa<ConstantFP>(Op1) && !cast<ConstantFP>(Op1)->isZero())
Worklist.push_back(std::make_pair(Op0, Op1));
}
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=236499&r1=236498&r2=236499&view=diff
==============================================================================
--- llvm/branches/release_36/test/Transforms/GVN/edge.ll (original)
+++ llvm/branches/release_36/test/Transforms/GVN/edge.ll Tue May 5 09:43:00 2015
@@ -59,7 +59,7 @@ bb2:
ret void
}
-define double @fcmp_oeq(double %x, double %y) {
+define double @fcmp_oeq_not_zero(double %x, double %y) {
entry:
%cmp = fcmp oeq double %y, 2.0
br i1 %cmp, label %if, label %return
@@ -72,11 +72,11 @@ return:
%retval = phi double [ %div, %if ], [ %x, %entry ]
ret double %retval
-; CHECK-LABEL: define double @fcmp_oeq(
+; CHECK-LABEL: define double @fcmp_oeq_not_zero(
; CHECK: %div = fdiv double %x, 2.0
}
-define double @fcmp_une(double %x, double %y) {
+define double @fcmp_une_not_zero(double %x, double %y) {
entry:
%cmp = fcmp une double %y, 2.0
br i1 %cmp, label %return, label %else
@@ -89,7 +89,7 @@ return:
%retval = phi double [ %div, %else ], [ %x, %entry ]
ret double %retval
-; CHECK-LABEL: define double @fcmp_une(
+; CHECK-LABEL: define double @fcmp_une_not_zero(
; CHECK: %div = fdiv double %x, 2.0
}
@@ -129,3 +129,42 @@ return:
; CHECK-LABEL: define double @fcmp_une_zero(
; CHECK: %div = fdiv double %x, %y
}
+
+; We also cannot propagate a value if it's not a constant.
+; This is because the value could be 0.0 or -0.0.
+
+define double @fcmp_oeq_maybe_zero(double %x, double %y, double %z1, double %z2) {
+entry:
+ %z = fadd double %z1, %z2
+ %cmp = fcmp oeq double %y, %z
+ br i1 %cmp, label %if, label %return
+
+if:
+ %div = fdiv double %x, %z
+ br label %return
+
+return:
+ %retval = phi double [ %div, %if ], [ %x, %entry ]
+ ret double %retval
+
+; CHECK-LABEL: define double @fcmp_oeq_maybe_zero(
+; CHECK: %div = fdiv double %x, %z
+}
+
+define double @fcmp_une_maybe_zero(double %x, double %y, double %z1, double %z2) {
+entry:
+ %z = fadd double %z1, %z2
+ %cmp = fcmp une double %y, %z
+ br i1 %cmp, label %return, label %else
+
+else:
+ %div = fdiv double %x, %z
+ br label %return
+
+return:
+ %retval = phi double [ %div, %else ], [ %x, %entry ]
+ ret double %retval
+
+; CHECK-LABEL: define double @fcmp_une_maybe_zero(
+; CHECK: %div = fdiv double %x, %z
+}
More information about the llvm-branch-commits
mailing list