-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] enable VTYPE before whole RVVReg move #117866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b0d5b06
aa51793
fa361d5
88facd4
7530065
9740196
9e4eab8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -922,6 +922,7 @@ class RISCVInsertVSETVLI : public MachineFunctionPass { | |
VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI) const; | ||
VSETVLIInfo computeInfoForInstr(const MachineInstr &MI) const; | ||
void forwardVSETVLIAVL(VSETVLIInfo &Info) const; | ||
void insertVSETIVLIBeforeCopy(MachineBasicBlock &MBB); | ||
}; | ||
|
||
} // end anonymous namespace | ||
|
@@ -1768,6 +1769,55 @@ void RISCVInsertVSETVLI::insertReadVL(MachineBasicBlock &MBB) { | |
} | ||
} | ||
|
||
static bool isRVVCopy(const MachineInstr &MI) { | ||
static const TargetRegisterClass *RVVRegClasses[] = { | ||
&RISCV::VRRegClass, &RISCV::VRM2RegClass, &RISCV::VRM4RegClass, | ||
&RISCV::VRM8RegClass, &RISCV::VRN2M1RegClass, &RISCV::VRN2M2RegClass, | ||
&RISCV::VRN2M4RegClass, &RISCV::VRN3M1RegClass, &RISCV::VRN3M2RegClass, | ||
&RISCV::VRN4M1RegClass, &RISCV::VRN4M2RegClass, &RISCV::VRN5M1RegClass, | ||
&RISCV::VRN6M1RegClass, &RISCV::VRN7M1RegClass, &RISCV::VRN8M1RegClass}; | ||
|
||
if (MI.getOpcode() != TargetOpcode::COPY) | ||
return false; | ||
|
||
Register DstReg = MI.getOperand(0).getReg(); | ||
Register SrcReg = MI.getOperand(1).getReg(); | ||
for (const auto &RegClass : RVVRegClasses) { | ||
if (RegClass->contains(DstReg, SrcReg)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
void RISCVInsertVSETVLI::insertVSETIVLIBeforeCopy(MachineBasicBlock &MBB) { | ||
bool NeedVSETVL = true; | ||
|
||
if (!BlockInfo[MBB.getNumber()].Pred.isUnknown() && | ||
BlockInfo[MBB.getNumber()].Pred.isValid()) | ||
NeedVSETVL = false; | ||
|
||
for (auto &MI : MBB) { | ||
if (isVectorConfigInstr(MI) || RISCVII::hasSEWOp(MI.getDesc().TSFlags)) | ||
NeedVSETVL = false; | ||
|
||
if (MI.isCall() || MI.isInlineAsm()) | ||
NeedVSETVL = true; | ||
|
||
if (NeedVSETVL && isRVVCopy(MI)) { | ||
auto VSETVL0MI = | ||
BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(RISCV::PseudoVSETIVLI)) | ||
.addReg(RISCV::X0, RegState::Define | RegState::Dead) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't use x0, x0 when vtype is vill. The vtype is invalid and thus vlmax is invalid. You can only use x0, x0 when vlmax isn't being reduced since reducing vlmax may need to change VL. If vlmax is invalid due to vill, I don't think we can know that VL won't need to be reduced for the new vlmax. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should work. |
||
.addImm(0) | ||
.addImm(RISCVVType::encodeVTYPE(RISCVII::VLMUL::LMUL_1, 8, false, | ||
false)); | ||
if (LIS) | ||
LIS->InsertMachineInstrInMaps(*VSETVL0MI); | ||
NeedVSETVL = false; | ||
} | ||
} | ||
} | ||
|
||
bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) { | ||
// Skip if the vector extension is not enabled. | ||
ST = &MF.getSubtarget<RISCVSubtarget>(); | ||
|
@@ -1798,12 +1848,6 @@ bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) { | |
|
||
} | ||
|
||
// If we didn't find any instructions that need VSETVLI, we're done. | ||
if (!HaveVectorOp) { | ||
BlockInfo.clear(); | ||
return false; | ||
} | ||
|
||
// Phase 2 - determine the exit VL/VTYPE from each block. We add all | ||
// blocks to the list here, but will also add any that need to be revisited | ||
// during Phase 2 processing. | ||
|
@@ -1842,6 +1886,9 @@ bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) { | |
for (MachineBasicBlock &MBB : MF) | ||
insertReadVL(MBB); | ||
|
||
for (MachineBasicBlock &MBB : MF) | ||
insertVSETIVLIBeforeCopy(MBB); | ||
|
||
BlockInfo.clear(); | ||
return HaveVectorOp; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use
isRVVRegClass
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC
isRVVRegClass
is for virtual registers, and the insertvsetvl pass runs after RVV register allocation.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh thanks for reminding! Would
getMinimalPhysRegClass
and check the TSFlags better than a loop?