Skip to content

Commit 6ace567

Browse files
committed
Revert "[HLSL] Vector standard conversions (llvm#71098)"
This reverts commit 5c57fd7. This commit causes crashes in Clang codegen tests.
1 parent 1d03d59 commit 6ace567

24 files changed

+96
-597
lines changed

clang/include/clang/AST/OperationKinds.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,6 @@ CAST_OPERATION(AddressSpaceConversion)
361361
// Convert an integer initializer to an OpenCL sampler.
362362
CAST_OPERATION(IntToOCLSampler)
363363

364-
// Truncate a vector type by dropping elements from the end (HLSL only).
365-
CAST_OPERATION(HLSLVectorTruncation)
366-
367364
//===- Binary Operations -------------------------------------------------===//
368365
// Operators listed in order of precedence.
369366
// Note that additions to this should also update the StmtVisitor class,

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12112,9 +12112,6 @@ def err_hlsl_operator_unsupported : Error<
1211212112
def err_hlsl_param_qualifier_mismatch :
1211312113
Error<"conflicting parameter qualifier %0 on parameter %1">;
1211412114

12115-
def warn_hlsl_impcast_vector_truncation : Warning<
12116-
"implicit conversion truncates vector: %0 to %1">, InGroup<Conversion>;
12117-
1211812115
// Layout randomization diagnostics.
1211912116
def err_non_designated_init_used : Error<
1212012117
"a randomized struct can only be initialized with a designated initializer">;

clang/include/clang/Sema/Overload.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ class Sema;
195195
/// Fixed point type conversions according to N1169.
196196
ICK_Fixed_Point_Conversion,
197197

198-
/// HLSL vector truncation.
199-
ICK_HLSL_Vector_Truncation,
200-
201198
/// The number of conversion kinds
202199
ICK_Num_Conversion_Kinds,
203200
};
@@ -274,12 +271,6 @@ class Sema;
274271
/// pointer-to-member conversion, or boolean conversion.
275272
ImplicitConversionKind Second : 8;
276273

277-
/// Element - Between the second and third conversion a vector or matrix
278-
/// element conversion may occur. If this is not ICK_Identity this
279-
/// conversion is applied element-wise to each element in the vector or
280-
/// matrix.
281-
ImplicitConversionKind Element : 8;
282-
283274
/// Third - The third conversion can be a qualification conversion
284275
/// or a function conversion.
285276
ImplicitConversionKind Third : 8;
@@ -376,8 +367,7 @@ class Sema;
376367
void setAsIdentityConversion();
377368

378369
bool isIdentityConversion() const {
379-
return Second == ICK_Identity && Element == ICK_Identity &&
380-
Third == ICK_Identity;
370+
return Second == ICK_Identity && Third == ICK_Identity;
381371
}
382372

383373
ImplicitConversionRank getRank() const;

