[llvm] [DirectX] Add support for vector_reduce_add (PR #117646)

Chris B via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 17 09:35:41 PST 2024


================
@@ -67,10 +67,46 @@ static bool isIntrinsicExpansion(Function &F) {
   case Intrinsic::dx_sign:
   case Intrinsic::dx_step:
   case Intrinsic::dx_radians:
+  case Intrinsic::vector_reduce_add:
+  case Intrinsic::vector_reduce_fadd:
     return true;
   }
   return false;
 }
+static Value *expandVecReduceAdd(CallInst *Orig, Intrinsic::ID IntrinsicId) {
+  assert(IntrinsicId == Intrinsic::vector_reduce_add ||
+         IntrinsicId == Intrinsic::vector_reduce_fadd);
+
+  IRBuilder<> Builder(Orig);
+  bool IsFAdd = (IntrinsicId == Intrinsic::vector_reduce_fadd);
+
+  // Define the addition operation based on the intrinsic ID.
+  auto AddOp = [&Builder, IsFAdd](Value *Sum, Value *Elt) {
+    return IsFAdd ? Builder.CreateFAdd(Sum, Elt) : Builder.CreateAdd(Sum, Elt);
+  };
----------------
llvm-beanz wrote:

A lambda seems like a bit of unnecessary complexity for something that is only used in one place.

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


More information about the llvm-commits mailing list