Skip to content

Commit f00a7a4

Browse files
authored
[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.
1 parent 2447540 commit f00a7a4

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27620,6 +27620,11 @@ SDValue DAGCombiner::visitINSERT_SUBVECTOR(SDNode *N) {
2762027620
if (DAG.isConstantValueOfAnyType(N1.getOperand(0)) || N1.hasOneUse())
2762127621
return DAG.getNode(ISD::SPLAT_VECTOR, SDLoc(N), VT, N1.getOperand(0));
2762227622

27623+
// insert_subvector (splat X), (splat X), N2 -> splat X
27624+
if (N0.getOpcode() == ISD::SPLAT_VECTOR && N0.getOpcode() == N1.getOpcode() &&
27625+
N0.getOperand(0) == N1.getOperand(0))
27626+
return N0;
27627+
2762327628
// If we are inserting a bitcast value into an undef, with the same
2762427629
// number of elements, just use the bitcast input of the extract.
2762527630
// i.e. INSERT_SUBVECTOR UNDEF (BITCAST N1) N2 ->

llvm/test/CodeGen/RISCV/rvv/insert-subvector.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,8 @@ define <vscale x 8 x i32> @insert_splat_to_undef() {
620620
define <vscale x 8 x i32> @insert_splat_to_splat() {
621621
; CHECK-LABEL: insert_splat_to_splat:
622622
; CHECK: # %bb.0:
623-
; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma
624-
; CHECK-NEXT: vmv.v.i v12, 1
625623
; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, ma
626624
; CHECK-NEXT: vmv.v.i v8, 1
627-
; CHECK-NEXT: vmv2r.v v8, v12
628625
; CHECK-NEXT: ret
629626
%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)
630627
ret <vscale x 8 x i32> %v

0 commit comments

Comments
 (0)