Index: clang/lib/CodeGen/CGExprScalar.cpp =================================================================== --- clang/lib/CodeGen/CGExprScalar.cpp +++ clang/lib/CodeGen/CGExprScalar.cpp @@ -4796,12 +4796,10 @@ // to vec4 if the original type is not vec4, then a shuffle vector to // get a vec3. if (NumElementsSrc != 3 && NumElementsDst == 3) { - if (!CGF.CGM.getCodeGenOpts().PreserveVec3Type) { - auto *Vec4Ty = llvm::FixedVectorType::get( - cast(DstTy)->getElementType(), 4); - Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src, - Vec4Ty); - } + auto *Vec4Ty = llvm::FixedVectorType::get( + cast(DstTy)->getElementType(), 4); + Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src, + Vec4Ty); Src = ConvertVec3AndVec4(Builder, CGF, Src, 3); Src->setName("astype"); Index: clang/test/CodeGenOpenCL/preserve_vec3.cl =================================================================== --- clang/test/CodeGenOpenCL/preserve_vec3.cl +++ clang/test/CodeGenOpenCL/preserve_vec3.cl @@ -1,6 +1,7 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -fpreserve-vec3-type | FileCheck %s typedef char char3 __attribute__((ext_vector_type(3))); +typedef char char8 __attribute__((ext_vector_type(8))); typedef short short3 __attribute__((ext_vector_type(3))); typedef double double2 __attribute__((ext_vector_type(2))); typedef float float3 __attribute__((ext_vector_type(3))); @@ -38,6 +39,15 @@ *b = __builtin_astype(*a, double2); } +void kernel char8_to_short3(global short3 *a, global char8 *b) { + // CHECK-LABEL: spir_kernel void @char8_to_short3 + // CHECK: %[[IN_BC:.*]] = bitcast <8 x i8> addrspace(1)* %b to <4 x i16> addrspace(1)* + // CHECK: %[[LOAD_B:.*]] = load <4 x i16>, <4 x i16> addrspace(1)* %[[IN_BC]] + // CHECK: %[[ASTYPE:.*]] = shufflevector <4 x i16> %[[LOAD_B]], <4 x i16> poison, <3 x i32> + // CHECK: store <3 x i16> %[[ASTYPE]], <3 x i16> addrspace(1)* %a, align 8 + *a = __builtin_astype(*b, short3); +} + void from_char3(char3 a, global int *out) { // CHECK-LABEL: void @from_char3 // CHECK: %[[ASTYPE:.*]] = shufflevector <3 x i8> %a, <3 x i8> poison, <4 x i32> @@ -53,3 +63,19 @@ // CHECK: store <4 x i16> %[[ASTYPE]], <4 x i16> addrspace(1)* %[[OUT_BC]] *out = __builtin_astype(a, long); } + +void scalar_to_char3(int a, global char3 *out) { + // CHECK-LABEL: void @scalar_to_char3 + // CHECK: %[[IN_BC:.*]] = bitcast i32 %a to <4 x i8> + // CHECK: %[[ASTYPE:.*]] = shufflevector <4 x i8> %[[IN_BC]], <4 x i8> poison, <3 x i32> + // CHECK: store <3 x i8> %[[ASTYPE]], <3 x i8> addrspace(1)* %out + *out = __builtin_astype(a, char3); +} + +void scalar_to_short3(long a, global short3 *out) { + // CHECK-LABEL: void @scalar_to_short3 + // CHECK: %[[IN_BC:.*]] = bitcast i64 %a to <4 x i16> + // CHECK: %[[ASTYPE:.*]] = shufflevector <4 x i16> %[[IN_BC]], <4 x i16> poison, <3 x i32> + // CHECK: store <3 x i16> %[[ASTYPE]], <3 x i16> addrspace(1)* %out + *out = __builtin_astype(a, short3); +}