[llvm] [VectorCombine] Precisely calculate the cost in foldInstExtBinop and avoid infinite loop (PR #153069)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 06:45:42 PDT 2025


================
@@ -1250,6 +1256,10 @@ bool VectorCombine::scalarizeOpOrCmp(Instruction &I) {
   InstructionCost NewCost =
       ScalarOpCost + TTI.getVectorInstrCost(Instruction::InsertElement, VecTy,
                                             CostKind, *Index, NewVecC);
+  // Additional cost for unfoldable constant expression.
+  if (!NewVecC)
+    NewCost += VectorOpCost;
+
----------------
lukel97 wrote:

Oh perfect, great to see we could avoid the regression. Thanks!

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


More information about the llvm-commits mailing list