(Adding Joseph in Cc: because we'll want the same behavior in C
afterwards. Conversation starts here:
http://gcc.gnu.org/ml/gcc-patches/2012-10/msg01665.html )
On Thu, 18 Oct 2012, Marc Glisse wrote:
Clang's webpage says they support ?: for vector types, but my version (3.1)
rejects it, I'll compile a new one to check what they do.
They implement ?: for vectors only in OpenCL mode, and in that mode
implement the OpenCL semantics (<0).
OpenCL can be confusing. x?y:z means (x<0)?y:z, but !x means x==0 and x&&y
seems to mean (x!=0)&(y!=0) (the text is not extremely clear).
On Wed, 17 Oct 2012, Jason Merrill wrote:
On 10/17/2012 11:15 PM, Marc Glisse wrote:
In the middle-end, VEC_COND_EXPR is documented to take a vector of 0 and
-1, and at expansion time, it gives vcond(x<0,y,z) to the target if its
first argument is not a comparison.
I shouldn't have mentioned the <0 in vcond which is rather random: x is
necessarily a vector of -1 and 0 there, so anything like <0, !=0, ==-1 is
equivalent, we just need one because of a currently missing target
interface.
Maybe we should leave the first argument alone and let the middle end mess
with it, then?
VEC_COND_EXPR only accepts a vector of -1 and 0, so we can't just pass
arbitrary input from the front-end. Richard B didn't want to make
VEC_COND_EXPR more general either.
Besides, I believe it is the front-end's responsibility to decide this. If
we don't want to decide on a specific semantic, I think I'd rather sorry()
if a user passes an argument that is not directly a comparison (with a
note explaining that they can write <0 for OpenCL-like behavior) than
have an unspecified behavior.
So between the following:
a) x?y:z means (x<0)?y:z
b) x?y:z means (x!=0)?y:z
c) x?y:z is rejected, only things like (x==t)?y:z are accepted
d) other
is the choice still b) ? That's an easy one, only 2 characters to change
in the patch (assuming the rest is correct) :-)
(well, no, actually, I'd also remove the conversion to a signed type)
--
Marc Glisse
PS: sorry for the slow reply, I was at a meeting.