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

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 02:24:39 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;
+
----------------
XChy wrote:

It sounds reasonable to me if there is no possible profitability. And I think `simplifyInstruction(Instruction *I, const SimplifyQuery &Q)` in `InstSimplify` would resolve your concern about n-ary intrinsics.

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


More information about the llvm-commits mailing list