[llvm] 1f60c8d - [IR] Replace calls to ConstantFP::getNullValue with ConstantFP::getZero. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 3 23:14:14 PDT 2023
Author: Craig Topper
Date: 2023-04-03T23:14:02-07:00
New Revision: 1f60c8d025d55f6156c93a63aa3b01f27aabee39
URL: https://github.com/llvm/llvm-project/commit/1f60c8d025d55f6156c93a63aa3b01f27aabee39
DIFF: https://github.com/llvm/llvm-project/commit/1f60c8d025d55f6156c93a63aa3b01f27aabee39.diff
LOG: [IR] Replace calls to ConstantFP::getNullValue with ConstantFP::getZero. NFC
There is no getNullValue in ConstantFP. Due to inheritance, we're calling
Constant::getNullValue which handles any type including FP.
Since we already know we want an FP constant we can use ConstantFP::getZero
which might be faster and is a more readable name for an FP zero.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/tools/llvm-stress/llvm-stress.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 65ea0dad90d5a..f085b16c2622c 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2583,7 +2583,7 @@ static Constant *ConstantFoldScalarCall2(StringRef Name,
// The legacy behaviour is that multiplying +/- 0.0 by anything, even
// NaN or infinity, gives +0.0.
if (Op1V.isZero() || Op2V.isZero())
- return ConstantFP::getNullValue(Ty);
+ return ConstantFP::getZero(Ty);
return ConstantFP::get(Ty->getContext(), Op1V * Op2V);
}
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index b82b0e784e425..ce41f8a20c02d 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5508,11 +5508,11 @@ simplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
// X = 0.0: ( 0.0 - ( 0.0)) + ( 0.0) == ( 0.0) + ( 0.0) == 0.0
if (match(Op0, m_FSub(m_AnyZeroFP(), m_Specific(Op1))) ||
match(Op1, m_FSub(m_AnyZeroFP(), m_Specific(Op0))))
- return ConstantFP::getNullValue(Op0->getType());
+ return ConstantFP::getZero(Op0->getType());
if (match(Op0, m_FNeg(m_Specific(Op1))) ||
match(Op1, m_FNeg(m_Specific(Op0))))
- return ConstantFP::getNullValue(Op0->getType());
+ return ConstantFP::getZero(Op0->getType());
}
// (X - Y) + Y --> X
@@ -5616,7 +5616,7 @@ static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
if (match(Op1, m_AnyZeroFP())) {
// X * 0.0 --> 0.0 (with nnan and nsz)
if (FMF.noNaNs() && FMF.noSignedZeros())
- return ConstantFP::getNullValue(Op0->getType());
+ return ConstantFP::getZero(Op0->getType());
// +normal number * (-)0.0 --> (-)0.0
if (isKnownNeverInfinity(Op0, Q.TLI) && isKnownNeverNaN(Op0, Q.TLI) &&
@@ -5705,7 +5705,7 @@ simplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF,
// Requires that NaNs are off (X could be zero) and signed zeroes are
// ignored (X could be positive or negative, so the output sign is unknown).
if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op0, m_AnyZeroFP()))
- return ConstantFP::getNullValue(Op0->getType());
+ return ConstantFP::getZero(Op0->getType());
if (FMF.noNaNs()) {
// X / X -> 1.0 is legal when NaNs are ignored.
@@ -5762,7 +5762,7 @@ simplifyFRemInst(Value *Op0, Value *Op1, FastMathFlags FMF,
if (FMF.noNaNs()) {
// +0 % X -> 0
if (match(Op0, m_PosZeroFP()))
- return ConstantFP::getNullValue(Op0->getType());
+ return ConstantFP::getZero(Op0->getType());
// -0 % X -> -0
if (match(Op0, m_NegZeroFP()))
return ConstantFP::getNegativeZero(Op0->getType());
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index d99a62ef716d7..44ad131bd7eff 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -1001,7 +1001,7 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
// TODO: Move to InstSimplify?
if (match(Op0, PatternMatch::m_AnyZeroFP()) ||
match(Op1, PatternMatch::m_AnyZeroFP()))
- return IC.replaceInstUsesWith(II, ConstantFP::getNullValue(II.getType()));
+ return IC.replaceInstUsesWith(II, ConstantFP::getZero(II.getType()));
// If we can prove we don't have one of the special cases then we can use a
// normal fmul instruction instead.
@@ -1024,7 +1024,7 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
match(Op1, PatternMatch::m_AnyZeroFP())) {
// It's tempting to just return Op2 here, but that would give the wrong
// result if Op2 was -0.0.
- auto *Zero = ConstantFP::getNullValue(II.getType());
+ auto *Zero = ConstantFP::getZero(II.getType());
auto *FAdd = IC.Builder.CreateFAddFMF(Zero, Op2, &II);
FAdd->takeName(&II);
return IC.replaceInstUsesWith(II, FAdd);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 269a3d4a6e671..13fdaf22f63d2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -6901,7 +6901,7 @@ static Instruction *foldFabsWithFcmpZero(FCmpInst &I, InstCombinerImpl &IC) {
Mode.Input == DenormalMode::PositiveZero) {
auto replaceFCmp = [](FCmpInst *I, FCmpInst::Predicate P, Value *X) {
- Constant *Zero = ConstantFP::getNullValue(X->getType());
+ Constant *Zero = ConstantFP::getZero(X->getType());
return new FCmpInst(P, X, Zero, "", I);
};
@@ -6997,7 +6997,7 @@ static Instruction *foldFCmpFNegCommonOp(FCmpInst &I) {
// Replace the negated operand with 0.0:
// fcmp Pred Op0, -Op0 --> fcmp Pred Op0, 0.0
- Constant *Zero = ConstantFP::getNullValue(Op0->getType());
+ Constant *Zero = ConstantFP::getZero(Op0->getType());
return new FCmpInst(Pred, Op0, Zero, "", &I);
}
@@ -7048,10 +7048,10 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
// then canonicalize the operand to 0.0.
if (Pred == CmpInst::FCMP_ORD || Pred == CmpInst::FCMP_UNO) {
if (!match(Op0, m_PosZeroFP()) && isKnownNeverNaN(Op0, &TLI))
- return replaceOperand(I, 0, ConstantFP::getNullValue(OpType));
+ return replaceOperand(I, 0, ConstantFP::getZero(OpType));
if (!match(Op1, m_PosZeroFP()) && isKnownNeverNaN(Op1, &TLI))
- return replaceOperand(I, 1, ConstantFP::getNullValue(OpType));
+ return replaceOperand(I, 1, ConstantFP::getZero(OpType));
}
// fcmp pred (fneg X), (fneg Y) -> fcmp swap(pred) X, Y
@@ -7080,7 +7080,7 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
// The sign of 0.0 is ignored by fcmp, so canonicalize to +0.0:
// fcmp Pred X, -0.0 --> fcmp Pred X, 0.0
if (match(Op1, m_AnyZeroFP()) && !match(Op1, m_PosZeroFP()))
- return replaceOperand(I, 1, ConstantFP::getNullValue(OpType));
+ return replaceOperand(I, 1, ConstantFP::getZero(OpType));
// Ignore signbit of bitcasted int when comparing equality to FP 0.0:
// fcmp oeq/une (bitcast X), 0.0 --> (and X, SignMaskC) ==/!= 0
@@ -7169,11 +7169,11 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
case FCmpInst::FCMP_ONE:
// X is ordered and not equal to an impossible constant --> ordered
return new FCmpInst(FCmpInst::FCMP_ORD, X,
- ConstantFP::getNullValue(X->getType()));
+ ConstantFP::getZero(X->getType()));
case FCmpInst::FCMP_UEQ:
// X is unordered or equal to an impossible constant --> unordered
return new FCmpInst(FCmpInst::FCMP_UNO, X,
- ConstantFP::getNullValue(X->getType()));
+ ConstantFP::getZero(X->getType()));
case FCmpInst::FCMP_UNE:
// X is unordered or not equal to an impossible constant --> true
return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType()));
diff --git a/llvm/tools/llvm-stress/llvm-stress.cpp b/llvm/tools/llvm-stress/llvm-stress.cpp
index 639506c7d488d..722120d7aae81 100644
--- a/llvm/tools/llvm-stress/llvm-stress.cpp
+++ b/llvm/tools/llvm-stress/llvm-stress.cpp
@@ -222,7 +222,7 @@ struct Modifier {
} else if (Tp->isFloatingPointTy()) {
if (getRandom() & 1)
return ConstantFP::getAllOnesValue(Tp);
- return ConstantFP::getNullValue(Tp);
+ return ConstantFP::getZero(Tp);
}
return UndefValue::get(Tp);
}
@@ -244,7 +244,7 @@ struct Modifier {
} else if (Tp->isFloatingPointTy()) {
if (getRandom() & 1)
return ConstantFP::getAllOnesValue(Tp);
- return ConstantFP::getNullValue(Tp);
+ return ConstantFP::getZero(Tp);
} else if (auto *VTp = dyn_cast<FixedVectorType>(Tp)) {
std::vector<Constant*> TempValues;
TempValues.reserve(VTp->getNumElements());
@@ -442,7 +442,7 @@ struct ConstModifier: public Modifier {
APFloat RandomFloat(Ty->getFltSemantics(), RandomInt);
if (getRandom() & 1)
- return PT->push_back(ConstantFP::getNullValue(Ty));
+ return PT->push_back(ConstantFP::getZero(Ty));
return PT->push_back(ConstantFP::get(Ty->getContext(), RandomFloat));
}
More information about the llvm-commits
mailing list