[llvm] [LV] Reuse VPReplicateRecipe to handle scalar stores in exit block. (PR #106342)

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 02:54:50 PDT 2024


================
@@ -9406,11 +9385,14 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
     auto *FinalReductionResult = new VPInstruction(
         VPInstruction::ComputeReductionResult, {PhiR, NewExitingVPV}, ExitDL);
     FinalReductionResult->insertBefore(*MiddleVPBB, IP);
-    OrigExitingVPV->replaceUsesWithIf(FinalReductionResult, [](VPUser &User,
-                                                               unsigned) {
-      return match(&User, m_Binary<VPInstruction::ExtractFromEnd>(m_VPValue(),
-                                                                  m_VPValue()));
-    });
+    OrigExitingVPV->replaceUsesWithIf(
+        FinalReductionResult, [IntermediateStore](VPUser &User, unsigned) {
+          return match(&User, m_Binary<VPInstruction::ExtractFromEnd>(
+                                  m_VPValue(), m_VPValue())) ||
+                 (isa<VPReplicateRecipe>(&User) &&
----------------
Mel-Chen wrote:

Only the address (operand(1) in VPReplicateRecipe) is not defined in the vector region at this moment, and `Legal->isInvariantAddressOfReduction(SI->getPointerOperand())` insures it when the recipe was generating for IntermediateStore, I think.
However, if you're concerned it, we can have more check here:
40b40fad275840e115e50d757d30142f6f75c477
BTW, let me know, if you feel using assert would be better.

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


More information about the llvm-commits mailing list