Author: Sven van Haastregt Date: 2021-09-29T09:40:06+01:00 New Revision: 4da744a20ff58c9b3d8df0e2eb9e8b69d9e5cc3d
URL: https://github.com/llvm/llvm-project/commit/4da744a20ff58c9b3d8df0e2eb9e8b69d9e5cc3d DIFF: https://github.com/llvm/llvm-project/commit/4da744a20ff58c9b3d8df0e2eb9e8b69d9e5cc3d.diff LOG: [OpenCL] Fix as_type3 invalid store creation With -fpreserve-vec3-type enabled, a cast was not created when converting from a non-vec3 type to a vec3 type, even though a conversion to vec3 was performed. This resulted in creation of invalid store instructions. Differential Revision: https://reviews.llvm.org/D108470 Added: Modified: clang/lib/CodeGen/CGExprScalar.cpp clang/test/CodeGenOpenCL/preserve_vec3.cl Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 67c581b46eae7..6bef004987828 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -4804,12 +4804,10 @@ Value *ScalarExprEmitter::VisitAsTypeExpr(AsTypeExpr *E) { // 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<llvm::VectorType>(DstTy)->getElementType(), 4); - Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src, - Vec4Ty); - } + auto *Vec4Ty = llvm::FixedVectorType::get( + cast<llvm::VectorType>(DstTy)->getElementType(), 4); + Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src, + Vec4Ty); Src = ConvertVec3AndVec4(Builder, CGF, Src, 3); Src->setName("astype"); diff --git a/clang/test/CodeGenOpenCL/preserve_vec3.cl b/clang/test/CodeGenOpenCL/preserve_vec3.cl index 2237cf1e27e46..3dc703d320eca 100644 --- a/clang/test/CodeGenOpenCL/preserve_vec3.cl +++ b/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 @@ void kernel float3_to_double2(global float3 *a, global double2 *b) { *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> <i32 0, i32 1, i32 2> + // 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> <i32 0, i32 1, i32 2, i32 undef> @@ -53,3 +63,19 @@ void from_short3(short3 a, global long *out) { // 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> <i32 0, i32 1, i32 2> + // 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> <i32 0, i32 1, i32 2> + // CHECK: store <3 x i16> %[[ASTYPE]], <3 x i16> addrspace(1)* %out + *out = __builtin_astype(a, short3); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits