Skip to content

Commit 14ea545

Browse files
committed
[RISCV][InsertVSETVLI] Generalize scalar move rule for when AVL is unchanged
By definition, the AVL of the scalar move is equally zero to the prior AVL if they are the same value. This generalizes the existing code to the case where the scalar move has a register AVL which is unknown, but unchanged from the preceeding instruction. This doesn't cause any interesting diffs on its own, but another patch makes this case much more common. Split off to reduce a future diff.
1 parent 91b38c6 commit 14ea545

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,13 @@ class VSETVLIInfo {
304304
return false;
305305
}
306306

307+
bool hasEquallyZeroAVL(const VSETVLIInfo &Other) const {
308+
if (hasSameAVL(Other))
309+
return true;
310+
return (hasNonZeroAVL() && Other.hasNonZeroAVL());
311+
}
312+
307313
bool hasSameAVL(const VSETVLIInfo &Other) const {
308-
assert(isValid() && Other.isValid() &&
309-
"Can't compare invalid VSETVLIInfos");
310-
assert(!isUnknown() && !Other.isUnknown() &&
311-
"Can't compare AVL in unknown state");
312314
if (hasAVLReg() && Other.hasAVLReg())
313315
return getAVLReg() == Other.getAVLReg();
314316

@@ -771,12 +773,10 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
771773
return true;
772774

773775
// For vmv.s.x and vfmv.s.f, there is only two behaviors, VL = 0 and VL > 0.
774-
// VL=0 is uninteresting (as it should have been deleted already), so it is
775-
// compatible if we can prove both are non-zero. Additionally, if writing
776-
// to an implicit_def operand, we don't need to preserve any other bits and
777-
// are thus compatible with any larger etype, and can disregard policy bits.
778-
if (isScalarMoveInstr(MI) &&
779-
CurInfo.hasNonZeroAVL() && Require.hasNonZeroAVL()) {
776+
// Additionally, if writing to an implicit_def operand, we don't need to
777+
// preserve any other bits and are thus compatible with any larger etype,
778+
// and can disregard policy bits.
779+
if (isScalarMoveInstr(MI) && CurInfo.hasEquallyZeroAVL(Require)) {
780780
auto *VRegDef = MRI->getVRegDef(MI.getOperand(1).getReg());
781781
if (VRegDef && VRegDef->isImplicitDef() &&
782782
CurInfo.getSEW() >= Require.getSEW())
@@ -830,7 +830,7 @@ void RISCVInsertVSETVLI::transferBefore(VSETVLIInfo &Info, const MachineInstr &M
830830
// prevent extending live range of an avl register operand.
831831
// TODO: We can probably relax this for immediates.
832832
if (isScalarMoveInstr(MI) && PrevInfo.isValid() &&
833-
PrevInfo.hasNonZeroAVL() && Info.hasNonZeroAVL() &&
833+
PrevInfo.hasEquallyZeroAVL(Info) &&
834834
Info.hasSameVLMAX(PrevInfo)) {
835835
if (PrevInfo.hasAVLImm())
836836
Info.setAVLImm(PrevInfo.getAVLImm());

0 commit comments

Comments
 (0)