[llvm-branch-commits] [llvm] 9766957 - [LoopUtils] reduce code for creatng reduction; NFC

Sanjay Patel via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jan 4 13:09:14 PST 2021


Author: Sanjay Patel
Date: 2021-01-04T16:05:03-05:00
New Revision: 976695752416f6ff51993ec1f3769e8a62eea2f2

URL: https://github.com/llvm/llvm-project/commit/976695752416f6ff51993ec1f3769e8a62eea2f2
DIFF: https://github.com/llvm/llvm-project/commit/976695752416f6ff51993ec1f3769e8a62eea2f2.diff

LOG: [LoopUtils] reduce code for creatng reduction; NFC

We can return from each case instead creating a temporary
variable just to have a common return.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/LoopUtils.cpp

Removed: 
    


################################################################################
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<Value *> 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<VectorType>(Src->getType());
-
-  std::function<Value *()> BuildFunc;
+  auto *SrcVecEltTy = cast<VectorType>(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,


        


More information about the llvm-branch-commits mailing list