[PATCH] D75236: [APFloat] Overload unary operator-
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 04:11:20 PST 2020
foad updated this revision to Diff 247844.
foad added a comment.
Move unary operator- next to other overloads.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75236/new/
https://reviews.llvm.org/D75236
Files:
llvm/include/llvm/ADT/APFloat.h
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/lib/IR/ConstantFold.cpp
llvm/unittests/ADT/APFloatTest.cpp
Index: llvm/unittests/ADT/APFloatTest.cpp
===================================================================
--- llvm/unittests/ADT/APFloatTest.cpp
+++ llvm/unittests/ADT/APFloatTest.cpp
@@ -2990,6 +2990,17 @@
EXPECT_TRUE(Inf.bitwiseIsEqual(neg(NegInf)));
EXPECT_TRUE(NegQNaN.bitwiseIsEqual(neg(QNaN)));
EXPECT_TRUE(QNaN.bitwiseIsEqual(neg(NegQNaN)));
+
+ EXPECT_TRUE(NegOne.bitwiseIsEqual(-One));
+ EXPECT_TRUE(One.bitwiseIsEqual(-NegOne));
+ EXPECT_TRUE(NegZero.bitwiseIsEqual(-Zero));
+ EXPECT_TRUE(Zero.bitwiseIsEqual(-NegZero));
+ EXPECT_TRUE(NegInf.bitwiseIsEqual(-Inf));
+ EXPECT_TRUE(Inf.bitwiseIsEqual(-NegInf));
+ EXPECT_TRUE(NegInf.bitwiseIsEqual(-Inf));
+ EXPECT_TRUE(Inf.bitwiseIsEqual(-NegInf));
+ EXPECT_TRUE(NegQNaN.bitwiseIsEqual(-QNaN));
+ EXPECT_TRUE(QNaN.bitwiseIsEqual(-NegQNaN));
}
TEST(APFloatTest, ilogb) {
Index: llvm/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/lib/IR/ConstantFold.cpp
+++ llvm/lib/IR/ConstantFold.cpp
@@ -986,7 +986,7 @@
default:
break;
case Instruction::FNeg:
- return ConstantFP::get(C->getContext(), neg(CV));
+ return ConstantFP::get(C->getContext(), -CV);
}
} else if (VectorType *VTy = dyn_cast<VectorType>(C->getType())) {
// Do not iterate on scalable vector. The number of elements is unknown at
Index: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -5568,7 +5568,7 @@
// Don't invert constant FP values after legalization unless the target says
// the negated constant is legal.
if (isOperationLegal(ISD::ConstantFP, VT) ||
- isFPImmLegal(neg(cast<ConstantFPSDNode>(Op)->getValueAPF()), VT,
+ isFPImmLegal(-cast<ConstantFPSDNode>(Op)->getValueAPF(), VT,
ForCodeSize))
return NegatibleCost::Neutral;
break;
@@ -5586,7 +5586,7 @@
return NegatibleCost::Neutral;
if (llvm::all_of(Op->op_values(), [&](SDValue N) {
return N.isUndef() ||
- isFPImmLegal(neg(cast<ConstantFPSDNode>(N)->getValueAPF()), VT,
+ isFPImmLegal(-cast<ConstantFPSDNode>(N)->getValueAPF(), VT,
ForCodeSize);
}))
return NegatibleCost::Neutral;
Index: llvm/include/llvm/ADT/APFloat.h
===================================================================
--- llvm/include/llvm/ADT/APFloat.h
+++ llvm/include/llvm/ADT/APFloat.h
@@ -1036,6 +1036,13 @@
APFLOAT_DISPATCH_ON_SEMANTICS(next(nextDown));
}
+ /// Negate an APFloat.
+ APFloat operator-() const {
+ APFloat Result(*this);
+ Result.changeSign();
+ return Result;
+ }
+
/// Add two APFloats, rounding ties to the nearest even.
/// No error checking.
APFloat operator+(const APFloat &RHS) const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75236.247844.patch
Type: text/x-patch
Size: 2961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200303/d7434d77/attachment.bin>
More information about the llvm-commits
mailing list