[llvm] [SDAG] Match BUILD_VECTOR in INSERT_SUBVECTOR to SPLAT_VECTOR fold (PR #163984)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 17 09:31:41 PDT 2025


================
@@ -28014,9 +28014,14 @@ SDValue DAGCombiner::visitINSERT_SUBVECTOR(SDNode *N) {
 
   // Simplify scalar inserts into an undef vector:
   // insert_subvector undef, (splat X), N2 -> splat X
-  if (N0.isUndef() && N1.getOpcode() == ISD::SPLAT_VECTOR)
-    if (DAG.isConstantValueOfAnyType(N1.getOperand(0)) || N1.hasOneUse())
+  auto *BV0 = dyn_cast<BuildVectorSDNode>(N1);
+  if (N0.isUndef() && (N1.getOpcode() == ISD::SPLAT_VECTOR || BV0)) {
+    SDValue Splat = BV0 ? BV0->getSplatValue() : N1.getOperand(0);
+    bool SplatLegal = TLI.isOperationLegalOrCustom(ISD::SPLAT_VECTOR, VT);
----------------
MacDue wrote:

Note: The legality check avoids a regression (where the splat is just lowered to another `BUILD_VECTOR`, which seems to duplicate some code). 

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


More information about the llvm-commits mailing list