[llvm] [LV][EVL] Support in-loop reduction using tail folding with EVL. (PR #90184)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 02:57:10 PDT 2024


================
@@ -57,7 +57,55 @@ Value *VectorBuilder::createVectorInstruction(unsigned Opcode, Type *ReturnTy,
   auto VPID = VPIntrinsic::getForOpcode(Opcode);
   if (VPID == Intrinsic::not_intrinsic)
     return returnWithError<Value *>("No VPIntrinsic for this opcode");
+  return createVectorInstructionImpl(VPID, ReturnTy, InstOpArray, Name);
+}
+
+Value *VectorBuilder::createSimpleTargetReduction(RecurKind Kind, Type *ValTy,
+                                                  ArrayRef<Value *> InstOpArray,
+                                                  const Twine &Name) {
+  auto GetForRecurKind = [](RecurKind Kind) {
+    switch (Kind) {
+    case RecurKind::Add:
+      return Intrinsic::vp_reduce_add;
+    case RecurKind::Mul:
+      return Intrinsic::vp_reduce_mul;
+    case RecurKind::And:
+      return Intrinsic::vp_reduce_and;
+    case RecurKind::Or:
+      return Intrinsic::vp_reduce_or;
+    case RecurKind::Xor:
+      return Intrinsic::vp_reduce_xor;
+    case RecurKind::FMulAdd:
+    case RecurKind::FAdd:
+      return Intrinsic::vp_reduce_fadd;
+    case RecurKind::FMul:
+      return Intrinsic::vp_reduce_fmul;
+    case RecurKind::SMax:
+      return Intrinsic::vp_reduce_smax;
+    case RecurKind::SMin:
+      return Intrinsic::vp_reduce_smin;
+    case RecurKind::UMax:
+      return Intrinsic::vp_reduce_umax;
+    case RecurKind::UMin:
+      return Intrinsic::vp_reduce_umin;
+    case RecurKind::FMax:
+      return Intrinsic::vp_reduce_fmax;
+    case RecurKind::FMin:
+      return Intrinsic::vp_reduce_fmin;
+    default:
+      return Intrinsic::not_intrinsic;
+    }
+  };
+  auto VPID = getForRecurKind(Kind);
+  if (VPID == Intrinsic::not_intrinsic)
----------------
fhahn wrote:

Right, but here it makes more sense to assert as this is more consistent with the general overall codebase, especially as the caller expects this to always succeed (and not silently return something other than the correct VP intrinsic?)

https://github.com/llvm/llvm-project/pull/90184


More information about the llvm-commits mailing list