[llvm] [LV] Keep predicate select when optimizeFindIVReductions when folding tail. (PR #191166)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 9 07:52:47 PDT 2026


================
@@ -5902,6 +5904,10 @@ void VPlanTransforms::optimizeFindIVReductions(VPlan &Plan,
       }
     }
 
+    // Update the predicated select with FindLastSelect when folding tail.
+    if (HeaderMask)
+      PredSelect->setOperand(1, FindLastSelect);
----------------
lukel97 wrote:

Is there definitely nothing else using the BackedgeVal/PredSelect? Would it be safer to just create a new select, something like

```c++
VPValue *RdxOut = FindLastSelect;
if (HeaderMask)
  RdxOut = Select.createSelect(HeaderMask, RdxOut, PhiR);
VPValue *ReducedIV = createNaryOp(ComputeReductionResult, RdxOut, Flags, ExitDL);
```

And then let DCE remove the old BackedgeVal if needed?

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


More information about the llvm-commits mailing list