clang/lib/AST/Expr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,6 @@ bool CastExpr::CastConsistency() const {
18971897
case CK_FixedPointToIntegral:
18981898
case CK_IntegralToFixedPoint:
18991899
case CK_MatrixCast:
1900-
case CK_HLSLVectorTruncation:
19011900
assert(!getType()->isBooleanType() && "unheralded conversion to bool");
19021901
goto CheckNoBasePath;
19031902

clang/lib/AST/ExprConstant.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13980,7 +13980,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
1398013980
case CK_FixedPointCast:
1398113981
case CK_IntegralToFixedPoint:
1398213982
case CK_MatrixCast:
13983-
case CK_HLSLVectorTruncation:
1398413983
llvm_unreachable("invalid cast kind for integral value");
1398513984

1398613985
case CK_BitCast:
@@ -14819,7 +14818,6 @@ bool ComplexExprEvaluator::VisitCastExpr(const CastExpr *E) {
1481914818
case CK_FixedPointToIntegral:
1482014819
case CK_IntegralToFixedPoint:
1482114820
case CK_MatrixCast:
14822-
case CK_HLSLVectorTruncation:
1482314821
llvm_unreachable("invalid cast kind for complex value");
1482414822

1482514823
case CK_LValueToRValue:

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5180,7 +5180,6 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
51805180
case CK_FixedPointToIntegral:
51815181
case CK_IntegralToFixedPoint:
51825182
case CK_MatrixCast:
5183-
case CK_HLSLVectorTruncation:
51845183
return EmitUnsupportedLValue(E, "unexpected cast lvalue");
51855184

51865185
case CK_Dependent:

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,6 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
933933
case CK_BuiltinFnToFnPtr:
934934
case CK_ZeroToOCLOpaqueType:
935935
case CK_MatrixCast:
936-
case CK_HLSLVectorTruncation:
937936

938937
case CK_IntToOCLSampler:
939938
case CK_FloatingToFixedPoint:
@@ -1458,7 +1457,6 @@ static bool castPreservesZero(const CastExpr *CE) {
14581457
case CK_MatrixCast:
14591458
case CK_NonAtomicToAtomic:
14601459
case CK_AtomicToNonAtomic:
1461-
case CK_HLSLVectorTruncation:
14621460
return true;
14631461

14641462
case CK_BaseToDerivedMemberPointer:

clang/lib/CodeGen/CGExprComplex.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ ComplexPairTy ComplexExprEmitter::EmitCast(CastKind CK, Expr *Op,
564564
case CK_FixedPointToIntegral:
565565
case CK_IntegralToFixedPoint:
566566
case CK_MatrixCast:
567-
case CK_HLSLVectorTruncation:
568567
llvm_unreachable("invalid cast kind for complex value");
569568

570569
case CK_FloatingRealToComplex:

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,6 @@ class ConstExprEmitter :
12251225
case CK_IntegralToFixedPoint:
12261226
case CK_ZeroToOCLOpaqueType:
12271227
case CK_MatrixCast:
1228-
case CK_HLSLVectorTruncation:
12291228
return nullptr;
12301229
}
12311230
llvm_unreachable("Invalid CastKind");

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,12 +2408,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
24082408
CE->getExprLoc());
24092409

24102410
case CK_IntegralCast: {
2411-
if (E->getType()->isExtVectorType() && DestTy->isExtVectorType()) {
2412-
QualType SrcElTy = E->getType()->castAs<VectorType>()->getElementType();
2413-
return Builder.CreateIntCast(Visit(E), ConvertType(DestTy),
2414-
SrcElTy->isSignedIntegerOrEnumerationType(),
2415-
"conv");
2416-
}
24172411
ScalarConversionOpts Opts;
24182412
if (auto *ICE = dyn_cast<ImplicitCastExpr>(CE)) {
24192413
if (!ICE->isPartOfExplicitCast())
@@ -2422,50 +2416,9 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
24222416
return EmitScalarConversion(Visit(E), E->getType(), DestTy,
24232417
CE->getExprLoc(), Opts);
24242418
}
2425-
case CK_IntegralToFloating: {
2426-
if (E->getType()->isVectorType() && DestTy->isVectorType()) {
2427-
// TODO: Support constrained FP intrinsics.
2428-
assert(!Builder.getIsFPConstrained() &&
2429-
"FP Constrained vector casts not supported yet.");
2430-
QualType SrcElTy = E->getType()->castAs<VectorType>()->getElementType();
2431-
if (SrcElTy->isSignedIntegerOrEnumerationType())
2432-
return Builder.CreateSIToFP(Visit(E), ConvertType(DestTy), "conv");
2433-
return Builder.CreateUIToFP(Visit(E), ConvertType(DestTy), "conv");
2434-
}
2435-
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, CE);
2436-
return EmitScalarConversion(Visit(E), E->getType(), DestTy,
2437-
CE->getExprLoc());
2438-
}
2439-
case CK_FloatingToIntegral: {
2440-
if (E->getType()->isVectorType() && DestTy->isVectorType()) {
2441-
// TODO: Support constrained FP intrinsics.
2442-
assert(!Builder.getIsFPConstrained() &&
2443-
"FP Constrained vector casts not supported yet.");
2444-
QualType DstElTy = DestTy->castAs<VectorType>()->getElementType();
2445-
if (DstElTy->isSignedIntegerOrEnumerationType())
2446-
return Builder.CreateFPToSI(Visit(E), ConvertType(DestTy), "conv");
2447-
return Builder.CreateFPToUI(Visit(E), ConvertType(DestTy), "conv");
2448-
}
2449-
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, CE);
2450-
return EmitScalarConversion(Visit(E), E->getType(), DestTy,
2451-
CE->getExprLoc());
2452-
}
2453-
case CK_FloatingCast: {
2454-
if (E->getType()->isVectorType() && DestTy->isVectorType()) {
2455-
// TODO: Support constrained FP intrinsics.
2456-
assert(!Builder.getIsFPConstrained() &&
2457-
"FP Constrained vector casts not supported yet.");
2458-
QualType SrcElTy = E->getType()->castAs<VectorType>()->getElementType();
2459-
QualType DstElTy = DestTy->castAs<VectorType>()->getElementType();
2460-
if (DstElTy->castAs<BuiltinType>()->getKind() <
2461-
SrcElTy->castAs<BuiltinType>()->getKind())
2462-
return Builder.CreateFPTrunc(Visit(E), ConvertType(DestTy), "conv");
2463-
return Builder.CreateFPExt(Visit(E), ConvertType(DestTy), "conv");
2464-
}
2465-
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, CE);
2466-
return EmitScalarConversion(Visit(E), E->getType(), DestTy,
2467-
CE->getExprLoc());
2468-
}
2419+
case CK_IntegralToFloating:
2420+
case CK_FloatingToIntegral:
2421+
case CK_FloatingCast:
24692422
case CK_FixedPointToFloating:
24702423
case CK_FloatingToFixedPoint: {
24712424
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, CE);
@@ -2515,17 +2468,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
25152468
case CK_IntToOCLSampler:
25162469
return CGF.CGM.createOpenCLIntToSamplerConversion(E, CGF);
25172470

