[OpenCL] allow __builtin_astype(char4, char3)

Is char3 as_char3(char4 x) a valid OpenCL builtin function?

According to the spec, both have 4 bytes, so it seems to be a valid builtin.

Naturally one would want to implement it as

char3 as_char3(char4 x) { return __builtin_astype(x, char3); }

However this does not work since Clang will generate bitcast <4 x i8> to <3 x i8> and this is an invalid llvm instruction.

Do you think Clang should be patched to generate correct llvm instruction for this case?



Hi Sam,

I think it makes sense considering that it’s quite common to use __builtin_astype for implementing OpenCL as_type.



Actually the codegen can generate correct llvm IR for __builtin_astype(char4, char3), but not for __builtin_astype(int, char3) and other types. I will try to fix that.