diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h --- a/llvm/include/llvm/ADT/APFloat.h +++ b/llvm/include/llvm/ADT/APFloat.h @@ -1243,12 +1243,6 @@ return X; } -/// Returns the negated value of the argument. -inline APFloat neg(APFloat X) { - X.changeSign(); - return X; -} - /// Implements IEEE minNum semantics. Returns the smaller of the 2 arguments if /// both are not NaN. If either argument is a NaN, returns the other argument. LLVM_READONLY diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -5579,7 +5579,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(Op)->getValueAPF()), VT, + isFPImmLegal(-cast(Op)->getValueAPF(), VT, ForCodeSize)) return NegatibleCost::Neutral; break; @@ -5597,7 +5597,7 @@ return NegatibleCost::Neutral; if (llvm::all_of(Op->op_values(), [&](SDValue N) { return N.isUndef() || - isFPImmLegal(neg(cast(N)->getValueAPF()), VT, + isFPImmLegal(-cast(N)->getValueAPF(), VT, ForCodeSize); })) return NegatibleCost::Neutral; diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp --- a/llvm/lib/IR/ConstantFold.cpp +++ b/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(C->getType())) { // Do not iterate on scalable vector. The number of elements is unknown at diff --git a/llvm/unittests/ADT/APFloatTest.cpp b/llvm/unittests/ADT/APFloatTest.cpp --- a/llvm/unittests/ADT/APFloatTest.cpp +++ b/llvm/unittests/ADT/APFloatTest.cpp @@ -2980,17 +2980,6 @@ APFloat QNaN = APFloat::getNaN(APFloat::IEEEsingle(), false); APFloat NegQNaN = APFloat::getNaN(APFloat::IEEEsingle(), true); - EXPECT_TRUE(NegOne.bitwiseIsEqual(neg(One))); - EXPECT_TRUE(One.bitwiseIsEqual(neg(NegOne))); - EXPECT_TRUE(NegZero.bitwiseIsEqual(neg(Zero))); - EXPECT_TRUE(Zero.bitwiseIsEqual(neg(NegZero))); - EXPECT_TRUE(NegInf.bitwiseIsEqual(neg(Inf))); - EXPECT_TRUE(Inf.bitwiseIsEqual(neg(NegInf))); - EXPECT_TRUE(NegInf.bitwiseIsEqual(neg(Inf))); - 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));