aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/ExpandVectorPredication.cpp
diff options
context:
space:
mode:
authorPhilip Reames <preames@rivosinc.com>2024-08-30 17:13:51 -0700
committerPhilip Reames <listmail@philipreames.com>2024-09-04 08:23:21 -0700
commit3d9abfc9f841b13825e3d03cfba272f5eeab9a3b (patch)
treee8b7f6074af959d0f2591be744f39d63bbccf89f /llvm/lib/CodeGen/ExpandVectorPredication.cpp
parentc1a8283fcc735b1567c49bb6cd485f9e71a12cc4 (diff)
downloadllvm-3d9abfc9f841b13825e3d03cfba272f5eeab9a3b.zip
llvm-3d9abfc9f841b13825e3d03cfba272f5eeab9a3b.tar.gz
llvm-3d9abfc9f841b13825e3d03cfba272f5eeab9a3b.tar.bz2
Consolidate all IR logic for getting the identity value of a reduction [nfc]
This change merges the three different places (at the IR layer) for finding the identity value of a reduction into a single copy. This depends on several prior commits which fix ommissions and bugs in the distinct copies, but this patch itself should be fully non-functional. As the new comments and naming try to make clear, the identity value is a property of the @llvm.vector.reduce.* intrinsic, not of e.g. the recurrence descriptor. (We still provide an interface for clients using recurrence descriptors, but the implementation simply translates to the intrinsic which each corresponds to.) As a note, the getIntrinsicIdentity API does not support fminnum/fmaxnum or fminimum/fmaximum which is why we still need manual logic (but at least only one copy of manual logic) for those cases.
Diffstat (limited to 'llvm/lib/CodeGen/ExpandVectorPredication.cpp')
-rw-r--r--llvm/lib/CodeGen/ExpandVectorPredication.cpp51
1 files changed, 5 insertions, 46 deletions
diff --git a/llvm/lib/CodeGen/ExpandVectorPredication.cpp b/llvm/lib/CodeGen/ExpandVectorPredication.cpp
index fe95a27..ffe879f 100644
--- a/llvm/lib/CodeGen/ExpandVectorPredication.cpp
+++ b/llvm/lib/CodeGen/ExpandVectorPredication.cpp
@@ -368,52 +368,11 @@ Value *CachingVPExpander::expandPredicationToFPCall(
static Value *getNeutralReductionElement(const VPReductionIntrinsic &VPI,
Type *EltTy) {
- bool Negative = false;
- unsigned EltBits = EltTy->getScalarSizeInBits();
- Intrinsic::ID VID = VPI.getIntrinsicID();
- switch (VID) {
- default:
- llvm_unreachable("Expecting a VP reduction intrinsic");
- case Intrinsic::vp_reduce_add:
- case Intrinsic::vp_reduce_or:
- case Intrinsic::vp_reduce_xor:
- case Intrinsic::vp_reduce_umax:
- return Constant::getNullValue(EltTy);
- case Intrinsic::vp_reduce_mul:
- return ConstantInt::get(EltTy, 1, /*IsSigned*/ false);
- case Intrinsic::vp_reduce_and:
- case Intrinsic::vp_reduce_umin:
- return ConstantInt::getAllOnesValue(EltTy);
- case Intrinsic::vp_reduce_smin:
- return ConstantInt::get(EltTy->getContext(),
- APInt::getSignedMaxValue(EltBits));
- case Intrinsic::vp_reduce_smax:
- return ConstantInt::get(EltTy->getContext(),
- APInt::getSignedMinValue(EltBits));
- case Intrinsic::vp_reduce_fmax:
- case Intrinsic::vp_reduce_fmaximum:
- Negative = true;
- [[fallthrough]];
- case Intrinsic::vp_reduce_fmin:
- case Intrinsic::vp_reduce_fminimum: {
- bool PropagatesNaN = VID == Intrinsic::vp_reduce_fminimum ||
- VID == Intrinsic::vp_reduce_fmaximum;
- FastMathFlags Flags = VPI.getFastMathFlags();
- const fltSemantics &Semantics = EltTy->getFltSemantics();
- return (!Flags.noNaNs() && !PropagatesNaN)
- ? ConstantFP::getQNaN(EltTy, Negative)
- : !Flags.noInfs()
- ? ConstantFP::getInfinity(EltTy, Negative)
- : ConstantFP::get(EltTy,
- APFloat::getLargest(Semantics, Negative));
- }
- case Intrinsic::vp_reduce_fadd:
- return ConstantExpr::getBinOpIdentity(
- Instruction::FAdd, EltTy, false,
- VPI.getFastMathFlags().noSignedZeros());
- case Intrinsic::vp_reduce_fmul:
- return ConstantFP::get(EltTy, 1.0);
- }
+ Intrinsic::ID RdxID = *VPI.getFunctionalIntrinsicID();
+ FastMathFlags FMF;
+ if (isa<FPMathOperator>(VPI))
+ FMF = VPI.getFastMathFlags();
+ return getReductionIdentity(RdxID, EltTy, FMF);
}
Value *