2518-
case CK_HLSLVectorTruncation: {
2519-
assert(DestTy->isVectorType() && "Expected dest type to be vector type");
2520-
Value *Vec = Visit(const_cast<Expr *>(E));
2521-
SmallVector<int, 16> Mask;
2522-
unsigned NumElts = DestTy->castAs<VectorType>()->getNumElements();
2523-
for (unsigned I = 0; I != NumElts; ++I)
2524-
Mask.push_back(I);
2525-
2526-
return Builder.CreateShuffleVector(Vec, Mask, "trunc");
2527-
}
2528-
25292471
} // end of switch
25302472

25312473
llvm_unreachable("unknown scalar cast");

clang/lib/Edit/RewriteObjCFoundationAPI.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,10 +1083,6 @@ static bool rewriteToNumericBoxedExpression(const ObjCMessageExpr *Msg,
10831083
case CK_BooleanToSignedIntegral:
10841084
llvm_unreachable("OpenCL-specific cast in Objective-C?");
10851085

1086-
case CK_HLSLVectorTruncation:
1087-
llvm_unreachable("HLSL-specific cast in Objective-C?");
1088-
break;
1089-
10901086
case CK_FloatingToFixedPoint:
10911087
case CK_FixedPointToFloating:
10921088
case CK_FixedPointCast:

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15676,18 +15676,11 @@ static void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
1567615676
if (S.SourceMgr.isInSystemMacro(CC))
1567715677
return;
1567815678
return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_vector_scalar);
15679-
} else if (S.getLangOpts().HLSL &&
15680-
Target->castAs<VectorType>()->getNumElements() <
15681-
Source->castAs<VectorType>()->getNumElements()) {
15682-
// Diagnose vector truncation but don't return. We may also want to
15683-
// diagnose an element conversion.
15684-
DiagnoseImpCast(S, E, T, CC, diag::warn_hlsl_impcast_vector_truncation);
1568515679
}
1568615680

1568715681
// If the vector cast is cast between two vectors of the same size, it is
15688-
// a bitcast, not a conversion, except under HLSL where it is a conversion.
15689-
if (!S.getLangOpts().HLSL &&
15690-
S.Context.getTypeSize(Source) == S.Context.getTypeSize(Target))
15682+
// a bitcast, not a conversion.
15683+
if (S.Context.getTypeSize(Source) == S.Context.getTypeSize(Target))
1569115684
return;
1569215685

1569315686
Source = cast<VectorType>(Source)->getElementType().getTypePtr();

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4762,22 +4762,6 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
47624762
CK_ZeroToOCLOpaqueType,
47634763
From->getValueKind()).get();
47644764
break;
4765-
case ICK_HLSL_Vector_Truncation: {
4766-
// Note: HLSL built-in vectors are ExtVectors. Since this truncates a vector
4767-
// to a smaller vector, this can only operate on arguments where the source
4768-
// and destination types are ExtVectors.
4769-
assert(From->getType()->isExtVectorType() && ToType->isExtVectorType() &&
4770-
"HLSL vector truncation should only apply to ExtVectors");
4771-
auto *FromVec = From->getType()->castAs<VectorType>();
4772-
auto *ToVec = ToType->castAs<VectorType>();
4773-
QualType ElType = FromVec->getElementType();
4774-
QualType TruncTy =
4775-
Context.getExtVectorType(ElType, ToVec->getNumElements());
4776-
From = ImpCastExprToType(From, TruncTy, CK_HLSLVectorTruncation,
4777-
From->getValueKind())
4778-
.get();
4779-
break;
4780-
}
47814765

