Skip to content

[RISCV] Avoid redundant SchedRead on _TIED VPseudos #113940

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

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions llvm/lib/Target/RISCV/RISCVInstrInfoV.td
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,28 @@ class SchedCommon<list<SchedWrite> writes, list<SchedRead> reads,
string mx = "WorstCase", int sew = 0, bit forceMasked = 0,
bit forcePassthruRead = 0> : Sched<[]> {
defvar isMasked = !ne(!find(NAME, "_MASK"), -1);
defvar isTied = !ne(!find(NAME, "_TIED"), -1);
defvar isMaskedOrForceMasked = !or(forceMasked, isMasked);
defvar isTiedMasked = !and(isMaskedOrForceMasked, isTied);
defvar passthruRead = !if(!or(!eq(mx, "WorstCase"), !eq(sew, 0)),
!cast<SchedRead>("ReadVPassthru_" # mx),
!cast<SchedRead>("ReadVPassthru_" # mx # "_E" #sew));
defvar needsPassthruRead = !or(isMaskedOrForceMasked, forcePassthruRead);
// We don't need passthru operand if it's already _TIED without mask.
defvar needsForcePassthruRead = !and(forcePassthruRead, !not(isTied));
defvar needsPassthruRead = !or(isMaskedOrForceMasked, needsForcePassthruRead);
// If this is a _TIED + masked operation, $rs2 (i.e. the first operand) is
// merged with the mask.
// NOTE: the following if statement is written in such a weird way because
// should we want to write something like
// `!if(!and(!not(!empty(reads), isTiedMasked), !tail(reads), reads)`
// since `!if` doesn't have a proper short-circuit behavior, if the
// condition of this `!if` cannot be resolved right away, `!tail(reads)` will
// be immediately evaluated anyway even when `reads` is empty, which leads to
// an assertion failure.
defvar readsWithTiedMask =
!if(isTiedMasked, !if(!not(!empty(reads)), !tail(reads), reads), reads);
defvar readsWithMask =
!if(isMaskedOrForceMasked, !listconcat(reads, [ReadVMask]), reads);
!if(isMaskedOrForceMasked, !listconcat(readsWithTiedMask, [ReadVMask]), reads);
defvar allReads =
!if(needsPassthruRead, !listconcat([passthruRead], readsWithMask), reads);
let SchedRW = !listconcat(writes, allReads);
Expand Down
Loading