This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Document overview of vector pseudos [nfc]
ClosedPublic

Authored by reames on Jun 14 2023, 10:43 AM.

Details

Summary

I tried to give a rough overview of our current pseudo structure. I'm mostly focused on the policy handling bits - since that's what I'm in the process of changing - but touched on the other dimensions in the process of framing it.

Diff Detail

Event Timeline

reames created this revision.Jun 14 2023, 10:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2023, 10:43 AM
reames requested review of this revision.Jun 14 2023, 10:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2023, 10:43 AM
reames updated this revision to Diff 531424.Jun 14 2023, 10:44 AM

Fix a minor spelling mistake.

craig.topper added inline comments.Jun 14 2023, 1:39 PM
llvm/lib/Target/RISCV/RISCVInstrInfo.h
303 ↗(On Diff #531424)

knownledge -> knowledge

328 ↗(On Diff #531424)

How do we represent "undefined" for fma, integer multiple-accumulate where the destination is also an arithmetic source. Also vslideup where the destination is used for elements below offset and for the tail, but only tail follows the tail policy.

How do we represent tail "undefined" vs tail "agnostic" for _MASK?

Generally not sure about the commenting style - I don't think this usage necessitates C-style comments as described here: https://llvm.org/docs/CodingStandards.html#comment-formatting

llvm/lib/Target/RISCV/RISCVInstrInfo.h
326 ↗(On Diff #531424)

existance -> existence

eopXD added inline comments.Jun 15 2023, 12:07 AM
llvm/lib/Target/RISCV/RISCVInstrInfo.h
299 ↗(On Diff #531424)

Adding upon this, the behavior of "bit pattern -1"" or "preserve" can be different among different lanes.

321 ↗(On Diff #531424)

TA is abbreviation for tail agnostic.

I agree that the meaning is ambiguous, as

  1. Unmasked intrinsics that model policy behavior, and set to tail-agnostic
  2. Intrinsics that does not model a policy behavior

both share this same state.

luke added inline comments.Jun 15 2023, 2:43 AM
llvm/lib/Target/RISCV/RISCVInstrInfo.h
300 ↗(On Diff #531424)

Is undefined actually a policy, or just a common representation within the backend? Because I don’t think we can mix both tail undefined and mask undisturbed policies, or that there’s no way to represent it at least

323 ↗(On Diff #531424)

Not for this patch, but should we standardise the terminology of passthrough vs. merge throughout the backend and pick one? My weak preference would be for passthrough as it’s less confusing with vmerge etc.

luke added inline comments.Jun 15 2023, 2:49 AM
llvm/lib/Target/RISCV/RISCVInstrInfo.h
323 ↗(On Diff #531424)

Not all TU pseudos have a policy operand (as of today). Should we document that without the policy operand it defaults to TUMU?

eopXD added inline comments.Jun 15 2023, 2:54 AM
llvm/lib/Target/RISCV/RISCVInstrInfo.h
323 ↗(On Diff #531424)

I think all unmasked Pseudo does not have a policy operand.

When the merge operand is undef, the tail policy is agnostic. When the merge operand is not undef, the tail policy is undisturbed.

I don't quite understand what are the instructions are affected by the default setting you have mentioned. My understanding is that at Pseudo instruction level the vector instructions all have explicit policy information. May you elaborate more?

luke added inline comments.Jun 15 2023, 3:42 AM
llvm/lib/Target/RISCV/RISCVInstrInfo.h
323 ↗(On Diff #531424)

Thanks for clarifying this, I just did a quick check: with the exception of the VPseudoTiedBinaryNoMask class, unmasked pseudos don't have a policy operand.

The bit that I'm getting confused about is the sentence below:

Otherwise, policy operand and tablegen flags drive the interpretation.

Since TU pseudos are unmasked and don't have a policy operand.

By "default" I meant what policy is computed in computeInfoForInstr in RISCVInsertVSETVLI.cpp when there's no policy operand, and this is the piece of logic here:

bool TailAgnostic = true;
bool MaskAgnostic = true;
if (!hasUndefinedMergeOp(MI, *MRI)) {
  // Start with undisturbed.
  TailAgnostic = false;
  MaskAgnostic = false;

  // If there is a policy operand, use it.
  if (RISCVII::hasVecPolicyOp(TSFlags)) {
    const MachineOperand &Op = MI.getOperand(MI.getNumExplicitOperands() - 1);
    uint64_t Policy = Op.getImm();
    assert(Policy <= (RISCVII::TAIL_AGNOSTIC | RISCVII::MASK_AGNOSTIC) &&
           "Invalid Policy Value");
    TailAgnostic = Policy & RISCVII::TAIL_AGNOSTIC;
    MaskAgnostic = Policy & RISCVII::MASK_AGNOSTIC;
  }

  // Some pseudo instructions force a tail agnostic policy despite having a
  // tied def.
  if (RISCVII::doesForceTailAgnostic(TSFlags))
    TailAgnostic = true;

  if (!RISCVII::usesMaskPolicy(TSFlags))
    MaskAgnostic = true;
}

So as you say, unmasked pseudos don't have a policy operand and so are TUMU "by default", unless the merge operand is undefined in which case it's TAMA.

eopXD added inline comments.Jun 15 2023, 5:51 AM
llvm/lib/Target/RISCV/RISCVInstrInfo.h
323 ↗(On Diff #531424)

I think having undisturbed as default may not be a good choice, since the vector extension is targeting high performance, and possibly out-of-order cores. The undisturbed policy is likely to ruin the performance.

reames updated this revision to Diff 532341.Jun 16 2023, 5:49 PM
reames edited the summary of this revision. (Show Details)

Update based on comments and further digging.

reames added inline comments.Jun 16 2023, 5:52 PM
llvm/lib/Target/RISCV/RISCVInstrInfo.h
323 ↗(On Diff #531424)

I'm trying to move away from a model where the default is meaningful. Always having an explicit policy operand means the instruction carries the flags, and we can simply setup an agnostic flag if useful.

328 ↗(On Diff #531424)

Right now, we don't represent undefined for either of these cases. We could extend the policy operand with additional bits if desired, but for the moment, but I'm not sure this is warranted at this time.

craig.topper retitled this revision from [RISCV] Document overview of vector psuedos [nfc] to [RISCV] Document overview of vector pseudos [nfc].Jun 17 2023, 6:46 PM
luke accepted this revision.Jun 19 2023, 8:25 AM

Nice to have the clarification on the policy families, LGTM

This revision is now accepted and ready to land.Jun 19 2023, 8:25 AM
asb accepted this revision.Jun 22 2023, 6:58 AM

Left a tiny nit comment, but looks good (and indeed, very helpful!) to me.

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
47

Nit, should either change the item above to *, or change this one to 2) for consistency.

This revision was automatically updated to reflect the committed changes.