Fix matrix pre/post increment/decrement (#1987)

This commit is contained in:
Tristan Labelle 2019-03-01 13:22:44 -08:00 коммит произвёл GitHub
Родитель ebe3536a2a
Коммит c6cd8c8b55
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 63 добавлений и 5 удалений

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

@ -1030,7 +1030,9 @@ Value *HLMatrixLowerPass::lowerHLUnaryOperation(Value *MatVal, HLUnaryOpcode Opc
? ConstantFP::get(VecTy->getElementType(), 1)
: ConstantInt::get(VecTy->getElementType(), 1);
Constant *VecOne = ConstantVector::getSplat(VecTy->getNumElements(), ScalarOne);
// BUGBUG: This implementation has incorrect semantics (GitHub #1780)
// CodeGen already emitted the load and following store, our job is only to produce
// the updated value.
if (Opcode == HLUnaryOpcode::PostInc || Opcode == HLUnaryOpcode::PreInc) {
return IsFloat
? Builder.CreateFAdd(LoweredVal, VecOne)

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

@ -218,10 +218,11 @@ public:
}
}
} else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E)) {
if (hlsl::IsHLSLMatType(E->getType())) {
llvm::Value *Oper = CGF.EmitScalarExpr(UnOp->getSubExpr());
// ++/-- operators are handled in EmitScalarPrePostIncDec
if (hlsl::IsHLSLMatType(E->getType()) && !UnOp->isIncrementDecrementOp()) {
llvm::Value *Operand = CGF.EmitScalarExpr(UnOp->getSubExpr());
return CGF.CGM.getHLSLRuntime().EmitHLSLMatrixOperationCall(
CGF, E, Oper->getType(), {Oper});
CGF, E, Operand->getType(), { Operand });
}
}
// HLSL Change Ends

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

@ -1,4 +1,4 @@
// RUN: %dxc /T vs_6_0 /E main > %s | FileCheck %s | XFail GitHub #1780
// RUN: %dxc /T vs_6_0 /E main %s | FileCheck %s
// Check that pre/post increment/decrement operators on
// matrices have the intended semantics for both the original

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

@ -0,0 +1,43 @@
// RUN: %dxc /T vs_6_2 /E main %s | FileCheck %s
// Check that pre/post increment/decrement operators on
// matrices have the intended semantics for both the original
// variable and the returned value, for matrices living in resources.
RWStructuredBuffer<int1x1> buf;
AppendStructuredBuffer<int> results;
void main()
{
// Post-increment
// CHECK: rawBufferLoad
// CHECK: add i32 %{{.*}}, 1
// CHECK: rawBufferStore
// CHECK-NOT: rawBufferLoad
// CHECK: rawBufferStore
results.Append((buf[0]++)._11);
// Post-decrement
// CHECK: rawBufferLoad
// CHECK: add i32 %{{.*}}, -1
// CHECK: rawBufferStore
// CHECK-NOT: rawBufferLoad
// CHECK: rawBufferStore
results.Append((buf[0]--)._11);
// Pre-increment
// CHECK: rawBufferLoad
// CHECK: add i32 %{{.*}}, 1
// CHECK: rawBufferStore
// CHECK: rawBufferLoad
// CHECK: rawBufferStore
results.Append((++buf[0])._11);
// Pre-decrement
// CHECK: rawBufferLoad
// CHECK: add i32 %{{.*}}, -1
// CHECK: rawBufferStore
// CHECK: rawBufferLoad
// CHECK: rawBufferStore
results.Append((--buf[0])._11);
}

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

@ -0,0 +1,12 @@
// RUN: %dxc /T vs_6_0 /E main %s | FileCheck %s
// Check that matrix pre-increment/decrement can be chained.
int2 main() : OUT
{
int1x1 variable = 10;
int1x1 result = --(++(++(++variable)));
// CHECK: call void @dx.op.storeOutput.i32(i32 5, i32 0, i32 0, i8 0, i32 12)
// CHECK: call void @dx.op.storeOutput.i32(i32 5, i32 0, i32 0, i8 1, i32 12)
return int2(variable._11, result._11);
}