Skip to content

Commit

Permalink
[RISCV][NFC] Unify compatibility checks under one function
Browse files Browse the repository at this point in the history
Split off from D125021.

We were duplicating logic across different phases. Since we want to
ensure a consistency of logic across phases for correctness, this patch
combines our multiple compatibility checks into one function to better
convey this.

Several methods were made const too.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D126472
  • Loading branch information
frasercrmck committed May 27, 2022
1 parent f168a65 commit 3e450d9
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
Expand Up @@ -453,8 +453,12 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
StringRef getPassName() const override { return RISCV_INSERT_VSETVLI_NAME; }

private:
bool needVSETVLI(const VSETVLIInfo &Require, const VSETVLIInfo &CurInfo);
bool needVSETVLIPHI(const VSETVLIInfo &Require, const MachineBasicBlock &MBB);
bool needVSETVLI(const VSETVLIInfo &Require,
const VSETVLIInfo &CurInfo) const;
bool needVSETVLI(const MachineInstr &MI, const VSETVLIInfo &Require,
const VSETVLIInfo &CurInfo) const;
bool needVSETVLIPHI(const VSETVLIInfo &Require,
const MachineBasicBlock &MBB) const;
void insertVSETVLI(MachineBasicBlock &MBB, MachineInstr &MI,
const VSETVLIInfo &Info, const VSETVLIInfo &PrevInfo);
void insertVSETVLI(MachineBasicBlock &MBB,
Expand Down Expand Up @@ -715,7 +719,7 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI) {
}

bool RISCVInsertVSETVLI::needVSETVLI(const VSETVLIInfo &Require,
const VSETVLIInfo &CurInfo) {
const VSETVLIInfo &CurInfo) const {
if (CurInfo.isCompatible(Require))
return false;

Expand Down Expand Up @@ -934,6 +938,15 @@ bool canSkipVSETVLIForLoadStore(const MachineInstr &MI,
return CurInfo.isCompatibleWithLoadStoreEEW(EEW, Require);
}

bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI, const VSETVLIInfo &Require,
const VSETVLIInfo &CurInfo) const {
if (!needVSETVLI(Require, CurInfo))
return false;
// If this is a unit-stride or strided load/store, we may be able to use the
// EMUL=(EEW/SEW)*LMUL relationship to avoid changing VTYPE.
return !canSkipVSETVLIForLoadStore(MI, Require, CurInfo);
}

bool RISCVInsertVSETVLI::computeVLVTYPEChanges(const MachineBasicBlock &MBB) {
bool HadVectorOp = false;

Expand All @@ -958,13 +971,10 @@ bool RISCVInsertVSETVLI::computeVLVTYPEChanges(const MachineBasicBlock &MBB) {
} else {
// If this instruction isn't compatible with the previous VL/VTYPE
// we need to insert a VSETVLI.
// If this is a unit-stride or strided load/store, we may be able to use
// the EMUL=(EEW/SEW)*LMUL relationship to avoid changing vtype.
// NOTE: We only do this if the vtype we're comparing against was
// created in this block. We need the first and third phase to treat
// the store the same way.
if (!canSkipVSETVLIForLoadStore(MI, NewInfo, BBInfo.Change) &&
needVSETVLI(NewInfo, BBInfo.Change))
if (needVSETVLI(MI, NewInfo, BBInfo.Change))
BBInfo.Change = NewInfo;
}
}
Expand Down Expand Up @@ -1033,7 +1043,7 @@ void RISCVInsertVSETVLI::computeIncomingVLVTYPE(const MachineBasicBlock &MBB) {
// be/ unneeded if the AVL is a phi node where all incoming values are VL
// outputs from the last VSETVLI in their respective basic blocks.
bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
const MachineBasicBlock &MBB) {
const MachineBasicBlock &MBB) const {
if (DisableInsertVSETVLPHIOpt)
return true;

Expand Down Expand Up @@ -1128,13 +1138,10 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
} else {
// If this instruction isn't compatible with the previous VL/VTYPE
// we need to insert a VSETVLI.
// If this is a unit-stride or strided load/store, we may be able to use
// the EMUL=(EEW/SEW)*LMUL relationship to avoid changing vtype.
// NOTE: We can't use predecessor information for the store. We must
// treat it the same as the first phase so that we produce the correct
// vl/vtype for succesor blocks.
if (!canSkipVSETVLIForLoadStore(MI, NewInfo, CurInfo) &&
needVSETVLI(NewInfo, CurInfo)) {
if (needVSETVLI(MI, NewInfo, CurInfo)) {
insertVSETVLI(MBB, MI, NewInfo, CurInfo);
CurInfo = NewInfo;
}
Expand Down

0 comments on commit 3e450d9

Please sign in to comment.