From 976695752416f6ff51993ec1f3769e8a62eea2f2 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 4 Jan 2021 15:24:36 -0500 Subject: [PATCH] [LoopUtils] reduce code for creatng reduction; NFC We can return from each case instead creating a temporary variable just to have a common return. --- llvm/lib/Transforms/Utils/LoopUtils.cpp | 56 +++++++------------------ 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index e062eacf82b2..3245f5f21017 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -983,77 +983,53 @@ Value *llvm::createSimpleTargetReduction(IRBuilderBase &Builder, RecurKind RdxKind, ArrayRef RedOps) { TargetTransformInfo::ReductionFlags RdxFlags; - RdxFlags.IsMaxOp = RdxKind == RecurKind::SMax || - RdxKind == RecurKind::UMax || + RdxFlags.IsMaxOp = RdxKind == RecurKind::SMax || RdxKind == RecurKind::UMax || RdxKind == RecurKind::FMax; RdxFlags.IsSigned = RdxKind == RecurKind::SMax || RdxKind == RecurKind::SMin; if (!ForceReductionIntrinsic && !TTI->useReductionIntrinsic(Opcode, Src->getType(), RdxFlags)) return getShuffleReduction(Builder, Src, Opcode, RdxKind, RedOps); - auto *SrcVTy = cast(Src->getType()); - - std::function BuildFunc; + auto *SrcVecEltTy = cast(Src->getType())->getElementType(); switch (Opcode) { case Instruction::Add: - BuildFunc = [&]() { return Builder.CreateAddReduce(Src); }; - break; + return Builder.CreateAddReduce(Src); case Instruction::Mul: - BuildFunc = [&]() { return Builder.CreateMulReduce(Src); }; - break; + return Builder.CreateMulReduce(Src); case Instruction::And: - BuildFunc = [&]() { return Builder.CreateAndReduce(Src); }; - break; + return Builder.CreateAndReduce(Src); case Instruction::Or: - BuildFunc = [&]() { return Builder.CreateOrReduce(Src); }; - break; + return Builder.CreateOrReduce(Src); case Instruction::Xor: - BuildFunc = [&]() { return Builder.CreateXorReduce(Src); }; - break; + return Builder.CreateXorReduce(Src); case Instruction::FAdd: - BuildFunc = [&]() { - auto Rdx = Builder.CreateFAddReduce( - ConstantFP::getNegativeZero(SrcVTy->getElementType()), Src); - return Rdx; - }; - break; + return Builder.CreateFAddReduce(ConstantFP::getNegativeZero(SrcVecEltTy), + Src); case Instruction::FMul: - BuildFunc = [&]() { - Type *Ty = SrcVTy->getElementType(); - auto Rdx = Builder.CreateFMulReduce(ConstantFP::get(Ty, 1.0), Src); - return Rdx; - }; - break; + return Builder.CreateFMulReduce(ConstantFP::get(SrcVecEltTy, 1.0), Src); case Instruction::ICmp: switch (RdxKind) { case RecurKind::SMax: - BuildFunc = [&]() { return Builder.CreateIntMaxReduce(Src, true); }; - break; + return Builder.CreateIntMaxReduce(Src, true); case RecurKind::SMin: - BuildFunc = [&]() { return Builder.CreateIntMinReduce(Src, true); }; - break; + return Builder.CreateIntMinReduce(Src, true); case RecurKind::UMax: - BuildFunc = [&]() { return Builder.CreateIntMaxReduce(Src, false); }; - break; + return Builder.CreateIntMaxReduce(Src, false); case RecurKind::UMin: - BuildFunc = [&]() { return Builder.CreateIntMinReduce(Src, false); }; - break; + return Builder.CreateIntMinReduce(Src, false); default: llvm_unreachable("Unexpected min/max reduction type"); } - break; case Instruction::FCmp: assert((RdxKind == RecurKind::FMax || RdxKind == RecurKind::FMin) && "Unexpected min/max reduction type"); if (RdxKind == RecurKind::FMax) - BuildFunc = [&]() { return Builder.CreateFPMaxReduce(Src); }; + return Builder.CreateFPMaxReduce(Src); else - BuildFunc = [&]() { return Builder.CreateFPMinReduce(Src); }; - break; + return Builder.CreateFPMinReduce(Src); default: llvm_unreachable("Unhandled opcode"); } - return BuildFunc(); } Value *llvm::createTargetReduction(IRBuilderBase &B,