[llvm] [LV] Handle swapped blend inputs in predicated partial reductions (PR #208013)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 00:34:55 PDT 2026


================
@@ -6572,6 +6569,22 @@ struct VPPartialReductionChain {
   VPBlendRecipe *Blend = nullptr;
 };
 
+// Return the incoming index of the single-use value in the blend, which is
+// expected to be the predicated reduction update.
+static std::optional<unsigned>
+getBlendReductionUpdateValueIdx(VPBlendRecipe *Blend) {
+  assert(Blend && !Blend->isNormalized() &&
+         Blend->getNumIncomingValues() == 2 &&
+         "Expected a non-normalized blend with two incoming values");
+  bool FirstIncomingHasOneUse = Blend->getIncomingValue(0)->hasOneUse();
+
+  // Only the update value should have one use (the blend). The previous
+  // value should always have at least two uses, the blend and the reduction.
+  if (FirstIncomingHasOneUse == Blend->getIncomingValue(1)->hasOneUse())
----------------
MacDue wrote:

Then you're assuming the second incoming value has one use. I personally, find the current approach a little clearer (it also exits earlier, before matching the reduction operands). 

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


More information about the llvm-commits mailing list