[llvm] f00a7a4 - [DAG] Fold insert_subvector (splat X), (splat X), N2 - > splat X (#147380)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 08:50:04 PDT 2025
Author: Philip Reames
Date: 2025-07-08T08:50:01-07:00
New Revision: f00a7a49bde2504a08777bffdb85bce0c4bff83c
URL: https://github.com/llvm/llvm-project/commit/f00a7a49bde2504a08777bffdb85bce0c4bff83c
DIFF: https://github.com/llvm/llvm-project/commit/f00a7a49bde2504a08777bffdb85bce0c4bff83c.diff
LOG: [DAG] Fold insert_subvector (splat X), (splat X), N2 - > splat X (#147380)
If we're inserting a splat into a splat of the same value, then
regardless of the index, the result is simply a splat of that value.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 94cb529d9899d..9ffdda28f7899 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -27620,6 +27620,11 @@ SDValue DAGCombiner::visitINSERT_SUBVECTOR(SDNode *N) {
if (DAG.isConstantValueOfAnyType(N1.getOperand(0)) || N1.hasOneUse())
return DAG.getNode(ISD::SPLAT_VECTOR, SDLoc(N), VT, N1.getOperand(0));
+ // insert_subvector (splat X), (splat X), N2 -> splat X
+ if (N0.getOpcode() == ISD::SPLAT_VECTOR && N0.getOpcode() == N1.getOpcode() &&
+ N0.getOperand(0) == N1.getOperand(0))
+ return N0;
+
// If we are inserting a bitcast value into an undef, with the same
// number of elements, just use the bitcast input of the extract.
// i.e. INSERT_SUBVECTOR UNDEF (BITCAST N1) N2 ->
diff --git a/llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll b/llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll
index d5e805b78f6bd..7b2d82a414644 100644
--- a/llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll
@@ -620,11 +620,8 @@ define <vscale x 8 x i32> @insert_splat_to_undef() {
define <vscale x 8 x i32> @insert_splat_to_splat() {
; CHECK-LABEL: insert_splat_to_splat:
; CHECK: # %bb.0:
-; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma
-; CHECK-NEXT: vmv.v.i v12, 1
; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, ma
; CHECK-NEXT: vmv.v.i v8, 1
-; CHECK-NEXT: vmv2r.v v8, v12
; CHECK-NEXT: ret
%v = call <vscale x 8 x i32> @llvm.vector.insert.nxv4i32.nxv8i32(<vscale x 8 x i32> splat (i32 1), <vscale x 4 x i32> splat (i32 1), i64 0)
ret <vscale x 8 x i32> %v
More information about the llvm-commits
mailing list