This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add intrinsics for vsetvli instruction
ClosedPublic

Authored by craig.topper on Dec 9 2020, 2:35 PM.

Details

Summary

This patch adds two IR intrinsics for vsetvli instruction. One to set the vector length to a user specified value and one to set it to vlmax. The vlmax uses the X0 source register encoding.

Clang builtins will follow in a separate patch

Diff Detail

Event Timeline

craig.topper created this revision.Dec 9 2020, 2:35 PM
craig.topper requested review of this revision.Dec 9 2020, 2:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2020, 2:35 PM
Herald added a subscriber: MaskRay. · View Herald Transcript

Disabling isel if V extension isn't enabled.

NickHung added inline comments.Dec 9 2020, 6:46 PM
llvm/include/llvm/IR/IntrinsicsRISCV.td
76

typo? AVL?

craig.topper added inline comments.Dec 9 2020, 6:55 PM
llvm/include/llvm/IR/IntrinsicsRISCV.td
76

Oops. Thanks. I think my hands are used to typing AVX after years in X86.

xmj added a subscriber: xmj.Dec 9 2020, 7:25 PM
NickHung added inline comments.Dec 9 2020, 10:28 PM
llvm/include/llvm/IR/IntrinsicsRISCV.td
83

vsetvlimax? Why not vsetvlmax defined in rvv intrinsic doc.

craig.topper added inline comments.Dec 9 2020, 11:04 PM
llvm/include/llvm/IR/IntrinsicsRISCV.td
83

Mainly wanted to match the instruction name that it selects. It would also avoid a conflict if a C intrinsic is ever proposed that takes the vtype in a register. The current C intrinsics all have a SEW and LMUL suffix to their name so a "vsetvlmax(size_t vtype)" could be added without a conflict.

frasercrmck added inline comments.Dec 10 2020, 1:30 AM
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
168

This doesn't look tested below

Add tests for zero avl

The default should be ta and mu. The compiler is usually agnostic about the tail of the vector, but usually assumes that masked elements are preserved.

Use tail agnostic.

Rebase on top of the tail agnostic change

craig.topper planned changes to this revision.Dec 16 2020, 10:02 AM

Looks like I uploaded the wrong file when I rebased this. Will fix

Restore the correct diff

This revision is now accepted and ready to land.Dec 16 2020, 11:56 PM
This revision was automatically updated to reflect the committed changes.

The default should be ta and mu. The compiler is usually agnostic about the tail of the vector, but usually assumes that masked elements are preserved.

Hello! Sorry to bother everyone, but I want to know what should one use to set ta/tu/ma/mu if the intrinsic just make ta and mu as default?

The default should be ta and mu. The compiler is usually agnostic about the tail of the vector, but usually assumes that masked elements are preserved.

Hello! Sorry to bother everyone, but I want to know what should one use to set ta/tu/ma/mu if the intrinsic just make ta and mu as default?

ta ma is now the default.

The compiler will try to change it automatically based on the requirements of the intrinsics that use it.

In some regards the intrinsic shouldn’t be thought of as creating a vsetvli instruction directly. It’s an intrinsic to get the VL that a vsetvli would produce for the given AVL, SEW, and LMUL.