This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Support LMUL!=1 for __attribute__((riscv_rvv_vector_bits(N)))
ClosedPublic

Authored by craig.topper on May 18 2023, 6:21 PM.

Details

Summary

The first patch supported only LMUL=1 types. This patch supports
LMUL!=1.

LMUL is length multiplier that allows multiple vector registers to
be treated as one large register or a fraction of a single vector
register. Supported values for LMUL are 1/8, 1/4, 1/2, 1, 2, 4, and 8.

An LMUL=2 type will be twice as large as an LMUL=1 type. An LMUL=1/2
type will be half the size as an LMUL=1 type.

Type name with "m2" is LMUL=2, "m4" is LMUL=4.
Type name with "mf2" is LMUL=1/2, "mf4" is LMUL=1/4.

For the LMUL!=1 types the user will need to scale __riscv_v_fixed_vlen
by the LMUL before passing to the attribute.

Diff Detail

Event Timeline

craig.topper created this revision.May 18 2023, 6:21 PM
craig.topper requested review of this revision.May 18 2023, 6:21 PM
asb added inline comments.May 19 2023, 7:46 AM
clang/include/clang/Basic/AttrDocs.td
2347–2350

LMULo -> LMUL

aaron.ballman added inline comments.Jun 7 2023, 10:58 AM
clang/include/clang/Basic/AttrDocs.td
2350

Do you have test coverage that demonstrates this?

clang/lib/AST/Type.cpp
2450–2451

FIXME is now stale and can be removed?

clang/lib/Sema/SemaType.cpp
8347–8348

Random thought I didn't think to ask earlier: is it possible for this multiplication to overflow (if so, we should add test coverage to make sure we don't do bad things)?

craig.topper added inline comments.Jun 7 2023, 1:00 PM
clang/lib/Sema/SemaType.cpp
8347–8348

The largest value for -mrvv-vector-bits is 65536 which makes VScale->first 65536/64 == 1024. MinElts and EltSize should be small enough that it won't overflow.

I'm not sure if there's any protection if someone bypasses the driver with -Xclang -mvscale-min= and uses a larger value.

Remove stale FIXME

aaron.ballman accepted this revision.Jun 8 2023, 5:32 AM

LGTM

clang/lib/Sema/SemaType.cpp
8347–8348

The largest value for -mrvv-vector-bits is 65536 which makes VScale->first 65536/64 == 1024. MinElts and EltSize should be small enough that it won't overflow.

Fantastic, thank you!

I'm not sure if there's any protection if someone bypasses the driver with -Xclang -mvscale-min= and uses a larger value.

IMO, using cc1 options is compiler YOLO-mode, so I don't mind if this has no protection.

This revision is now accepted and ready to land.Jun 8 2023, 5:32 AM
This revision was landed with ongoing or failed builds.Jun 8 2023, 9:14 AM
This revision was automatically updated to reflect the committed changes.