[Hexagon] Make conversions to vector predicate types explicit for builtins
authorKrzysztof Parzyszek <kparzysz@quicinc.com>
Wed, 22 Dec 2021 19:29:36 +0000 (11:29 -0800)
committerKrzysztof Parzyszek <kparzysz@quicinc.com>
Wed, 22 Dec 2021 20:52:24 +0000 (12:52 -0800)
commitdcb3e8083a3229b44e23d5d1c19453f0777f3aa2
tree8720723623f25b6fd6dbc204ccb3eefe6361488e
parent86618e37bded924d0a7a06ef0818bb9b2311532d
[Hexagon] Make conversions to vector predicate types explicit for builtins

HVX does not have load/store instructions for vector predicates (i.e. bool
vectors). Because of that, vector predicates need to be converted to another
type before being stored, and the most convenient representation is an HVX
vector.
As a consequence, in C/C++, source-level builtins that either take or
produce vector predicates take or return regular vectors instead. On the
other hand, the corresponding LLVM intrinsics do have boolean types that,
and so a conversion of the operand or the return value was necessary.
This conversion would happen inside clang's codegen, but was somewhat
fragile.

This patch changes the strategy: a builtin that takes a vector predicate
now really expects a vector predicate. Since such a predicate cannot be
provided via a variable, this builtin must be composed with other builtins
that either convert vector to a predicate (V6_vandvrt) or predicate to a
vector (V6_vandqrt).

For users using builtins defined in hvx_hexagon_protos.h there is no impact:
the conversions were added to that file. Other users will need to insert
- __builtin_HEXAGON_V6_vandvrt[_128B](V, -1) to convert vector V to a
  vector predicate, or
- __builtin_HEXAGON_V6_vandqrt[_128B](Q, -1) to convert vector predicate Q
  to a vector.

Builtins __builtin_HEXAGON_V6_vmaskedstore.* are a temporary exception to
that, but they are deprecated and should not be used anyway. In the future
they will either follow the same rule, or be removed.
clang/include/clang/Basic/BuiltinsHexagonMapCustomDep.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/hvx_hexagon_protos.h
clang/test/CodeGen/builtins-hexagon-v66-128B.c
clang/test/CodeGen/builtins-hexagon-v66.c
clang/test/CodeGen/builtins-hvx128.c
clang/test/CodeGen/builtins-hvx64.c
llvm/include/llvm/IR/IntrinsicsHexagonDep.td