Skip to content

Commit ba65710

Browse files
authored
[RISCV] Avoid redundant SchedRead on _TIED VPseudos (#113940)
_TIED and _MASK_TIED pseudos have one less operand compared to other pseudos, thus we shouldn't attach the same number of SchedRead for these instructions. I don't think we have a way to (explicitly) check scheduling classes. So I only test this patch with existing tests.
1 parent 528e975 commit ba65710

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoV.td

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,28 @@ class SchedCommon<list<SchedWrite> writes, list<SchedRead> reads,
104104
string mx = "WorstCase", int sew = 0, bit forceMasked = 0,
105105
bit forcePassthruRead = 0> : Sched<[]> {
106106
defvar isMasked = !ne(!find(NAME, "_MASK"), -1);
107+
defvar isTied = !ne(!find(NAME, "_TIED"), -1);
107108
defvar isMaskedOrForceMasked = !or(forceMasked, isMasked);
109+
defvar isTiedMasked = !and(isMaskedOrForceMasked, isTied);
108110
defvar passthruRead = !if(!or(!eq(mx, "WorstCase"), !eq(sew, 0)),
109111
!cast<SchedRead>("ReadVPassthru_" # mx),
110112
!cast<SchedRead>("ReadVPassthru_" # mx # "_E" #sew));
111-
defvar needsPassthruRead = !or(isMaskedOrForceMasked, forcePassthruRead);
113+
// We don't need passthru operand if it's already _TIED without mask.
114+
defvar needsForcePassthruRead = !and(forcePassthruRead, !not(isTied));
115+
defvar needsPassthruRead = !or(isMaskedOrForceMasked, needsForcePassthruRead);
116+
// If this is a _TIED + masked operation, $rs2 (i.e. the first operand) is
117+
// merged with the mask.
118+
// NOTE: the following if statement is written in such a weird way because
119+
// should we want to write something like
120+
// `!if(!and(!not(!empty(reads), isTiedMasked), !tail(reads), reads)`
121+
// since `!if` doesn't have a proper short-circuit behavior, if the
122+
// condition of this `!if` cannot be resolved right away, `!tail(reads)` will
123+
// be immediately evaluated anyway even when `reads` is empty, which leads to
124+
// an assertion failure.
125+
defvar readsWithTiedMask =
126+
!if(isTiedMasked, !if(!not(!empty(reads)), !tail(reads), reads), reads);
112127
defvar readsWithMask =
113-
!if(isMaskedOrForceMasked, !listconcat(reads, [ReadVMask]), reads);
128+
!if(isMaskedOrForceMasked, !listconcat(readsWithTiedMask, [ReadVMask]), reads);
114129
defvar allReads =
115130
!if(needsPassthruRead, !listconcat([passthruRead], readsWithMask), reads);
116131
let SchedRW = !listconcat(writes, allReads);

0 commit comments

Comments
 (0)