svenvh created this revision. svenvh added reviewers: Anastasia, jaykang10. svenvh added a project: clang. Herald added subscribers: ldrumm, yaxunl. svenvh requested review of this revision. Herald added a subscriber: cfe-commits.
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. Related to D107963 <https://reviews.llvm.org/D107963>, but now for the to-vec3 case. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D108470 Files: clang/lib/CodeGen/CGExprScalar.cpp clang/test/CodeGenOpenCL/preserve_vec3.cl Index: clang/test/CodeGenOpenCL/preserve_vec3.cl =================================================================== --- clang/test/CodeGenOpenCL/preserve_vec3.cl +++ clang/test/CodeGenOpenCL/preserve_vec3.cl @@ -53,3 +53,11 @@ // CHECK: store <4 x i16> %[[ASTYPE]], <4 x i16> addrspace(1)* %[[OUT_BC]] *out = __builtin_astype(a, long); } + +void to_char3(int a, global char3 *out) { + // CHECK-LABEL: void @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); +} 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<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");
Index: clang/test/CodeGenOpenCL/preserve_vec3.cl =================================================================== --- clang/test/CodeGenOpenCL/preserve_vec3.cl +++ clang/test/CodeGenOpenCL/preserve_vec3.cl @@ -53,3 +53,11 @@ // CHECK: store <4 x i16> %[[ASTYPE]], <4 x i16> addrspace(1)* %[[OUT_BC]] *out = __builtin_astype(a, long); } + +void to_char3(int a, global char3 *out) { + // CHECK-LABEL: void @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); +} 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<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");
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits