Skip to content

Commit

Permalink
Merge pull request #10424 from JuliaLang/tk/fix10377
Browse files Browse the repository at this point in the history
Carry local patch to fix #10377
  • Loading branch information
vtjnash committed Mar 7, 2015
2 parents cb09d28 + 8ed90a1 commit 4a43960
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ ifeq ($(ARCH),x86_64)
patch -p0 < win64-int128.llvm-3.3.patch
endif
endif
else ifeq ($(LLVM_VER),3.6.0)
cd llvm-3.6.0 && patch -p1 < ../zerosign-llvm-3.6.0.patch
endif
touch -c $@

Expand Down
103 changes: 103 additions & 0 deletions deps/zerosign-llvm-3.6.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index 4a85780..73a1f25 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/lib/Transforms/Scalar/GVN.cpp
@@ -2182,12 +2182,16 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS,
// 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));
}

diff --git a/test/Transforms/GVN/edge.ll b/test/Transforms/GVN/edge.ll
index f28a76b..0c1a3fb 100644
--- a/test/Transforms/GVN/edge.ll
+++ b/test/Transforms/GVN/edge.ll
@@ -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
+}

0 comments on commit 4a43960

Please sign in to comment.