Skip to content

Commit

Permalink
[PowerPC] Include vector bool and pixel when emitting lax warning
Browse files Browse the repository at this point in the history
This patch is to fix some missing lax-vector-conversion warnings including
cases that involve vector bool and vector pixel, also to fix the vector
compatibility check for the warnings.

Differential Revision: https://reviews.llvm.org/D143210
  • Loading branch information
Maryam Moghadas committed Feb 21, 2023
1 parent ce3a1c5 commit 02a71b0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 26 deletions.
1 change: 0 additions & 1 deletion clang/include/clang/Sema/Sema.h
Expand Up @@ -12620,7 +12620,6 @@ class Sema final {
bool areVectorTypesSameSize(QualType srcType, QualType destType);
bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType);
bool isLaxVectorConversion(QualType srcType, QualType destType);
bool areSameVectorElemTypes(QualType srcType, QualType destType);
bool anyAltivecTypes(QualType srcType, QualType destType);

/// type checking declaration initializers (C99 6.7.8)
Expand Down
40 changes: 18 additions & 22 deletions clang/lib/Sema/SemaExpr.cpp
Expand Up @@ -7987,30 +7987,24 @@ bool Sema::anyAltivecTypes(QualType SrcTy, QualType DestTy) {
"expected at least one type to be a vector here");

bool IsSrcTyAltivec =
SrcTy->isVectorType() && (SrcTy->castAs<VectorType>()->getVectorKind() ==
VectorType::AltiVecVector);
SrcTy->isVectorType() && ((SrcTy->castAs<VectorType>()->getVectorKind() ==
VectorType::AltiVecVector) ||
(SrcTy->castAs<VectorType>()->getVectorKind() ==
VectorType::AltiVecBool) ||
(SrcTy->castAs<VectorType>()->getVectorKind() ==
VectorType::AltiVecPixel));

bool IsDestTyAltivec = DestTy->isVectorType() &&
(DestTy->castAs<VectorType>()->getVectorKind() ==
VectorType::AltiVecVector);
((DestTy->castAs<VectorType>()->getVectorKind() ==
VectorType::AltiVecVector) ||
(DestTy->castAs<VectorType>()->getVectorKind() ==
VectorType::AltiVecBool) ||
(DestTy->castAs<VectorType>()->getVectorKind() ==
VectorType::AltiVecPixel));

return (IsSrcTyAltivec || IsDestTyAltivec);
}

// This returns true if both vectors have the same element type.
bool Sema::areSameVectorElemTypes(QualType SrcTy, QualType DestTy) {
assert((DestTy->isVectorType() || SrcTy->isVectorType()) &&
"expected at least one type to be a vector here");

uint64_t SrcLen, DestLen;
QualType SrcEltTy, DestEltTy;
if (!breakDownVectorType(SrcTy, SrcLen, SrcEltTy))
return false;
if (!breakDownVectorType(DestTy, DestLen, DestEltTy))
return false;

return (SrcEltTy == DestEltTy);
}

/// Are the two types lax-compatible vector types? That is, given
/// that one of them is a vector, do they have equal storage sizes,
/// where the storage size is the number of elements times the element
Expand Down Expand Up @@ -9848,7 +9842,7 @@ Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS,
// change, so if we are converting between vector types where
// at least one is an Altivec vector, emit a warning.
if (anyAltivecTypes(RHSType, LHSType) &&
!areSameVectorElemTypes(RHSType, LHSType))
!Context.areCompatibleVectorTypes(RHSType, LHSType))
Diag(RHS.get()->getExprLoc(), diag::warn_deprecated_lax_vec_conv_all)
<< RHSType << LHSType;
Kind = CK_BitCast;
Expand All @@ -9864,7 +9858,9 @@ Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS,
const VectorType *VecType = RHSType->getAs<VectorType>();
if (VecType && VecType->getNumElements() == 1 &&
isLaxVectorConversion(RHSType, LHSType)) {
if (VecType->getVectorKind() == VectorType::AltiVecVector)
if (VecType->getVectorKind() == VectorType::AltiVecVector ||
VecType->getVectorKind() == VectorType::AltiVecBool ||
VecType->getVectorKind() == VectorType::AltiVecPixel)
Diag(RHS.get()->getExprLoc(), diag::warn_deprecated_lax_vec_conv_all)
<< RHSType << LHSType;
ExprResult *VecExpr = &RHS;
Expand Down Expand Up @@ -10813,7 +10809,7 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
ExprResult *OtherExpr = LHSVecType ? &RHS : &LHS;
if (isLaxVectorConversion(OtherType, VecType)) {
if (anyAltivecTypes(RHSType, LHSType) &&
!areSameVectorElemTypes(RHSType, LHSType))
!Context.areCompatibleVectorTypes(RHSType, LHSType))
Diag(Loc, diag::warn_deprecated_lax_vec_conv_all) << RHSType << LHSType;
// If we're allowing lax vector conversions, only the total (data) size
// needs to be the same. For non compound assignment, if one of the types is
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaOverload.cpp
Expand Up @@ -1770,7 +1770,7 @@ static bool IsVectorConversion(Sema &S, QualType FromType, QualType ToType,
!ToType->hasAttr(attr::ArmMveStrictPolymorphism))) {
if (S.isLaxVectorConversion(FromType, ToType) &&
S.anyAltivecTypes(FromType, ToType) &&
!S.areSameVectorElemTypes(FromType, ToType) &&
!S.Context.areCompatibleVectorTypes(FromType, ToType) &&
!InOverloadResolution && !CStyle) {
S.Diag(From->getBeginLoc(), diag::warn_deprecated_lax_vec_conv_all)
<< FromType << ToType;
Expand Down
4 changes: 3 additions & 1 deletion clang/test/CodeGen/SystemZ/zvector.c
@@ -1,4 +1,6 @@
// RUN: %clang_cc1 -triple s390x-linux-gnu -target-cpu z13 -fzvector -emit-llvm -o - -W -Wall -Werror %s | opt -S -passes=mem2reg | FileCheck %s
// RUN: %clang_cc1 -triple s390x-linux-gnu -target-cpu z13 -fzvector \
// RUN: -emit-llvm -o - -W -Wall -Werror -Wno-error=deprecate-lax-vec-conv-all \
// RUN: %s | opt -S -passes=mem2reg | FileCheck %s

volatile vector signed char sc, sc2;
volatile vector unsigned char uc, uc2;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/SystemZ/zvector2.c
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -triple s390x-linux-gnu -target-cpu z14 -fzvector \
// RUN: -O -emit-llvm -o - -W -Wall -Werror %s | FileCheck %s
// RUN: -O -emit-llvm -o - -W -Wall -Werror -Wno-error=deprecate-lax-vec-conv-all %s | FileCheck %s

volatile vector float ff, ff2;
volatile vector bool int bi;
Expand Down

0 comments on commit 02a71b0

Please sign in to comment.