This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] (2/2) Add the tail policy argument to builtins/intrinsics.
ClosedPublic

Authored by HsiangKai on Sep 6 2021, 6:44 AM.

Details

Summary

Add the tail policy argument to Clang builtins. There
are two policies for tail elements. Tail agnostic means users do not
care about the values in the tail elements and tail undisturbed means
the values in the tail elements need to be kept after the operation. In
order to let users control the tail policy, we add an additional
argument at the end of the argument list.

For unmasked operations, we have no maskedoff and the tail policy is
always tail agnostic. If users want to keep tail elements under unmasked
operations, they could use all one mask in the masked operations to do
it. So, we only add the additional argument for masked operations for
most cases. There are exceptions listed below.

In this patch, we do not handle the following cases to reduce the
complexity of the patch. There could be two separate patches for them.

Use dest argument to control tail policy
vmerge.vvm/vmerge.vxm/vmerge.vim (add _t builtins with additional dest
argument)
vfmerge.vfm (add _t builtins with additional dest argument)
vmv.v.v (add _t builtins with additional dest argument)
vmv.v.x (add _t builtins with additional dest argument)
vmv.v.i (add _t builtins with additional dest argument)
vfmv.v.f (add _t builtins with additional dest argument)
vadc.vvm/vadc.vxm/vadc.vim (add _t builtins with additional dest
argument)
vsbc.vvm/vsbc.vxm (add _t builtins with additional dest argument)

Always has tail argument for masked/unmasked intrinsics
Vector Single-Width Integer Multiply-Add Instructions (add _t and _mt
builtins)
Vector Widening Integer Multiply-Add Instructions (add _t and _mt
builtins)
Vector Single-Width Floating-Point Fused Multiply-Add Instructions (add
_t and _mt builtins)
Vector Widening Floating-Point Fused Multiply-Add Instructions (add _t
and _mt builtins)
Vector Reduction Operations (add _t and _mt builtins)
Vector Slideup Instructions (add _t and _mt builtins)
Vector Slidedown Instructions (add _t and _mt builtins)

Discussion: https://github.com/riscv/rvv-intrinsic-doc/pull/101

Diff Detail

Event Timeline

HsiangKai created this revision.Sep 6 2021, 6:44 AM
HsiangKai requested review of this revision.Sep 6 2021, 6:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 6 2021, 6:44 AM

I didn't attach all the test update in this patch. It is too huge to collect them in one patch.

I ever ran check-clang and all tests pass after I updated all the clang test cases.

khchen added inline comments.Sep 23 2021, 12:57 AM
clang/include/clang/Basic/riscv_vector.td
181

Add more comment like:
If HasPolicy, masked operation have tail policy argument in the last position, and append t in function name.
and update the HasVL comment too.

personally, I prefer the naming like HasTailPolicy, HasTail or HasTailOperand.

2198

It seems like we can rewrite vsetvli/vsetvl and vsetvlmax instructions by using the RVVHeader mechanism?
We only need to have one mechanism to dump header code.

clang/test/CodeGen/RISCV/rvv-intrinsics/vadd.c
14

Nit: we don't need to add a space here.

clang/utils/TableGen/RISCVVEmitter.cpp
1180

Nit: update this comment

HsiangKai added inline comments.Sep 23 2021, 2:01 AM
clang/include/clang/Basic/riscv_vector.td
2198

Should we create vsetvli/vsetvlmax builtins? If we should, we may not be able to use RVVHeader for these intrinsics.

HsiangKai updated this revision to Diff 374482.Sep 23 2021, 2:06 AM

Update comments.

khchen accepted this revision.Sep 23 2021, 3:01 AM

LGTM.

clang/include/clang/Basic/riscv_vector.td
2198

oh, you are right. I forget that.
Could you please move class definition in top of this file due to all class centralized there.

This revision is now accepted and ready to land.Sep 23 2021, 3:01 AM
craig.topper added inline comments.Sep 23 2021, 5:41 PM
clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vadd.c
8

Please pre-commit this change to reduce noise

This revision was landed with ongoing or failed builds.Sep 24 2021, 2:11 AM
This revision was automatically updated to reflect the committed changes.