[llvm] [LV] Ensure getScaledReductions only matches extends inside the loop (PR #148264)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 14 01:47:54 PDT 2025


================
@@ -8109,14 +8109,19 @@ bool VPRecipeBuilder::getScaledReductions(
   std::optional<unsigned> BinOpc;
   Type *ExtOpTypes[2] = {nullptr};
 
-  auto CollectExtInfo = [&Exts,
+  auto CollectExtInfo = [this, &Exts,
                          &ExtOpTypes](SmallVectorImpl<Value *> &Ops) -> bool {
     unsigned I = 0;
     for (Value *OpI : Ops) {
       Value *ExtOp;
       if (!match(OpI, m_ZExtOrSExt(m_Value(ExtOp))))
         return false;
       Exts[I] = cast<Instruction>(OpI);
+
+      // Other operand should live inside the loop
+      if (!CM.TheLoop->contains(Exts[I]))
----------------
david-arm wrote:

Maybe it is possible, but given we're close to the branch point I thought it might be better to disable it first and look at adding support for it afterwards. What do you think?

I think the problem lies in the cost model (specifically VPPartialReduction::computeCost) and some assumptions made about the ordering of PHI operands.

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


More information about the llvm-commits mailing list