Skip to content

Commit c8ee116

Browse files
authored
[RISCV] Fix masked->unmasked peephole handling masked pseudos with no passthru (#122253)
Some masked pseudos like PseudoVCPOP_M_B8_MASK don't have a passthru, but in the masked->unmasked peephole we assumed the masked pseudo always had one. This checks for a passthru first and fixes #122245.
1 parent dcdf44a commit c8ee116

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,13 @@ bool RISCVVectorPeephole::convertToUnmasked(MachineInstr &MI) const {
460460
[[maybe_unused]] const bool HasPolicyOp =
461461
RISCVII::hasVecPolicyOp(MCID.TSFlags);
462462
const bool HasPassthru = RISCVII::isFirstDefTiedToFirstUse(MCID);
463-
#ifndef NDEBUG
464463
const MCInstrDesc &MaskedMCID = TII->get(MI.getOpcode());
465464
assert(RISCVII::hasVecPolicyOp(MaskedMCID.TSFlags) ==
466465
RISCVII::hasVecPolicyOp(MCID.TSFlags) &&
467466
"Masked and unmasked pseudos are inconsistent");
468467
assert(HasPolicyOp == HasPassthru && "Unexpected pseudo structure");
469-
#endif
468+
assert(!(HasPassthru && !RISCVII::isFirstDefTiedToFirstUse(MaskedMCID)) &&
469+
"Unmasked with passthru but masked with no passthru?");
470470
(void)HasPolicyOp;
471471

472472
MI.setDesc(MCID);
@@ -478,12 +478,16 @@ bool RISCVVectorPeephole::convertToUnmasked(MachineInstr &MI) const {
478478
// The unmasked pseudo will no longer be constrained to the vrnov0 reg class,
479479
// so try and relax it to vr.
480480
MRI->recomputeRegClass(MI.getOperand(0).getReg());
481-
unsigned PassthruOpIdx = MI.getNumExplicitDefs();
482-
if (HasPassthru) {
483-
if (MI.getOperand(PassthruOpIdx).getReg() != RISCV::NoRegister)
484-
MRI->recomputeRegClass(MI.getOperand(PassthruOpIdx).getReg());
485-
} else
486-
MI.removeOperand(PassthruOpIdx);
481+
482+
// If the original masked pseudo had a passthru, relax it or remove it.
483+
if (RISCVII::isFirstDefTiedToFirstUse(MaskedMCID)) {
484+
unsigned PassthruOpIdx = MI.getNumExplicitDefs();
485+
if (HasPassthru) {
486+
if (MI.getOperand(PassthruOpIdx).getReg() != RISCV::NoRegister)
487+
MRI->recomputeRegClass(MI.getOperand(PassthruOpIdx).getReg());
488+
} else
489+
MI.removeOperand(PassthruOpIdx);
490+
}
487491

488492
return true;
489493
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc %s -o - -mtriple=riscv64 -mattr=+v -run-pass=riscv-vector-peephole -verify-machineinstrs | FileCheck %s
3+
4+
# Take into account that the masked vcpop pseudo doesn't have a passthru
5+
---
6+
name: vcpop.m
7+
body: |
8+
bb.0:
9+
; CHECK-LABEL: name: vcpop.m
10+
; CHECK: %allones:vr = PseudoVMSET_M_B64 $noreg, 0 /* e8 */
11+
; CHECK-NEXT: $v0 = COPY %allones
12+
; CHECK-NEXT: [[PseudoVCPOP_M_B64_:%[0-9]+]]:gpr = PseudoVCPOP_M_B64 $noreg, 42, 0 /* e8 */
13+
%allones:vr = PseudoVMSET_M_B64 $noreg, 0
14+
$v0 = COPY %allones
15+
%2:gpr = PseudoVCPOP_M_B64_MASK $noreg, $v0, 42, 0
16+
...

0 commit comments

Comments
 (0)