[llvm] [VectorCombine] Precisely calculate the cost in foldInstExtBinop and avoid infinite loop (PR #153069)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 11 12:47:34 PDT 2025
================
@@ -1250,6 +1255,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:
Thanks for your review. And yes, it prevents any constant expression.
The comment below says that `Create a new base vector if the constant folding failed`. The original code seemed to try the fold after the constant folding failed. And it's theoretically possible to be profitable if the operand of binop has multiple uses. How do you think about that?
If still ok, I would adopt your advice.
https://github.com/llvm/llvm-project/pull/153069
More information about the llvm-commits
mailing list