Skip to content

Commit f47e7e4

Browse files
committed
[clang][SVE] Add support for bitwise operators on SVE types
This patch implements support for the &, |, ^, and ~ operators on sizeless SVE types. Differential Revision: https://reviews.llvm.org/D121119
1 parent 4b3a27e commit f47e7e4

File tree

10 files changed

+770
-27
lines changed

10 files changed

+770
-27
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11948,7 +11948,8 @@ class Sema final {
1194811948

1194911949
// type checking for sizeless vector binary operators.
1195011950
QualType CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS,
11951-
SourceLocation Loc);
11951+
SourceLocation Loc,
11952+
ArithConvKind OperationKind);
1195211953

1195311954
/// Type checking for matrix binary operators.
1195411955
QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS,

clang/lib/AST/Type.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,8 +1899,14 @@ bool Type::hasAutoForTrailingReturnType() const {
18991899
bool Type::hasIntegerRepresentation() const {
19001900
if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
19011901
return VT->getElementType()->isIntegerType();
1902-
else
1903-
return isIntegerType();
1902+
if (CanonicalType->isVLSTBuiltinType()) {
1903+
const auto *VT = cast<BuiltinType>(CanonicalType);
1904+
return VT->getKind() == BuiltinType::SveBool ||
1905+
(VT->getKind() >= BuiltinType::SveInt8 &&
1906+
VT->getKind() <= BuiltinType::SveUint64);
1907+
}
1908+
1909+
return isIntegerType();
19041910
}
19051911

19061912
/// Determine whether this type is an integral type.

clang/lib/Sema/SemaExpr.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10464,15 +10464,17 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
1046410464
}
1046510465

1046610466
QualType Sema::CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS,
10467-
SourceLocation Loc) {
10467+
SourceLocation Loc,
10468+
ArithConvKind OperationKind) {
1046810469
QualType LHSType = LHS.get()->getType().getUnqualifiedType();
1046910470
QualType RHSType = RHS.get()->getType().getUnqualifiedType();
1047010471

1047110472
const BuiltinType *LHSVecType = LHSType->getAs<BuiltinType>();
1047210473
const BuiltinType *RHSVecType = RHSType->getAs<BuiltinType>();
1047310474

1047410475
unsigned DiagID = diag::err_typecheck_invalid_operands;
10475-
if (LHSVecType->isSVEBool() || RHSVecType->isSVEBool()) {
10476+
if ((OperationKind == ACK_Arithmetic) &&
10477+
(LHSVecType->isSVEBool() || RHSVecType->isSVEBool())) {
1047610478
Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange()
1047710479
<< RHS.get()->getSourceRange();
1047810480
return QualType();
@@ -10600,7 +10602,7 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
1060010602
/*AllowBooleanOperation*/ false,
1060110603
/*ReportInvalid*/ true);
1060210604
if (LHSTy->isVLSTBuiltinType() || RHSTy->isVLSTBuiltinType())
10603-
return CheckSizelessVectorOperands(LHS, RHS, Loc);
10605+
return CheckSizelessVectorOperands(LHS, RHS, Loc, ACK_Arithmetic);
1060410606
if (!IsDiv &&
1060510607
(LHSTy->isConstantMatrixType() || RHSTy->isConstantMatrixType()))
1060610608
return CheckMatrixMultiplyOperands(LHS, RHS, Loc, IsCompAssign);
@@ -10650,7 +10652,7 @@ QualType Sema::CheckRemainderOperands(
1065010652
->getType()
1065110653
->getSveEltType(Context)
1065210654
->hasIntegerRepresentation())
10653-
return CheckSizelessVectorOperands(LHS, RHS, Loc);
10655+
return CheckSizelessVectorOperands(LHS, RHS, Loc, ACK_Arithmetic);
1065410656

1065510657
return InvalidOperands(Loc, LHS, RHS);
1065610658
}
@@ -10964,7 +10966,8 @@ QualType Sema::CheckAdditionOperands(ExprResult &LHS, ExprResult &RHS,
1096410966

1096510967
if (LHS.get()->getType()->isVLSTBuiltinType() ||
1096610968
RHS.get()->getType()->isVLSTBuiltinType()) {
10967-
QualType compType = CheckSizelessVectorOperands(LHS, RHS, Loc);
10969+
QualType compType =
10970+
CheckSizelessVectorOperands(LHS, RHS, Loc, ACK_Arithmetic);
1096810971
if (CompLHSTy)
1096910972
*CompLHSTy = compType;
1097010973
return compType;
@@ -11078,7 +11081,8 @@ QualType Sema::CheckSubtractionOperands(ExprResult &LHS, ExprResult &RHS,
1107811081

1107911082
if (LHS.get()->getType()->isVLSTBuiltinType() ||
1108011083
RHS.get()->getType()->isVLSTBuiltinType()) {
11081-
QualType compType = CheckSizelessVectorOperands(LHS, RHS, Loc);
11084+
QualType compType =
11085+
CheckSizelessVectorOperands(LHS, RHS, Loc, ACK_Arithmetic);
1108211086
if (CompLHSTy)
1108311087
*CompLHSTy = compType;
1108411088
return compType;
@@ -11417,6 +11421,10 @@ QualType Sema::CheckShiftOperands(ExprResult &LHS, ExprResult &RHS,
1141711421
return checkVectorShift(*this, LHS, RHS, Loc, IsCompAssign);
1141811422
}
1141911423

11424+
if (LHS.get()->getType()->isVLSTBuiltinType() ||
11425+
RHS.get()->getType()->isVLSTBuiltinType())
11426+
return InvalidOperands(Loc, LHS, RHS);
11427+
1142011428
// Shifts don't perform usual arithmetic conversions, they just do integer
1142111429
// promotions on each operand. C99 6.5.7p3
1142211430

@@ -12885,6 +12893,14 @@ inline QualType Sema::CheckBitwiseOperands(ExprResult &LHS, ExprResult &RHS,
1288512893
return InvalidOperands(Loc, LHS, RHS);
1288612894
}
1288712895

12896+
if (LHS.get()->getType()->isVLSTBuiltinType() ||
12897+
RHS.get()->getType()->isVLSTBuiltinType()) {
12898+
if (LHS.get()->getType()->hasIntegerRepresentation() &&
12899+
RHS.get()->getType()->hasIntegerRepresentation())
12900+
return CheckSizelessVectorOperands(LHS, RHS, Loc, ACK_BitwiseOp);
12901+
return InvalidOperands(Loc, LHS, RHS);
12902+
}
12903+
1288812904
if (Opc == BO_And)
1288912905
diagnoseLogicalNotOnLHSofCheck(*this, LHS, RHS, Loc, Opc);
1289012906

0 commit comments

Comments
 (0)