diff options
author | David Sherwood <david.sherwood@arm.com> | 2022-05-31 15:54:49 +0100 |
---|---|---|
committer | David Sherwood <david.sherwood@arm.com> | 2022-06-10 12:42:34 +0100 |
commit | 8daaea206b5905858bdbdd881be4fe9bdcc54516 (patch) | |
tree | fcaeccc1ea2b715346a647631a397f49159fb0b4 /llvm/lib/IR/Constants.cpp | |
parent | 46f08a4ee0e9169fdc153e2e4f9a5bb695372b27 (diff) | |
download | llvm-8daaea206b5905858bdbdd881be4fe9bdcc54516.zip llvm-8daaea206b5905858bdbdd881be4fe9bdcc54516.tar.gz llvm-8daaea206b5905858bdbdd881be4fe9bdcc54516.tar.bz2 |
[InstCombine] Use +0.0 instead of -0.0 as the FP identity for some folds
In foldSelectIntoOp we sometimes transform a select of a fadd into a
fadd of a select, where we select between data and an identity value.
For both fadd and fsub the identity is always -0.0, but if the nsz
flag is set on the select instruction we can use +0.0 instead. Doing
so then triggers other optimisations, such as when folding the select
of masked load into a new masked load.
Differential Revision: https://reviews.llvm.org/D126774
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 26da7fa..965012e 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -1037,9 +1037,9 @@ Constant *ConstantFP::getSNaN(Type *Ty, bool Negative, APInt *Payload) { return C; } -Constant *ConstantFP::getNegativeZero(Type *Ty) { +Constant *ConstantFP::getZero(Type *Ty, bool Negative) { const fltSemantics &Semantics = Ty->getScalarType()->getFltSemantics(); - APFloat NegZero = APFloat::getZero(Semantics, /*Negative=*/true); + APFloat NegZero = APFloat::getZero(Semantics, Negative); Constant *C = get(Ty->getContext(), NegZero); if (VectorType *VTy = dyn_cast<VectorType>(Ty)) @@ -1048,7 +1048,6 @@ Constant *ConstantFP::getNegativeZero(Type *Ty) { return C; } - Constant *ConstantFP::getZeroValueForNegation(Type *Ty) { if (Ty->isFPOrFPVectorTy()) return getNegativeZero(Ty); @@ -2835,7 +2834,7 @@ Constant *ConstantExpr::getExactLogBase2(Constant *C) { } Constant *ConstantExpr::getBinOpIdentity(unsigned Opcode, Type *Ty, - bool AllowRHSConstant) { + bool AllowRHSConstant, bool NSZ) { assert(Instruction::isBinaryOp(Opcode) && "Only binops allowed"); // Commutative opcodes: it does not matter if AllowRHSConstant is set. @@ -2850,8 +2849,7 @@ Constant *ConstantExpr::getBinOpIdentity(unsigned Opcode, Type *Ty, case Instruction::And: // X & -1 = X return Constant::getAllOnesValue(Ty); case Instruction::FAdd: // X + -0.0 = X - // TODO: If the fadd has 'nsz', should we return +0.0? - return ConstantFP::getNegativeZero(Ty); + return ConstantFP::getZero(Ty, !NSZ); case Instruction::FMul: // X * 1.0 = X return ConstantFP::get(Ty, 1.0); default: |