[PATCH] D71463: Implement VectorType conditional operator GNU extension.

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 13 06:34:56 PST 2019


erichkeane created this revision.
erichkeane added reviewers: eli.friedman, aaron.ballman, echristo, rjmccall.
Herald added a subscriber: Anastasia.
Herald added a project: clang.
erichkeane added a comment.

Sorry in advance for the reviewer choices... Blame got me you all for all touching these things in the early 2010s.  Since then, Richard and I seem to be the only one to have touched these types.


GCC supports the conditional operator on VectorTypes that acts as a
'select' in C++ mode. This patch implements the support. Types are
converted as closely to GCC's behavior as possible, though in a few
places consistency with our existing vector type support was preferred.

Note that this implementation is different from the OpenCL version in a
number of ways, so it unfortunately required a different implementation.

First, the SEMA rules and promotion rules are significantly different.

Secondly, GCC implements COND[i] != 0 ? LHS[i] : RHS[i] (where i is in
the range 0- VectorSize, for each element).  In OpenCL, the condition is
COND[i] < 0 ? LHS[i]: RHS[i].

In the process of implementing this, it was also required to make the
expression COND ? LHS : RHS type dependent if COND is type dependent,
since the type is now dependent on the condition.  For example:

  T ? 1 : 2;

Is not typically type dependent, since the result can be deduced from
the operands.  HOWEVER, if T is a VectorType now, it could change this
to a 'select' (basically a swizzle with a non-constant mask) with the 1
and 2 being promoted to vectors themselves.

While this is a change, it is NOT a standards incompatible change. Based
on my (and D. Gregor's, at the time of writing the code) reading of the
standard, the expression is supposed to be type dependent if ANY
sub-expression is type dependent.


Repository:
  rC Clang

https://reviews.llvm.org/D71463

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGenCXX/vector-conditional.cpp
  clang/test/Sema/vector-gcc-compat.cpp
  clang/test/SemaCXX/vector-conditional.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71463.233791.patch
Type: text/x-patch
Size: 41334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191213/b55ce561/attachment-0001.bin>


More information about the cfe-commits mailing list