Skip to content

Commit c073821

Browse files
authored
[RISCV] Reduce VL of vmerge.vvm's true operand (#105786)
This extends the peephole added in #104689 to also reduce the VL of a PseudoVMERGE_VVM's true operand. We could extend this later to reduce the false operand as well, but this starts with just the true operand since it allows vmerges that are converted to vmv.v.vs (convertVMergeToVMv) to be potentially further folded into their source (foldVMV_V_V).
1 parent bbf2781 commit c073821

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ bool RISCVVectorPeephole::tryToReduceVL(MachineInstr &MI) const {
131131
case RISCV::VMV_V_V:
132132
SrcIdx = 2;
133133
break;
134+
case RISCV::VMERGE_VVM:
135+
SrcIdx = 3; // TODO: We can also handle the false operand.
136+
break;
134137
}
135138

136139
MachineOperand &VL = MI.getOperand(RISCVII::getVLOpNum(MI.getDesc()));

llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-masked-vops.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ define <vscale x 2 x i32> @vmerge_larger_vl_same_passthru(<vscale x 2 x i32> %pa
159159
define <vscale x 2 x i32> @vmerge_smaller_vl_different_passthru(<vscale x 2 x i32> %pt1, <vscale x 2 x i32> %pt2, <vscale x 2 x i32> %x, <vscale x 2 x i32> %y, <vscale x 2 x i1> %m) {
160160
; CHECK-LABEL: vmerge_smaller_vl_different_passthru:
161161
; CHECK: # %bb.0:
162-
; CHECK-NEXT: vsetivli zero, 3, e32, m1, tu, mu
162+
; CHECK-NEXT: vsetivli zero, 2, e32, m1, tu, mu
163163
; CHECK-NEXT: vadd.vv v8, v10, v11, v0.t
164-
; CHECK-NEXT: vsetivli zero, 2, e32, m1, tu, ma
165164
; CHECK-NEXT: vmv.v.v v9, v8
166165
; CHECK-NEXT: vmv1r.v v8, v9
167166
; CHECK-NEXT: ret

llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-vops.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,9 +1072,8 @@ define <vscale x 2 x i32> @vmerge_larger_vl_same_passthru(<vscale x 2 x i32> %pa
10721072
define <vscale x 2 x i32> @vmerge_smaller_vl_different_passthru(<vscale x 2 x i32> %pt1, <vscale x 2 x i32> %pt2, <vscale x 2 x i32> %x, <vscale x 2 x i32> %y, <vscale x 2 x i1> %m) {
10731073
; CHECK-LABEL: vmerge_smaller_vl_different_passthru:
10741074
; CHECK: # %bb.0:
1075-
; CHECK-NEXT: vsetivli zero, 3, e32, m1, tu, ma
1076-
; CHECK-NEXT: vadd.vv v8, v10, v11
10771075
; CHECK-NEXT: vsetivli zero, 2, e32, m1, tu, ma
1076+
; CHECK-NEXT: vadd.vv v8, v10, v11
10781077
; CHECK-NEXT: vmerge.vvm v9, v9, v8, v0
10791078
; CHECK-NEXT: vmv1r.v v8, v9
10801079
; CHECK-NEXT: ret

0 commit comments

Comments
 (0)