[llvm] [VPlan] Replace PhiR operand of ComputeAnyOfResult with VPIRFlags. (PR #175657)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 16 08:32:45 PST 2026


================
@@ -8751,17 +8751,32 @@ void LoopVectorizationPlanner::addReductionResultComputation(
                                {PhiR, Start, Sentinel, NewExitingVPV}, ExitDL);
     } else if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RecurrenceKind)) {
       VPValue *Start = PhiR->getStartValue();
+      // Find the NewVal from the original scalar select. NewVal is the value
+      // selected when the condition is true (i.e., the non-phi operand).
+      // We need to find the SelectInst among the original phi's users.
+      auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingInstr());
+      SelectInst *SI = nullptr;
+      for (auto *U : OrigPhi->users()) {
+        if ((SI = dyn_cast<SelectInst>(U)))
+          break;
+      }
+      assert(SI && "AnyOf reduction must have a select user");
+      Value *NewValIR = SI->getTrueValue() == OrigPhi ? SI->getFalseValue()
+                                                      : SI->getTrueValue();
+      VPValue *NewVal = Plan->getOrAddLiveIn(NewValIR);
       FinalReductionResult =
           Builder.createNaryOp(VPInstruction::ComputeAnyOfResult,
-                               {PhiR, Start, NewExitingVPV}, ExitDL);
+                               {Start, NewVal, NewExitingVPV}, ExitDL);
----------------
fhahn wrote:

Yep, updated and simplified thanks

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


More information about the llvm-commits mailing list