Skip to content

Commit 3373776

Browse files
mshockwavetopperc
andcommitted
[RISCV] Handle more cases when combining (vfmv_s_f (extract_subvector X, 0))
Co-Authored-By: Craig Topper <[email protected]>
1 parent 7451270 commit 3373776

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20738,12 +20738,22 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
2073820738
isNullConstant(Src.getOperand(1)) &&
2073920739
Src.getOperand(0).getValueType().isScalableVector()) {
2074020740
EVT VT = N->getValueType(0);
20741-
EVT SrcVT = Src.getOperand(0).getValueType();
20741+
SDValue EVSrc = Src.getOperand(0);
20742+
EVT SrcVT = EVSrc.getValueType();
2074220743
assert(SrcVT.getVectorElementType() == VT.getVectorElementType());
2074320744
// Widths match, just return the original vector.
2074420745
if (SrcVT == VT)
20745-
return Src.getOperand(0);
20746-
// TODO: Use insert_subvector/extract_subvector to change widen/narrow?
20746+
return EVSrc;
20747+
SDLoc DL(N);
20748+
// Width is narrower, using insert_subvector.
20749+
if (SrcVT.getVectorMinNumElements() < VT.getVectorMinNumElements()) {
20750+
return DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT, DAG.getUNDEF(VT),
20751+
EVSrc,
20752+
DAG.getConstant(0, DL, Subtarget.getXLenVT()));
20753+
}
20754+
// Width is wider, using extract_subvector.
20755+
return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VT, EVSrc,
20756+
DAG.getConstant(0, DL, Subtarget.getXLenVT()));
2074720757
}
2074820758
[[fallthrough]];
2074920759
}

llvm/test/CodeGen/RISCV/rvv/redundant-vfmvsf.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ define <2 x float> @redundant_vfmv(<2 x float> %arg0, <64 x float> %arg1, <64 x
99
; CHECK-NEXT: vfredusum.vs v9, v12, v8
1010
; CHECK-NEXT: vsetivli zero, 1, e32, mf2, ta, ma
1111
; CHECK-NEXT: vslidedown.vi v8, v8, 1
12-
; CHECK-NEXT: vfmv.f.s fa5, v8
13-
; CHECK-NEXT: vfmv.s.f v8, fa5
1412
; CHECK-NEXT: vsetvli zero, a0, e32, m4, ta, ma
1513
; CHECK-NEXT: vfredusum.vs v8, v16, v8
1614
; CHECK-NEXT: vfmv.f.s fa5, v8

0 commit comments

Comments
 (0)