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

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 14 03:40:01 PDT 2025


================
@@ -769,6 +769,11 @@ bool VectorCombine::foldInsExtBinop(Instruction &I) {
   if (!ResultTy)
     return false;
 
+  // Avoid splitting the unfoldable constant expression binop(x,y), otherwise
+  // binop(insert(x,a,idx),insert(y,b,idx)) may be folded back and forth.
+  if (match(VecBinOp, m_BinOp(m_Constant(), m_Constant())))
----------------
RKSimon wrote:

"cost" and "reliable" don't always mix :) Let's keep it for now - mention in the comment that this is to help against cost table mismatches

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


More information about the llvm-commits mailing list