Correctly handle comma operator w/matrices (#3921)

The special HLSL matrix codegen didn't handle the comma operator. Since
the operation is simple enough, skip special handling and fallback to
the default behavior

Fixed #3916
This commit is contained in:
Greg Roth 2021-08-31 15:30:56 -06:00 коммит произвёл GitHub
Родитель 7ed55d8ed7
Коммит dd86223362
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 35 добавлений и 7 удалений

Просмотреть файл

@ -204,17 +204,16 @@ public:
if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) {
if (hlsl::IsHLSLMatType(E->getType()) ||
hlsl::IsHLSLMatType(BinOp->getLHS()->getType())) {
if (BinOp->getOpcode() != BO_Assign) {
llvm::Value *LHS = CGF.EmitScalarExpr(BinOp->getLHS());
llvm::Value *RHS = CGF.EmitScalarExpr(BinOp->getRHS());
return CGF.CGM.getHLSLRuntime().EmitHLSLMatrixOperationCall(
CGF, E, ConvertType(E->getType()), { LHS, RHS });
}
else {
if (BinOp->getOpcode() == BO_Assign) {
LValue LHS = CGF.EmitLValue(BinOp->getLHS());
llvm::Value *RHS = CGF.EmitScalarExpr(BinOp->getRHS());
CGF.CGM.getHLSLRuntime().EmitHLSLMatrixStore(CGF, RHS, LHS.getAddress(), BinOp->getLHS()->getType());
return RHS;
} else if (BinOp->getOpcode() != BO_Comma) { // comma handled by standard Visit below
llvm::Value *LHS = CGF.EmitScalarExpr(BinOp->getLHS());
llvm::Value *RHS = CGF.EmitScalarExpr(BinOp->getRHS());
return CGF.CGM.getHLSLRuntime().EmitHLSLMatrixOperationCall(
CGF, E, ConvertType(E->getType()), { LHS, RHS });
}
}
} else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E)) {

Просмотреть файл

@ -0,0 +1,29 @@
// RUN: %dxc -E vecret -T ps_6_0 %s | FileCheck %s
// RUN: %dxc -T lib_6_3 %s | FileCheck %s -check-prefix=CHK_MAT
// verify that the comma operator works with matrix types
// CHECK: dx.op.loadInput
// CHECK-NEXT: dx.op.loadInput
// CHECK-NEXT: dx.op.loadInput
// CHECK-NEXT: dx.op.loadInput
// CHECK-NEXT: dx.op.storeOutput
// CHECK-NEXT: dx.op.storeOutput
// CHECK-NEXT: dx.op.storeOutput
// CHECK-NEXT: dx.op.storeOutput
// CHK_MAT: store %class.matrix.float.2.2
// CHK_MAT: load %class.matrix.float.2.2
// Check where the result IS NOT a matrix type
float4 vecret(float2x2 pmat : M, float4 pvec : V) : SV_Target {
return pmat , pvec;
}
// Check where the result IS a matrix type
export
float2x2 matret(float2x2 pmat : M, float4 pvec : V) {
return pmat;
}