Skip to content

Commit a6b424e

Browse files
authored
[RISCV] Extend redundant vrgather.vx peephole to vfmv.v.f (llvm#135503)
Extend the transform introduced in 336b290 to vfmv.v.f. This is fairly trivial and would have been in the original commit except I hadn't written the FP tests yet. If the vrgather.vi is preceeded by a vfmv.v.f which writes a superset of the lanes writen by the vrgather, and the vrgather has no passthru, then the vrgather has no semantic effect.
1 parent f4ff209 commit a6b424e

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19716,10 +19716,15 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
1971619716
SDValue Src = N->getOperand(0);
1971719717
SDValue Passthru = N->getOperand(2);
1971819718
SDValue VL = N->getOperand(4);
19719-
// TODO: Handle fmv.v.f?
19720-
if (Src.getOpcode() == RISCVISD::VMV_V_X_VL && Passthru.isUndef() &&
19721-
VL == Src.getOperand(2))
19722-
return Src;
19719+
switch (Src.getOpcode()) {
19720+
default:
19721+
break;
19722+
case RISCVISD::VMV_V_X_VL:
19723+
case RISCVISD::VFMV_V_F_VL:
19724+
if (Passthru.isUndef() && VL == Src.getOperand(2))
19725+
return Src;
19726+
break;
19727+
}
1972319728
break;
1972419729
}
1972519730
}

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-shuffle-fp.ll

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ define <4 x double> @shuffle_vf_v4f64(<4 x double> %x) {
6969
define <4 x float> @vfmerge_constant_v4f32(<4 x float> %x) {
7070
; CHECK-LABEL: vfmerge_constant_v4f32:
7171
; CHECK: # %bb.0:
72-
; CHECK-NEXT: lui a0, 264704
73-
; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, mu
72+
; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
7473
; CHECK-NEXT: vmv.v.i v0, 6
75-
; CHECK-NEXT: vmv.v.x v9, a0
76-
; CHECK-NEXT: vrgather.vi v8, v9, 1, v0.t
74+
; CHECK-NEXT: lui a0, 264704
75+
; CHECK-NEXT: vmerge.vxm v8, v8, a0, v0
7776
; CHECK-NEXT: ret
7877
%s = shufflevector <4 x float> %x, <4 x float> <float poison, float 5.0, float poison, float poison>, <4 x i32> <i32 0, i32 5, i32 5, i32 3>
7978
ret <4 x float> %s
@@ -86,9 +85,8 @@ define <4 x double> @vfmerge_constant_v4f64(<4 x double> %x) {
8685
; CHECK-NEXT: fld fa5, %lo(.LCPI6_0)(a0)
8786
; CHECK-NEXT: vsetivli zero, 1, e8, mf8, ta, ma
8887
; CHECK-NEXT: vmv.v.i v0, 6
89-
; CHECK-NEXT: vsetivli zero, 4, e64, m2, ta, mu
90-
; CHECK-NEXT: vfmv.v.f v10, fa5
91-
; CHECK-NEXT: vrgather.vi v8, v10, 1, v0.t
88+
; CHECK-NEXT: vsetivli zero, 4, e64, m2, ta, ma
89+
; CHECK-NEXT: vfmerge.vfm v8, v8, fa5, v0
9290
; CHECK-NEXT: ret
9391
%s = shufflevector <4 x double> %x, <4 x double> <double poison, double 5.0, double poison, double poison>, <4 x i32> <i32 0, i32 5, i32 5, i32 3>
9492
ret <4 x double> %s

0 commit comments

Comments
 (0)