47824766
case ICK_Lvalue_To_Rvalue:
47834767
case ICK_Array_To_Pointer:
@@ -4790,76 +4774,6 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
47904774
llvm_unreachable("Improper second standard conversion");
47914775
}
47924776

4793-
if (SCS.Element != ICK_Identity) {
4794-
// If SCS.Element is not ICK_Identity the To and From types must be HLSL
4795-
// vectors or matrices.
4796-
4797-
// TODO: Support HLSL matrices.
4798-
assert((!From->getType()->isMatrixType() && !ToType->isMatrixType()) &&
4799-
"Element conversion for matrix types is not implemented yet.");
4800-
assert(From->getType()->isVectorType() && ToType->isVectorType() &&
4801-
"Element conversion is only supported for vector types.");
4802-
assert(From->getType()->getAs<VectorType>()->getNumElements() ==
4803-
ToType->getAs<VectorType>()->getNumElements() &&
4804-
"Element conversion is only supported for vectors with the same "
4805-
"element counts.");
4806-
QualType FromElTy = From->getType()->getAs<VectorType>()->getElementType();
4807-
unsigned NumElts = ToType->getAs<VectorType>()->getNumElements();
4808-
switch (SCS.Element) {
4809-
case ICK_Boolean_Conversion:
4810-
// Perform half-to-boolean conversion via float.
4811-
if (FromElTy->isHalfType()) {
4812-
QualType FPExtType = Context.getExtVectorType(FromElTy, NumElts);
4813-
From = ImpCastExprToType(From, FPExtType, CK_FloatingCast).get();
4814-
FromType = FPExtType;
4815-
}
4816-
4817-
From =
4818-
ImpCastExprToType(From, ToType, ScalarTypeToBooleanCastKind(FromElTy),
4819-
VK_PRValue,
4820-
/*BasePath=*/nullptr, CCK)
4821-
.get();
4822-
break;
4823-
case ICK_Integral_Promotion:
4824-
case ICK_Integral_Conversion:
4825-
if (ToType->isBooleanType()) {
4826-
assert(FromType->castAs<EnumType>()->getDecl()->isFixed() &&
4827-
SCS.Second == ICK_Integral_Promotion &&
4828-
"only enums with fixed underlying type can promote to bool");
4829-
From = ImpCastExprToType(From, ToType, CK_IntegralToBoolean, VK_PRValue,
4830-
/*BasePath=*/nullptr, CCK)
4831-
.get();
4832-
} else {
4833-
From = ImpCastExprToType(From, ToType, CK_IntegralCast, VK_PRValue,
4834-
/*BasePath=*/nullptr, CCK)
4835-
.get();
4836-
}
4837-
break;
4838-
4839-
case ICK_Floating_Promotion:
4840-
case ICK_Floating_Conversion:
4841-
From = ImpCastExprToType(From, ToType, CK_FloatingCast, VK_PRValue,
4842-
/*BasePath=*/nullptr, CCK)
4843-
.get();
4844-
break;
4845-
case ICK_Floating_Integral:
4846-
if (ToType->isRealFloatingType())
4847-
From =
4848-
ImpCastExprToType(From, ToType, CK_IntegralToFloating, VK_PRValue,
4849-
/*BasePath=*/nullptr, CCK)
4850-
.get();
4851-
else
4852-
From =
4853-
ImpCastExprToType(From, ToType, CK_FloatingToIntegral, VK_PRValue,
4854-
/*BasePath=*/nullptr, CCK)
4855-
.get();
4856-
break;
4857-
case ICK_Identity:
4858-
default:
4859-
llvm_unreachable("Improper element standard conversion");
4860-
}
4861-
}
4862-
48634777
switch (SCS.Third) {
48644778
case ICK_Identity:
48654779
// Nothing to do.

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6432,7 +6432,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
64326432
// For HLSL ext vector types we allow list initialization behavior for C++
64336433
// constructor syntax. This is accomplished by converting initialization
64346434
// arguments an InitListExpr late.
6435-
if (S.getLangOpts().HLSL && Args.size() > 1 && DestType->isExtVectorType() &&
6435+
if (S.getLangOpts().HLSL && DestType->isExtVectorType() &&
64366436
(SourceType.isNull() ||
64376437
!Context.hasSameUnqualifiedType(SourceType, DestType))) {
64386438

0 commit comments

Comments
 (0)