Skip to content

Commit 58e1c0e

Browse files
authored
[RISCV] Discard the false operand in vmerge.vvm -> vmv.v.v peephole (#106688)
vmerge.vvm needs to have an all ones mask, so nothing is taken from the false operand. So instead of checking that the passthru is the same as false, just use the passthru directly for the tail elements. This supersedes the convertVMergeToVMv part of #105788, as noted in https://github.com/llvm/llvm-project/pull/105788/files#r1731683971
1 parent 8e972ef commit 58e1c0e

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ bool RISCVVectorPeephole::convertToWholeRegister(MachineInstr &MI) const {
333333
return true;
334334
}
335335

336-
// Transform (VMERGE_VVM_<LMUL> false, false, true, allones, vl, sew) to
337-
// (VMV_V_V_<LMUL> false, true, vl, sew). It may decrease uses of VMSET.
336+
// Transform (VMERGE_VVM_<LMUL> pt, false, true, allones, vl, sew) to
337+
// (VMV_V_V_<LMUL> pt, true, vl, sew). It may decrease uses of VMSET.
338338
bool RISCVVectorPeephole::convertVMergeToVMv(MachineInstr &MI) const {
339339
#define CASE_VMERGE_TO_VMV(lmul) \
340340
case RISCV::PseudoVMERGE_VVM_##lmul: \
@@ -353,29 +353,21 @@ bool RISCVVectorPeephole::convertVMergeToVMv(MachineInstr &MI) const {
353353
CASE_VMERGE_TO_VMV(M8)
354354
}
355355

356-
Register PassthruReg = MI.getOperand(1).getReg();
357-
Register FalseReg = MI.getOperand(2).getReg();
358-
// Check passthru == false (or passthru == undef)
359-
if (PassthruReg != RISCV::NoRegister &&
360-
TRI->lookThruCopyLike(PassthruReg, MRI) !=
361-
TRI->lookThruCopyLike(FalseReg, MRI))
362-
return false;
363-
364356
assert(MI.getOperand(4).isReg() && MI.getOperand(4).getReg() == RISCV::V0);
365357
if (!isAllOnesMask(V0Defs.lookup(&MI)))
366358
return false;
367359

368360
MI.setDesc(TII->get(NewOpc));
369-
MI.removeOperand(1); // Passthru operand
370-
MI.tieOperands(0, 1); // Tie false to dest
361+
MI.removeOperand(2); // False operand
371362
MI.removeOperand(3); // Mask operand
372363
MI.addOperand(
373364
MachineOperand::CreateImm(RISCVII::TAIL_UNDISTURBED_MASK_UNDISTURBED));
374365

375366
// vmv.v.v doesn't have a mask operand, so we may be able to inflate the
376367
// register class for the destination and passthru operands e.g. VRNoV0 -> VR
377368
MRI->recomputeRegClass(MI.getOperand(0).getReg());
378-
MRI->recomputeRegClass(MI.getOperand(1).getReg());
369+
if (MI.getOperand(1).getReg() != RISCV::NoRegister)
370+
MRI->recomputeRegClass(MI.getOperand(1).getReg());
379371
return true;
380372
}
381373

llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-to-vmv.mir

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ body: |
1515
; CHECK-NEXT: %avl:gprnox0 = COPY $x1
1616
; CHECK-NEXT: %mask:vmv0 = PseudoVMSET_M_B8 %avl, 5 /* e32 */
1717
; CHECK-NEXT: $v0 = COPY %mask
18-
; CHECK-NEXT: %x:vr = PseudoVMV_V_V_M1 %false, %true, %avl, 5 /* e32 */, 0 /* tu, mu */
18+
; CHECK-NEXT: %x:vr = PseudoVMV_V_V_M1 $noreg, %true, %avl, 5 /* e32 */, 0 /* tu, mu */
1919
%false:vr = COPY $v8
2020
%true:vr = COPY $v9
2121
%avl:gprnox0 = COPY $x1
@@ -31,13 +31,13 @@ body: |
3131
; CHECK-LABEL: name: undef_false
3232
; CHECK: liveins: $x1, $v8, $v9
3333
; CHECK-NEXT: {{ $}}
34-
; CHECK-NEXT: %pt:vrnov0 = COPY $v8
34+
; CHECK-NEXT: %pt:vr = COPY $v8
3535
; CHECK-NEXT: %false:vr = COPY $noreg
3636
; CHECK-NEXT: %true:vr = COPY $v9
3737
; CHECK-NEXT: %avl:gprnox0 = COPY $x1
3838
; CHECK-NEXT: %mask:vmv0 = PseudoVMSET_M_B8 %avl, 5 /* e32 */
3939
; CHECK-NEXT: $v0 = COPY %mask
40-
; CHECK-NEXT: %x:vrnov0 = PseudoVMERGE_VVM_M1 %pt, %false, %true, $v0, %avl, 5 /* e32 */
40+
; CHECK-NEXT: %x:vr = PseudoVMV_V_V_M1 %pt, %true, %avl, 5 /* e32 */, 0 /* tu, mu */
4141
%pt:vrnov0 = COPY $v8
4242
%false:vr = COPY $noreg
4343
%true:vr = COPY $v9
@@ -55,12 +55,12 @@ body: |
5555
; CHECK: liveins: $x1, $v8, $v9
5656
; CHECK-NEXT: {{ $}}
5757
; CHECK-NEXT: %false:vr = COPY $v8
58-
; CHECK-NEXT: %pt:vrnov0 = COPY $v8
58+
; CHECK-NEXT: %pt:vr = COPY $v8
5959
; CHECK-NEXT: %true:vr = COPY $v9
6060
; CHECK-NEXT: %avl:gprnox0 = COPY $x1
6161
; CHECK-NEXT: %mask:vmv0 = PseudoVMSET_M_B8 %avl, 5 /* e32 */
6262
; CHECK-NEXT: $v0 = COPY %mask
63-
; CHECK-NEXT: %x:vr = PseudoVMV_V_V_M1 %false, %true, %avl, 5 /* e32 */, 0 /* tu, mu */
63+
; CHECK-NEXT: %x:vr = PseudoVMV_V_V_M1 %pt, %true, %avl, 5 /* e32 */, 0 /* tu, mu */
6464
%false:vr = COPY $v8
6565
%pt:vrnov0 = COPY $v8
6666
%true:vr = COPY $v9

0 commit comments

Comments
 (0)