Skip to content

Commit 17b2935

Browse files
committed
Revert "[RISCV][InsertVSETVLI] Make VL preserving vsetvli emission more explicit [nfc]"
This reverts commit 20fc8e8. As pointed out in review of the mentioned follow up patch, this gets the predicate wrong. We need not simply VL being unchanged, but VLMAX being unchanged. Given that the code structure I'd introduced here is simply confusing.
1 parent 34ed07e commit 17b2935

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,6 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
746746
const VSETVLIInfo &CurInfo) const;
747747
bool needVSETVLIPHI(const VSETVLIInfo &Require,
748748
const MachineBasicBlock &MBB) const;
749-
bool mayChangeVL(const VSETVLIInfo &Info, const VSETVLIInfo &PrevInfo) const;
750749
void insertVSETVLI(MachineBasicBlock &MBB, MachineInstr &MI,
751750
const VSETVLIInfo &Info, const VSETVLIInfo &PrevInfo);
752751
void insertVSETVLI(MachineBasicBlock &MBB,
@@ -860,47 +859,41 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI) {
860859
return NewInfo;
861860
}
862861

863-
/// Return true if a vsetvli instruction to change from PrevInfo
864-
/// to Info might change the VL register. If this returns false,
865-
/// the vsetvli can use the X0, X0 form.
866-
bool RISCVInsertVSETVLI::mayChangeVL(const VSETVLIInfo &Info,
867-
const VSETVLIInfo &PrevInfo) const {
868-
if (!PrevInfo.isValid() || PrevInfo.isUnknown())
869-
return true;
870-
871-
// If the AVL is the same and the SEW+LMUL gives the same VLMAX, VL
872-
// can not change.
873-
if (Info.hasSameAVL(PrevInfo) && Info.hasSameVLMAX(PrevInfo))
874-
return false;
875-
876-
// If our AVL is a virtual register, it might be defined by a VSET(I)VLI. If
877-
// it has the same VLMAX we want and the last VL/VTYPE we observed is the
878-
// same, then VL can not change.
879-
if (Info.hasSameVLMAX(PrevInfo) && Info.hasAVLReg() &&
880-
Info.getAVLReg().isVirtual()) {
881-
if (MachineInstr *DefMI = MRI->getVRegDef(Info.getAVLReg());
882-
DefMI && isVectorConfigInstr(*DefMI)) {
883-
VSETVLIInfo DefInfo = getInfoForVSETVLI(*DefMI);
884-
if (DefInfo.hasSameAVL(PrevInfo) && DefInfo.hasSameVLMAX(PrevInfo))
885-
return false;
886-
}
887-
}
888-
return true;
889-
}
890-
891862
void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
892863
MachineBasicBlock::iterator InsertPt, DebugLoc DL,
893864
const VSETVLIInfo &Info, const VSETVLIInfo &PrevInfo) {
894865

895-
// Use X0, X0 form if VL can't change. Changing only VTYPE is generally
896-
// cheaper than changing VL.
897-
if (!mayChangeVL(Info, PrevInfo)) {
898-
BuildMI(MBB, InsertPt, DL, TII->get(RISCV::PseudoVSETVLIX0))
899-
.addReg(RISCV::X0, RegState::Define | RegState::Dead)
900-
.addReg(RISCV::X0, RegState::Kill)
901-
.addImm(Info.encodeVTYPE())
902-
.addReg(RISCV::VL, RegState::Implicit);
903-
return;
866+
if (PrevInfo.isValid() && !PrevInfo.isUnknown()) {
867+
// Use X0, X0 form if the AVL is the same and the SEW+LMUL gives the same
868+
// VLMAX.
869+
if (Info.hasSameAVL(PrevInfo) && Info.hasSameVLMAX(PrevInfo)) {
870+
BuildMI(MBB, InsertPt, DL, TII->get(RISCV::PseudoVSETVLIX0))
871+
.addReg(RISCV::X0, RegState::Define | RegState::Dead)
872+
.addReg(RISCV::X0, RegState::Kill)
873+
.addImm(Info.encodeVTYPE())
874+
.addReg(RISCV::VL, RegState::Implicit);
875+
return;
876+
}
877+
878+
// If our AVL is a virtual register, it might be defined by a VSET(I)VLI. If
879+
// it has the same VLMAX we want and the last VL/VTYPE we observed is the
880+
// same, we can use the X0, X0 form.
881+
if (Info.hasSameVLMAX(PrevInfo) && Info.hasAVLReg() &&
882+
Info.getAVLReg().isVirtual()) {
883+
if (MachineInstr *DefMI = MRI->getVRegDef(Info.getAVLReg())) {
884+
if (isVectorConfigInstr(*DefMI)) {
885+
VSETVLIInfo DefInfo = getInfoForVSETVLI(*DefMI);
886+
if (DefInfo.hasSameAVL(PrevInfo) && DefInfo.hasSameVLMAX(PrevInfo)) {
887+
BuildMI(MBB, InsertPt, DL, TII->get(RISCV::PseudoVSETVLIX0))
888+
.addReg(RISCV::X0, RegState::Define | RegState::Dead)
889+
.addReg(RISCV::X0, RegState::Kill)
890+
.addImm(Info.encodeVTYPE())
891+
.addReg(RISCV::VL, RegState::Implicit);
892+
return;
893+
}
894+
}
895+
}
896+
}
904897
}
905898

906899
if (Info.hasAVLImm()) {

0 commit comments

Comments
 (0)