Fix matrix pre/post increment/decrement (#1987)
This commit is contained in:
Родитель
ebe3536a2a
Коммит
c6cd8c8b55
|
@ -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);
|
||||
}
|
Загрузка…
Ссылка в новой задаче