[PATCH] GVN: propagate fcmp equalities (PR17713)
Sanjay Patel
spatel at rotateright.com
Fri Jan 9 17:08:26 PST 2015
Hi reames, pete, ArchDRobison, hfinkel,
Patch based on suggestion in PR17713 ( http://llvm.org/bugs/show_bug.cgi?id=17713 ) and discussion in http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-January/080314.html .
This just handles the simple case of propagating FP values along edges; there are still a lot of other cases (eg http://llvm.org/bugs/show_bug.cgi?id=17683 ) that need work.
http://reviews.llvm.org/D6911
Files:
lib/Transforms/Scalar/GVN.cpp
test/Transforms/GVN/edge.ll
Index: lib/Transforms/Scalar/GVN.cpp
===================================================================
--- lib/Transforms/Scalar/GVN.cpp
+++ lib/Transforms/Scalar/GVN.cpp
@@ -2171,15 +2171,20 @@
// If we are propagating an equality like "(A == B)" == "true" then also
// propagate the equality A == B. When propagating a comparison such as
// "(A >= B)" == "true", replace all instances of "A < B" with "false".
- if (ICmpInst *Cmp = dyn_cast<ICmpInst>(LHS)) {
+ if (CmpInst *Cmp = dyn_cast<CmpInst>(LHS)) {
Value *Op0 = Cmp->getOperand(0), *Op1 = Cmp->getOperand(1);
// If "A == B" is known true, or "A != B" is known false, then replace
// A with B everywhere in the scope.
if ((isKnownTrue && Cmp->getPredicate() == CmpInst::ICMP_EQ) ||
(isKnownFalse && Cmp->getPredicate() == CmpInst::ICMP_NE))
Worklist.push_back(std::make_pair(Op0, Op1));
+ // 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));
+
// If "A >= B" is known true, replace "A < B" with false everywhere.
CmpInst::Predicate NotPred = Cmp->getInversePredicate();
Constant *NotVal = ConstantInt::get(Cmp->getType(), isKnownFalse);
Index: test/Transforms/GVN/edge.ll
===================================================================
--- test/Transforms/GVN/edge.ll
+++ test/Transforms/GVN/edge.ll
@@ -58,3 +58,38 @@
; CHECK: call void @g(i1 %y)
ret void
}
+
+define double @fcmp_oeq(double %x, double %y) {
+entry:
+ %cmp = fcmp oeq double %y, 2.000000e+00
+ br i1 %cmp, label %if, label %return
+
+if:
+ %div = fdiv double %x, %y
+ br label %return
+
+return:
+ %retval.0 = phi double [ %div, %if ], [ %x, %entry ]
+ ret double %retval.0
+
+; CHECK-LABEL: define double @fcmp_oeq(
+; CHECK: %div = fdiv double %x, 2.000000e+00
+}
+
+define double @fcmp_une(double %x, double %y) {
+entry:
+ %cmp = fcmp une double %y, 2.000000e+00
+ br i1 %cmp, label %return, label %else
+
+else:
+ %div = fdiv double %x, %y
+ br label %return
+
+return:
+ %retval.0 = phi double [ %div, %else ], [ %x, %entry ]
+ ret double %retval.0
+
+; CHECK-LABEL: define double @fcmp_une(
+; CHECK: %div = fdiv double %x, 2.000000e+00
+}
+
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6911.17963.patch
Type: text/x-patch
Size: 2410 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150110/ab5cf8f3/attachment.bin>
More information about the llvm-commits
mailing list