[C++] Handle ?: for vectors

Marc Glisse marc.glisse@inria.fr
Wed Oct 24 20:20:00 GMT 2012


On Wed, 24 Oct 2012, Jason Merrill wrote:

> My guess for the reason why OpenCL has the semantics it does is that if you 
> stored a boolean result in a variable earlier and then use it as the ? 
> condition, that would require an extra comparison whereas if it's already a 
> vector of 0 and -1 as expected it can be used directly.

I don't understand how < 0 differs from != 0 for that purpose. In both 
cases, the front-end will produce the extra comparison, and the middle-end 
will need an optimization to detect "truth values" (vectors of -1 and 0) 
and simplify trivial operations on those (<0, !=0, etc).

(at a point, based on Richard's words but apparently not on his 
suggestion, I was tempted to introduce a new boolean vector type, whose 
only values are 0 and -1, but that seems a bit complicated and doesn't 
answer whether x?y:z should mean x<0 or x!=0)

-- 
Marc Glisse



More information about the Gcc-patches mailing list