This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Check for alignment when selecting whole register loads/stores
AbandonedPublic

Authored by luke on Jul 7 2023, 12:39 PM.

Details

Summary

As per the specification, whole register vector loads and stores may raise a
misaligned address exception "if the base address is not naturally aligned to
the larger of the size of the encoded EEW in bytes (EEW/8) or the
implementation’s smallest supported SEW size in bytes (SEWMIN/8)."

This patch adds a predicate to ensure the alignment is greater than or equal to
the EEW in bytes. It doesn't check SEWMIN however since the smallest SEW can be
with the standard extensions is 8 bytes.

Note that this doesn't fix the issue raised here:
https://reviews.llvm.org/D154536#inline-1495073

Diff Detail

Event Timeline

luke created this revision.Jul 7 2023, 12:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2023, 12:39 PM
luke requested review of this revision.Jul 7 2023, 12:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2023, 12:39 PM

So what we're saying is the -mattr=+unaligned-vector-mem that we made up does not apply to whole register load/store? but applies regular loads and store?

llvm/test/CodeGen/RISCV/rvv/unaligned-loads-stores.ll
68

Couldn't we use vl1r.v?

239

Doesn't vs2r.v have an EEW of 8?

luke added inline comments.Jul 7 2023, 12:53 PM
llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td
69

I'm actually not sure if we need to do this for stores anymore. From the spec:

The load instructions have an EEW encoded in the mew and width elds following the pattern of regular unit-stride loads.
The vector whole register store instructions are encoded similar to unmasked unit-stride store of elements with EEW=8.

So the whole register stores don't have EEW encoded with them: So is their EEW always 8 or is it taken from SEW? If it's taken from SEW then I think we would need a pseudo to propagate this information to insertvsetvli. Otherwise we don't actually need to check the alignment here.

llvm/test/CodeGen/RISCV/rvv/unaligned-loads-stores.ll
68

I think so. Will take a look

luke added inline comments.Jul 7 2023, 12:56 PM
llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td
69

A bit further down in section 7.9:

Implementations are allowed to raise a misaligned address exception on whole register loads and stores if the base address is not naturally aligned to ...

So does this imply that it is possible for the store's EEW to not be 8?

luke abandoned this revision.Jul 7 2023, 1:04 PM

These test cases are actually correct, I've misread the UNALIGNED checks