Skip to content

Commit 897b00f

Browse files
committed
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.
1 parent 6ab07d7 commit 897b00f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

llvm/lib/Transforms/Utils/LoopUtils.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,11 @@ Value *llvm::createAnyOfTargetReduction(IRBuilderBase &Builder, Value *Src,
12101210
Value *llvm::createSimpleTargetReduction(IRBuilderBase &Builder, Value *Src,
12111211
RecurKind RdxKind) {
12121212
auto *SrcVecEltTy = cast<VectorType>(Src->getType())->getElementType();
1213+
auto getIdentity = [&]() {
1214+
Intrinsic::ID ID = getReductionIntrinsicID(RdxKind);
1215+
unsigned Opc = getArithmeticReductionInstruction(ID);
1216+
return ConstantExpr::getBinOpIdentity(Opc, SrcVecEltTy);
1217+
};
12131218
switch (RdxKind) {
12141219
case RecurKind::Add:
12151220
case RecurKind::Mul:
@@ -1227,10 +1232,9 @@ Value *llvm::createSimpleTargetReduction(IRBuilderBase &Builder, Value *Src,
12271232
return Builder.CreateUnaryIntrinsic(getReductionIntrinsicID(RdxKind), Src);
12281233
case RecurKind::FMulAdd:
12291234
case RecurKind::FAdd:
1230-
return Builder.CreateFAddReduce(ConstantFP::getNegativeZero(SrcVecEltTy),
1231-
Src);
1235+
return Builder.CreateFAddReduce(getIdentity(), Src);
12321236
case RecurKind::FMul:
1233-
return Builder.CreateFMulReduce(ConstantFP::get(SrcVecEltTy, 1.0), Src);
1237+
return Builder.CreateFMulReduce(getIdentity(), Src);
12341238
default:
12351239
llvm_unreachable("Unhandled opcode");
12361240
}

0 commit comments

Comments
 (0)