aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopUtils.cpp
diff options
context:
space:
mode:
authorPhilip Reames <preames@rivosinc.com>2024-08-30 11:55:04 -0700
committerPhilip Reames <listmail@philipreames.com>2024-08-30 11:57:24 -0700
commit897b00f3c563dd3f7b8f7263c41eaebb3520ec86 (patch)
tree3da196266fefbb854d6ab5da4180bfe7e4c7c56e /llvm/lib/Transforms/Utils/LoopUtils.cpp
parent6ab07d71174982e5cb95420ee4df01347333c342 (diff)
downloadllvm-897b00f3c563dd3f7b8f7263c41eaebb3520ec86.zip
llvm-897b00f3c563dd3f7b8f7263c41eaebb3520ec86.tar.gz
llvm-897b00f3c563dd3f7b8f7263c41eaebb3520ec86.tar.bz2
Reuse getBinOpIdentity in createAnyOfTargetReduction [nfc]
Consolidating code so that we have one copy instead of multiple reasoning about identity element. Note that we're (deliberately) not passing the FMF flags to common utility to preserve behavior in this change.
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopUtils.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index a49d3b0..8a8d8af 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -1210,6 +1210,11 @@ Value *llvm::createAnyOfTargetReduction(IRBuilderBase &Builder, Value *Src,
Value *llvm::createSimpleTargetReduction(IRBuilderBase &Builder, Value *Src,
RecurKind RdxKind) {
auto *SrcVecEltTy = cast<VectorType>(Src->getType())->getElementType();
+ auto getIdentity = [&]() {
+ Intrinsic::ID ID = getReductionIntrinsicID(RdxKind);
+ unsigned Opc = getArithmeticReductionInstruction(ID);
+ return ConstantExpr::getBinOpIdentity(Opc, SrcVecEltTy);
+ };
switch (RdxKind) {
case RecurKind::Add:
case RecurKind::Mul:
@@ -1227,10 +1232,9 @@ Value *llvm::createSimpleTargetReduction(IRBuilderBase &Builder, Value *Src,
return Builder.CreateUnaryIntrinsic(getReductionIntrinsicID(RdxKind), Src);
case RecurKind::FMulAdd:
case RecurKind::FAdd:
- return Builder.CreateFAddReduce(ConstantFP::getNegativeZero(SrcVecEltTy),
- Src);
+ return Builder.CreateFAddReduce(getIdentity(), Src);
case RecurKind::FMul:
- return Builder.CreateFMulReduce(ConstantFP::get(SrcVecEltTy, 1.0), Src);
+ return Builder.CreateFMulReduce(getIdentity(), Src);
default:
llvm_unreachable("Unhandled opcode");
}