Skip to content

Commit 6707b33

Browse files
authored
[RISCV] Don't set AVL if only zeroness is demanded (#74049)
This refactors the logic in transferBefore so that we're moving in the direction of "keep the existing Info, only change what is needed". For the sake of review there are two commits in this PR: The former is needed to make the latter an NFC commit. Neither introduce any test diffs but the former is not technically NFC, hence why I did not precommit it. - [RISCV] Preserve AVL when previous info is ratio only in transferBefore - [RISCV] Don't change AVL if only zeroness is demanded. NFC
1 parent 3944504 commit 6707b33

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,14 +1059,23 @@ void RISCVInsertVSETVLI::transferBefore(VSETVLIInfo &Info,
10591059
return;
10601060

10611061
const VSETVLIInfo PrevInfo = Info;
1062-
if (Info.hasSEWLMULRatioOnly() || !Info.isValid() || Info.isUnknown())
1062+
if (!Info.isValid() || Info.isUnknown())
10631063
Info = NewInfo;
10641064

10651065
DemandedFields Demanded = getDemanded(MI, MRI, ST);
10661066
const VSETVLIInfo IncomingInfo =
10671067
adjustIncoming(PrevInfo, NewInfo, Demanded, MRI);
10681068

1069-
if (Demanded.usedVL())
1069+
// If MI only demands that VL has the same zeroness, we only need to set the
1070+
// AVL if the zeroness differs. This removes a vsetvli entirely if the types
1071+
// match or allows use of cheaper avl preserving variant if VLMAX doesn't
1072+
// change. If VLMAX might change, we couldn't use the 'vsetvli x0, x0, vtype"
1073+
// variant, so we avoid the transform to prevent extending live range of an
1074+
// avl register operand.
1075+
// TODO: We can probably relax this for immediates.
1076+
bool EquallyZero = IncomingInfo.hasEquallyZeroAVL(PrevInfo, *MRI) &&
1077+
IncomingInfo.hasSameVLMAX(PrevInfo);
1078+
if (Demanded.VLAny || (Demanded.VLZeroness && !EquallyZero))
10701079
Info.setAVL(IncomingInfo);
10711080

10721081
Info.setVTYPE(
@@ -1079,6 +1088,14 @@ void RISCVInsertVSETVLI::transferBefore(VSETVLIInfo &Info,
10791088
IncomingInfo.getTailAgnostic(),
10801089
(Demanded.MaskPolicy ? IncomingInfo : Info).getMaskAgnostic() ||
10811090
IncomingInfo.getMaskAgnostic());
1091+
1092+
// If we only knew the sew/lmul ratio previously, replace the VTYPE but keep
1093+
// the AVL.
1094+
if (Info.hasSEWLMULRatioOnly()) {
1095+
VSETVLIInfo RatiolessInfo = IncomingInfo;
1096+
RatiolessInfo.setAVL(Info);
1097+
Info = RatiolessInfo;
1098+
}
10821099
}
10831100

10841101
static VSETVLIInfo adjustIncoming(VSETVLIInfo PrevInfo, VSETVLIInfo NewInfo,
@@ -1097,20 +1114,6 @@ static VSETVLIInfo adjustIncoming(VSETVLIInfo PrevInfo, VSETVLIInfo NewInfo,
10971114
Demanded.LMUL = true;
10981115
}
10991116

1100-
// If we only demand VL zeroness (i.e. vmv.s.x and vmv.x.s), then there are
1101-
// only two behaviors, VL = 0 and VL > 0. We can discard the user requested
1102-
// AVL and just use the last one if we can prove it equally zero. This
1103-
// removes a vsetvli entirely if the types match or allows use of cheaper avl
1104-
// preserving variant if VLMAX doesn't change. If VLMAX might change, we
1105-
// couldn't use the 'vsetvli x0, x0, vtype" variant, so we avoid the transform
1106-
// to prevent extending live range of an avl register operand.
1107-
// TODO: We can probably relax this for immediates.
1108-
if (Demanded.VLZeroness && !Demanded.VLAny && PrevInfo.isValid() &&
1109-
PrevInfo.hasEquallyZeroAVL(Info, *MRI) && Info.hasSameVLMAX(PrevInfo)) {
1110-
Info.setAVL(PrevInfo);
1111-
Demanded.demandVL();
1112-
}
1113-
11141117
return Info;
11151118
}
11161119

0 commit comments

Comments
 (0)