[RISCV] Use tail agnostic policy for instructions with tied defs if the use operand is IMPLICIT_DEF.

The vcompress intrinsic is defined such that it requires a tail
undisturbed policy. This patch makes it so we can use the tail
agnostic policy if the user has passed vundefined to the dest
operand.

We need to do something similar for masked policy, but we need
annotation of which instructions use the mask policy first.

Not sure if this is sufficient for scheduling or if we'll need to
select different pseudos that don't have a tied def.

Reviewed By: evandro

Differential Revision: https://reviews.llvm.org/D94566
This commit is contained in:
Craig Topper 2021-01-17 23:46:43 -08:00
parent cfec6cd50c
commit 383b6501ff
3 changed files with 43 additions and 1 deletions

View File

@ -2319,8 +2319,15 @@ static MachineBasicBlock *addVSetVL(MachineInstr &MI, MachineBasicBlock *BB,
// FIXME: This is conservatively correct, but we might want to detect that
// the input is undefined.
bool TailAgnostic = true;
if (MI.isRegTiedToUseOperand(0) && !WritesElement0)
unsigned UseOpIdx;
if (MI.isRegTiedToUseOperand(0, &UseOpIdx) && !WritesElement0) {
TailAgnostic = false;
// If the tied operand is an IMPLICIT_DEF we can keep TailAgnostic.
const MachineOperand &UseMO = MI.getOperand(UseOpIdx);
MachineInstr *UseMI = MRI.getVRegDef(UseMO.getReg());
if (UseMI && UseMI->isImplicitDef())
TailAgnostic = true;
}
// For simplicity we reuse the vtype representation here.
MIB.addImm(RISCVVType::encodeVTYPE(VLMul, ElementWidth,

View File

@ -738,3 +738,21 @@ entry:
ret <vscale x 8 x double> %a
}
; Test with undef for the dest operand. This should use tail agnostic policy.
define <vscale x 1 x i8> @intrinsic_vcompress_um_nxv1i8_nxv1i8(<vscale x 1 x i8> %0, <vscale x 1 x i1> %1, i32 %2) nounwind {
; CHECK-LABEL: intrinsic_vcompress_um_nxv1i8_nxv1i8:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: vsetvli a0, a0, e8,mf8,ta,mu
; CHECK-NEXT: vcompress.vm v25, v16, v0
; CHECK-NEXT: vmv1r.v v16, v25
; CHECK-NEXT: jalr zero, 0(ra)
entry:
%a = call <vscale x 1 x i8> @llvm.riscv.vcompress.nxv1i8(
<vscale x 1 x i8> undef,
<vscale x 1 x i8> %0,
<vscale x 1 x i1> %1,
i32 %2)
ret <vscale x 1 x i8> %a
}

View File

@ -828,3 +828,20 @@ entry:
ret <vscale x 8 x double> %a
}
; Test with undef for the dest operand. This should use tail agnostic policy.
define <vscale x 1 x i8> @intrinsic_vcompress_um_nxv1i8_nxv1i8(<vscale x 1 x i8> %0, <vscale x 1 x i1> %1, i64 %2) nounwind {
; CHECK-LABEL: intrinsic_vcompress_um_nxv1i8_nxv1i8:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: vsetvli a0, a0, e8,mf8,ta,mu
; CHECK-NEXT: vcompress.vm v25, v16, v0
; CHECK-NEXT: vmv1r.v v16, v25
; CHECK-NEXT: jalr zero, 0(ra)
entry:
%a = call <vscale x 1 x i8> @llvm.riscv.vcompress.nxv1i8(
<vscale x 1 x i8> undef,
<vscale x 1 x i8> %0,
<vscale x 1 x i1> %1,
i64 %2)
ret <vscale x 1 x i8> %a
}