[llvm] [DAGCombiner] Spill dynamic insertelt chain in one go (PR #162368)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 7 18:47:36 PDT 2025


================
@@ -23445,6 +23445,65 @@ SDValue DAGCombiner::visitINSERT_VECTOR_ELT(SDNode *N) {
     // inselt undef, InVal, EltNo --> build_vector < InVal, InVal, ... >
     if (InVec.isUndef() && TLI.shouldSplatInsEltVarIndex(VT))
       return DAG.getSplat(VT, DL, InVal);
+
+    if (TLI.getTypeAction(*DAG.getContext(), VT) ==
+        TargetLowering::TypeSplitVector) {
+      // For dynamic insertelts, the type legalizer will spill the entire
+      // vector. For a chain of dynamic insertelts, this can be really
+      // inefficient and bad for compile time. If each insertelt is only fed
+      // into the next, the vector is write-only across this chain, and we can
+      // just spill once.
+      SmallVector<SDNode *> Seq{N};
+      while (true) {
+        SDValue InVec = Seq.back()->getOperand(0);
+        if (InVec.getOpcode() != ISD::INSERT_VECTOR_ELT ||
+            isa<ConstantSDNode>(InVec.getOperand(2)))
----------------
arsenm wrote:

If you have mixed constant and dynamic indexes, I'd assume you wan't to collect and handle them as well 

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


More information about the llvm-commits mailing list