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

Princeton Ferro via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 8 12:49:23 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.
----------------
Prince781 wrote:

What's the correct terminology here? We're creating a copy of the vector temporary on the stack. The comments in `DAGTypeLegalizer::SplitVecRes_INSERT_VECTOR_ELT` use the same term:

https://github.com/llvm/llvm-project/blob/4a9e8eaab9cce24efc846d09c77b9627a3549514/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp#L2101-L2140

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


More information about the llvm-commits mailing list