Skip to content

Commit 8ed90a1

Browse files
committed
Carry local patch to fix #10377
signed-zero bug in LLVM 3.6.0
1 parent 753390b commit 8ed90a1

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

deps/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ ifeq ($(ARCH),x86_64)
515515
patch -p0 < win64-int128.llvm-3.3.patch
516516
endif
517517
endif
518+
else ifeq ($(LLVM_VER),3.6.0)
519+
cd llvm-3.6.0 && patch -p1 < ../zerosign-llvm-3.6.0.patch
518520
endif
519521
touch -c $@
520522

deps/zerosign-llvm-3.6.0.patch

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
2+
index 4a85780..73a1f25 100644
3+
--- a/lib/Transforms/Scalar/GVN.cpp
4+
+++ b/lib/Transforms/Scalar/GVN.cpp
5+
@@ -2182,12 +2182,16 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS,
6+
// Handle the floating point versions of equality comparisons too.
7+
if ((isKnownTrue && Cmp->getPredicate() == CmpInst::FCMP_OEQ) ||
8+
(isKnownFalse && Cmp->getPredicate() == CmpInst::FCMP_UNE)) {
9+
- // Floating point -0.0 and 0.0 compare equal, so we can't
10+
- // propagate a constant based on that comparison.
11+
+
12+
+ // Floating point -0.0 and 0.0 compare equal, so we can only
13+
+ // propagate values if we know that we have a constant and that
14+
+ // its value is non-zero.
15+
+
16+
// FIXME: We should do this optimization if 'no signed zeros' is
17+
// applicable via an instruction-level fast-math-flag or some other
18+
// indicator that relaxed FP semantics are being used.
19+
- if (!isa<ConstantFP>(Op1) || !cast<ConstantFP>(Op1)->isZero())
20+
+
21+
+ if (isa<ConstantFP>(Op1) && !cast<ConstantFP>(Op1)->isZero())
22+
Worklist.push_back(std::make_pair(Op0, Op1));
23+
}
24+
25+
diff --git a/test/Transforms/GVN/edge.ll b/test/Transforms/GVN/edge.ll
26+
index f28a76b..0c1a3fb 100644
27+
--- a/test/Transforms/GVN/edge.ll
28+
+++ b/test/Transforms/GVN/edge.ll
29+
@@ -59,7 +59,7 @@ bb2:
30+
ret void
31+
}
32+
33+
-define double @fcmp_oeq(double %x, double %y) {
34+
+define double @fcmp_oeq_not_zero(double %x, double %y) {
35+
entry:
36+
%cmp = fcmp oeq double %y, 2.0
37+
br i1 %cmp, label %if, label %return
38+
@@ -72,11 +72,11 @@ return:
39+
%retval = phi double [ %div, %if ], [ %x, %entry ]
40+
ret double %retval
41+
42+
-; CHECK-LABEL: define double @fcmp_oeq(
43+
+; CHECK-LABEL: define double @fcmp_oeq_not_zero(
44+
; CHECK: %div = fdiv double %x, 2.0
45+
}
46+
47+
-define double @fcmp_une(double %x, double %y) {
48+
+define double @fcmp_une_not_zero(double %x, double %y) {
49+
entry:
50+
%cmp = fcmp une double %y, 2.0
51+
br i1 %cmp, label %return, label %else
52+
@@ -89,7 +89,7 @@ return:
53+
%retval = phi double [ %div, %else ], [ %x, %entry ]
54+
ret double %retval
55+
56+
-; CHECK-LABEL: define double @fcmp_une(
57+
+; CHECK-LABEL: define double @fcmp_une_not_zero(
58+
; CHECK: %div = fdiv double %x, 2.0
59+
}
60+
61+
@@ -129,3 +129,42 @@ return:
62+
; CHECK-LABEL: define double @fcmp_une_zero(
63+
; CHECK: %div = fdiv double %x, %y
64+
}
65+
+
66+
+; We also cannot propagate a value if it's not a constant.
67+
+; This is because the value could be 0.0 or -0.0.
68+
+
69+
+define double @fcmp_oeq_maybe_zero(double %x, double %y, double %z1, double %z2) {
70+
+entry:
71+
+ %z = fadd double %z1, %z2
72+
+ %cmp = fcmp oeq double %y, %z
73+
+ br i1 %cmp, label %if, label %return
74+
+
75+
+if:
76+
+ %div = fdiv double %x, %z
77+
+ br label %return
78+
+
79+
+return:
80+
+ %retval = phi double [ %div, %if ], [ %x, %entry ]
81+
+ ret double %retval
82+
+
83+
+; CHECK-LABEL: define double @fcmp_oeq_maybe_zero(
84+
+; CHECK: %div = fdiv double %x, %z
85+
+}
86+
+
87+
+define double @fcmp_une_maybe_zero(double %x, double %y, double %z1, double %z2) {
88+
+entry:
89+
+ %z = fadd double %z1, %z2
90+
+ %cmp = fcmp une double %y, %z
91+
+ br i1 %cmp, label %return, label %else
92+
+
93+
+else:
94+
+ %div = fdiv double %x, %z
95+
+ br label %return
96+
+
97+
+return:
98+
+ %retval = phi double [ %div, %else ], [ %x, %entry ]
99+
+ ret double %retval
100+
+
101+
+; CHECK-LABEL: define double @fcmp_une_maybe_zero(
102+
+; CHECK: %div = fdiv double %x, %z
103+
+}

0 commit comments

Comments
 (0)