This is an archive of the discontinued LLVM Phabricator instance.

[ExtVectorType] Support conditional select operator for C++.
ClosedPublic

Authored by fhahn on Mar 5 2021, 9:42 AM.

Details

Summary

This patch implements the conditional select operator for
ext_vector_types in C++. It does so by using the same semantics as for
C.

D71463 added support for the conditional select operator for VectorType
in C++. Unfortunately the semantics between ext_vector_type in C are
different to VectorType in C++. Select for ext_vector_type is based on
the MSB of the condition vector, whereas for VectorType it is != 0.

This unfortunately means that the behavior is inconsistent between
ExtVectorType and VectorType, but I think using the C semantics for
ExtVectorType in C++ as well should be less surprising for users.

Diff Detail

Event Timeline

fhahn requested review of this revision.Mar 5 2021, 9:42 AM
fhahn created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2021, 9:42 AM
erichkeane added inline comments.Mar 5 2021, 9:49 AM
clang/lib/Sema/SemaExprCXX.cpp
5951

Why is this change necessary? Doesn't ExtVectorType inherit from VectorType? These should both be calling the same function here.

6012

Oh boy, this is awkward as all heck...

Makes me think we should instead have a templated function Context.getVectorType<VectorType>() or <ExtVectorType>

6144

Again I wonder why the 'if' here is necessary? Shouldn't just removing the 'error' diag in the call take care of this?

fhahn updated this revision to Diff 328815.Mar 6 2021, 1:37 PM

Got rid of the template parameter, greatly simplified the code.

fhahn added inline comments.Mar 6 2021, 1:40 PM
clang/lib/Sema/SemaExprCXX.cpp
5951

It's not really necessary, it turns out the template argument is not really needed and the whole function can be simplified a lot!

6012

That's gone now, it just checks for ExtvectorType now.

6144

It's gone now. I also added a few additional test cases that mix vector_size/ext_vector_type vectors, which should be rejected I think (see mix_vector_types in clang/test/SemaCXX/ext-vector-type-conditional.cpp)

erichkeane accepted this revision.Mar 8 2021, 5:54 AM
This revision is now accepted and ready to land.Mar 8 2021, 5:54 AM
aaron.ballman accepted this revision.Mar 8 2021, 1:00 PM

LGTM!

clang/lib/Sema/SemaExprCXX.cpp
6142–6150
fhahn marked an inline comment as done.Mar 9 2021, 4:52 AM
fhahn added inline comments.
clang/lib/Sema/SemaExprCXX.cpp
6142–6150

I'll fix that before committing, thanks!

This revision was automatically updated to reflect the committed changes.
fhahn marked an inline comment as done.
clang/test/SemaCXX/ext-vector-type-conditional.cpp