Make sure no short circuiting. (#336)
This commit is contained in:
Родитель
338da2aab4
Коммит
1d0da57987
|
@ -3378,8 +3378,15 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0 && RHS: If it is safe, just elide the RHS, and return 0/false.
|
// 0 && RHS: If it is safe, just elide the RHS, and return 0/false.
|
||||||
if (!CGF.ContainsLabel(E->getRHS()))
|
if (!CGF.ContainsLabel(E->getRHS())) {
|
||||||
|
// HLSL Change Begins.
|
||||||
|
if (CGF.getLangOpts().HLSL) {
|
||||||
|
// HLSL does not short circuit.
|
||||||
|
Visit(E->getRHS());
|
||||||
|
}
|
||||||
|
// HLSL Change Ends.
|
||||||
return llvm::Constant::getNullValue(ResTy);
|
return llvm::Constant::getNullValue(ResTy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HLSL Change Begins.
|
// HLSL Change Begins.
|
||||||
|
@ -3476,8 +3483,15 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 || RHS: If it is safe, just elide the RHS, and return 1/true.
|
// 1 || RHS: If it is safe, just elide the RHS, and return 1/true.
|
||||||
if (!CGF.ContainsLabel(E->getRHS()))
|
if (!CGF.ContainsLabel(E->getRHS())) {
|
||||||
|
// HLSL Change Begins.
|
||||||
|
if (CGF.getLangOpts().HLSL) {
|
||||||
|
// HLSL does not short circuit.
|
||||||
|
Visit(E->getRHS());
|
||||||
|
}
|
||||||
|
// HLSL Change Ends.
|
||||||
return llvm::ConstantInt::get(ResTy, 1);
|
return llvm::ConstantInt::get(ResTy, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HLSL Change Begins.
|
// HLSL Change Begins.
|
||||||
|
|
|
@ -568,6 +568,12 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S,
|
||||||
if (!ContainsLabel(Skipped)) {
|
if (!ContainsLabel(Skipped)) {
|
||||||
if (CondConstant)
|
if (CondConstant)
|
||||||
incrementProfileCounter(&S);
|
incrementProfileCounter(&S);
|
||||||
|
// HLSL Change Begin.
|
||||||
|
if (getLangOpts().HLSL) {
|
||||||
|
// Emit Cond to make sure not short circuiting.
|
||||||
|
EmitScalarExpr(S.getCond());
|
||||||
|
}
|
||||||
|
// HLSL Change End.
|
||||||
if (Executed) {
|
if (Executed) {
|
||||||
RunCleanupsScope ExecutedScope(*this);
|
RunCleanupsScope ExecutedScope(*this);
|
||||||
EmitStmt(Executed);
|
EmitStmt(Executed);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
|
||||||
|
|
||||||
|
// inc(color) will add 1 to color.
|
||||||
|
// Make sure result is add 5.2.
|
||||||
|
// CHECK: 0x4014CCCCC0000000
|
||||||
|
|
||||||
|
bool inc(inout float4 v) { v++; return true; }
|
||||||
|
|
||||||
|
float4 main(int val: A, float4 color: COLOR) : SV_TARGET {
|
||||||
|
if (false && inc(color)) return color;
|
||||||
|
|
||||||
|
return color + 4.2;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
|
||||||
|
|
||||||
|
// inc(color) will add 1 to color.
|
||||||
|
// Make sure result is add 1.
|
||||||
|
//CHECK: 1.0
|
||||||
|
|
||||||
|
bool inc(inout float4 v) { v++; return true; }
|
||||||
|
|
||||||
|
float4 main(int val: A, float4 color: COLOR) : SV_TARGET {
|
||||||
|
if (true && inc(color)) return color;
|
||||||
|
|
||||||
|
return color + 4.2;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
|
||||||
|
|
||||||
|
// inc(color) will add 1 to color.
|
||||||
|
// Make sure result is add 5.2.
|
||||||
|
// CHECK: 0x4014CCCCC0000000
|
||||||
|
|
||||||
|
bool inc(inout float4 v) { v++; return false; }
|
||||||
|
|
||||||
|
float4 main(int val: A, float4 color: COLOR) : SV_TARGET {
|
||||||
|
if (false || inc(color)) return color;
|
||||||
|
|
||||||
|
return color + 4.2;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
|
||||||
|
|
||||||
|
// inc(color) will add 1 to color.
|
||||||
|
// Make sure result is add 1.
|
||||||
|
//CHECK: 1.0
|
||||||
|
|
||||||
|
bool inc(inout float4 v) { v++; return true; }
|
||||||
|
|
||||||
|
float4 main(int val: A, float4 color: COLOR) : SV_TARGET {
|
||||||
|
if (true || inc(color)) return color;
|
||||||
|
|
||||||
|
return color + 4.2;
|
||||||
|
}
|
||||||
|
|
|
@ -606,6 +606,10 @@ public:
|
||||||
TEST_METHOD(CodeGenShare_Mem2)
|
TEST_METHOD(CodeGenShare_Mem2)
|
||||||
TEST_METHOD(CodeGenShare_Mem2Dim)
|
TEST_METHOD(CodeGenShare_Mem2Dim)
|
||||||
TEST_METHOD(CodeGenShift)
|
TEST_METHOD(CodeGenShift)
|
||||||
|
TEST_METHOD(CodeGenShortCircuiting0)
|
||||||
|
TEST_METHOD(CodeGenShortCircuiting1)
|
||||||
|
TEST_METHOD(CodeGenShortCircuiting2)
|
||||||
|
TEST_METHOD(CodeGenShortCircuiting3)
|
||||||
TEST_METHOD(CodeGenSimpleDS1)
|
TEST_METHOD(CodeGenSimpleDS1)
|
||||||
TEST_METHOD(CodeGenSimpleGS1)
|
TEST_METHOD(CodeGenSimpleGS1)
|
||||||
TEST_METHOD(CodeGenSimpleGS2)
|
TEST_METHOD(CodeGenSimpleGS2)
|
||||||
|
@ -3186,6 +3190,22 @@ TEST_F(CompilerTest, CodeGenShift) {
|
||||||
CodeGenTestCheck(L"..\\CodeGenHLSL\\shift.hlsl");
|
CodeGenTestCheck(L"..\\CodeGenHLSL\\shift.hlsl");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CompilerTest, CodeGenShortCircuiting0) {
|
||||||
|
CodeGenTestCheck(L"..\\CodeGenHLSL\\short_circuiting0.hlsl");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CompilerTest, CodeGenShortCircuiting1) {
|
||||||
|
CodeGenTestCheck(L"..\\CodeGenHLSL\\short_circuiting1.hlsl");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CompilerTest, CodeGenShortCircuiting2) {
|
||||||
|
CodeGenTestCheck(L"..\\CodeGenHLSL\\short_circuiting2.hlsl");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CompilerTest, CodeGenShortCircuiting3) {
|
||||||
|
CodeGenTestCheck(L"..\\CodeGenHLSL\\short_circuiting3.hlsl");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(CompilerTest, CodeGenSimpleDS1) {
|
TEST_F(CompilerTest, CodeGenSimpleDS1) {
|
||||||
CodeGenTestCheck(L"..\\CodeGenHLSL\\SimpleDS1.hlsl");
|
CodeGenTestCheck(L"..\\CodeGenHLSL\\SimpleDS1.hlsl");
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче