tint/uniformity: Move recently added tests

The uniformity tests are (very loosely) grouped into categories, so
move the recently added assignment, compound assignment, and
increment/decrement tests to be with the other statement tests instead
of with the tests for diagnostic quality.

Change-Id: I133da4b83b7faba3e43752d45bcebb822d08625f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123641
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2023-03-13 18:14:56 +00:00 committed by Dawn LUCI CQ
parent 8cb5ed8c2c
commit 69253ee8a5
1 changed files with 249 additions and 249 deletions

View File

@ -7524,6 +7524,255 @@ test:14:11 note: reading from read_write storage buffer 'rw' may result in a non
)");
}
TEST_F(UniformityAnalysisTest, AssignmentEval_LHS_Then_RHS_Pass) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn b(p : ptr<function, i32>) -> i32 {
*p = non_uniform;
return 0;
}
fn a(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
return 0;
}
fn foo() {
var i = 0;
var arr : array<i32, 4>;
arr[a(&i)] = arr[b(&i)];
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, AssignmentEval_LHS_Then_RHS_Fail) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn a(p : ptr<function, i32>) -> i32 {
*p = non_uniform;
return 0;
}
fn b(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
return 0;
}
fn foo() {
var i = 0;
var arr : array<i32, 4>;
arr[a(&i)] = arr[b(&i)];
}
)";
RunTest(src, false);
EXPECT_EQ(error_,
R"(test:11:5 error: 'workgroupBarrier' must only be called from uniform control flow
workgroupBarrier();
^^^^^^^^^^^^^^^^
test:10:3 note: control flow depends on possibly non-uniform value
if (*p == 0) {
^^
test:10:8 note: parameter 'p' of 'b' may be non-uniform
if (*p == 0) {
^
test:19:22 note: possibly non-uniform value passed via pointer here
arr[a(&i)] = arr[b(&i)];
^
test:19:9 note: contents of pointer may become non-uniform after calling 'a'
arr[a(&i)] = arr[b(&i)];
^
)");
}
TEST_F(UniformityAnalysisTest, CompoundAssignmentEval_LHS_Then_RHS_Pass) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn b(p : ptr<function, i32>) -> i32 {
*p = non_uniform;
return 0;
}
fn a(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
return 0;
}
fn foo() {
var i = 0;
var arr : array<i32, 4>;
arr[a(&i)] += arr[b(&i)];
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, CompoundAssignmentEval_LHS_Then_RHS_Fail) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn a(p : ptr<function, i32>) -> i32 {
*p = non_uniform;
return 0;
}
fn b(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
return 0;
}
fn foo() {
var i = 0;
var arr : array<i32, 4>;
arr[a(&i)] += arr[b(&i)];
}
)";
RunTest(src, false);
EXPECT_EQ(error_,
R"(test:11:5 error: 'workgroupBarrier' must only be called from uniform control flow
workgroupBarrier();
^^^^^^^^^^^^^^^^
test:10:3 note: control flow depends on possibly non-uniform value
if (*p == 0) {
^^
test:10:8 note: parameter 'p' of 'b' may be non-uniform
if (*p == 0) {
^
test:19:23 note: possibly non-uniform value passed via pointer here
arr[a(&i)] += arr[b(&i)];
^
test:19:9 note: contents of pointer may become non-uniform after calling 'a'
arr[a(&i)] += arr[b(&i)];
^
)");
}
TEST_F(UniformityAnalysisTest, CompoundAssignmentEval_RHS_Makes_LHS_NonUniform_After_Load) {
// Test that the LHS is loaded from before the RHS makes is evaluated.
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn bar(p : ptr<function, i32>) -> i32 {
*p = non_uniform;
return 0;
}
fn foo() {
var i = 0;
var arr : array<i32, 4>;
i += arr[bar(&i)];
if (i == 0) {
workgroupBarrier();
}
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, CompoundAssignmentEval_RHS_Makes_LHS_Uniform_After_Load) {
// Test that the LHS is loaded from before the RHS makes is evaluated.
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn bar(p : ptr<function, i32>) -> i32 {
*p = 0;
return 0;
}
fn foo() {
var i = non_uniform;
var arr : array<i32, 4>;
i += arr[bar(&i)];
if (i == 0) {
workgroupBarrier();
}
}
)";
RunTest(src, false);
EXPECT_EQ(error_,
R"(test:14:5 error: 'workgroupBarrier' must only be called from uniform control flow
workgroupBarrier();
^^^^^^^^^^^^^^^^
test:13:3 note: control flow depends on possibly non-uniform value
if (i == 0) {
^^
test:10:11 note: reading from read_write storage buffer 'non_uniform' may result in a non-uniform value
var i = non_uniform;
^^^^^^^^^^^
)");
}
TEST_F(UniformityAnalysisTest, CompoundAssignmentEval_LHS_OnlyOnce) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn bar(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
*p = non_uniform;
return 0;
}
fn foo(){
var f : i32 = 0;
var arr : array<i32, 4>;
arr[bar(&f)] += 1;
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, IncDec_LHS_OnlyOnce) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn bar(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
*p = non_uniform;
return 0;
}
fn foo(){
var f : i32 = 0;
var arr : array<i32, 4>;
arr[bar(&f)]++;
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, ShortCircuiting_UniformLHS) {
std::string src = R"(
@group(0) @binding(0) var<storage, read> uniform_global : i32;
@ -8625,254 +8874,5 @@ test:11:7 note: reading from read_write storage buffer 'non_uniform' may result
)");
}
TEST_F(UniformityAnalysisTest, AssignmentEval_LHS_Then_RHS_Pass) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn b(p : ptr<function, i32>) -> i32 {
*p = non_uniform;
return 0;
}
fn a(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
return 0;
}
fn foo() {
var i = 0;
var arr : array<i32, 4>;
arr[a(&i)] = arr[b(&i)];
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, AssignmentEval_LHS_Then_RHS_Fail) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn a(p : ptr<function, i32>) -> i32 {
*p = non_uniform;
return 0;
}
fn b(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
return 0;
}
fn foo() {
var i = 0;
var arr : array<i32, 4>;
arr[a(&i)] = arr[b(&i)];
}
)";
RunTest(src, false);
EXPECT_EQ(error_,
R"(test:11:5 error: 'workgroupBarrier' must only be called from uniform control flow
workgroupBarrier();
^^^^^^^^^^^^^^^^
test:10:3 note: control flow depends on possibly non-uniform value
if (*p == 0) {
^^
test:10:8 note: parameter 'p' of 'b' may be non-uniform
if (*p == 0) {
^
test:19:22 note: possibly non-uniform value passed via pointer here
arr[a(&i)] = arr[b(&i)];
^
test:19:9 note: contents of pointer may become non-uniform after calling 'a'
arr[a(&i)] = arr[b(&i)];
^
)");
}
TEST_F(UniformityAnalysisTest, CompoundAssignmentEval_LHS_Then_RHS_Pass) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn b(p : ptr<function, i32>) -> i32 {
*p = non_uniform;
return 0;
}
fn a(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
return 0;
}
fn foo() {
var i = 0;
var arr : array<i32, 4>;
arr[a(&i)] += arr[b(&i)];
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, CompoundAssignmentEval_LHS_Then_RHS_Fail) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn a(p : ptr<function, i32>) -> i32 {
*p = non_uniform;
return 0;
}
fn b(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
return 0;
}
fn foo() {
var i = 0;
var arr : array<i32, 4>;
arr[a(&i)] += arr[b(&i)];
}
)";
RunTest(src, false);
EXPECT_EQ(error_,
R"(test:11:5 error: 'workgroupBarrier' must only be called from uniform control flow
workgroupBarrier();
^^^^^^^^^^^^^^^^
test:10:3 note: control flow depends on possibly non-uniform value
if (*p == 0) {
^^
test:10:8 note: parameter 'p' of 'b' may be non-uniform
if (*p == 0) {
^
test:19:23 note: possibly non-uniform value passed via pointer here
arr[a(&i)] += arr[b(&i)];
^
test:19:9 note: contents of pointer may become non-uniform after calling 'a'
arr[a(&i)] += arr[b(&i)];
^
)");
}
TEST_F(UniformityAnalysisTest, CompoundAssignmentEval_RHS_Makes_LHS_NonUniform_After_Load) {
// Test that the LHS is loaded from before the RHS makes is evaluated.
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn bar(p : ptr<function, i32>) -> i32 {
*p = non_uniform;
return 0;
}
fn foo() {
var i = 0;
var arr : array<i32, 4>;
i += arr[bar(&i)];
if (i == 0) {
workgroupBarrier();
}
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, CompoundAssignmentEval_RHS_Makes_LHS_Uniform_After_Load) {
// Test that the LHS is loaded from before the RHS makes is evaluated.
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn bar(p : ptr<function, i32>) -> i32 {
*p = 0;
return 0;
}
fn foo() {
var i = non_uniform;
var arr : array<i32, 4>;
i += arr[bar(&i)];
if (i == 0) {
workgroupBarrier();
}
}
)";
RunTest(src, false);
EXPECT_EQ(error_,
R"(test:14:5 error: 'workgroupBarrier' must only be called from uniform control flow
workgroupBarrier();
^^^^^^^^^^^^^^^^
test:13:3 note: control flow depends on possibly non-uniform value
if (i == 0) {
^^
test:10:11 note: reading from read_write storage buffer 'non_uniform' may result in a non-uniform value
var i = non_uniform;
^^^^^^^^^^^
)");
}
TEST_F(UniformityAnalysisTest, CompoundAssignmentEval_LHS_OnlyOnce) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn bar(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
*p = non_uniform;
return 0;
}
fn foo(){
var f : i32 = 0;
var arr : array<i32, 4>;
arr[bar(&f)] += 1;
}
)";
RunTest(src, true);
}
TEST_F(UniformityAnalysisTest, IncDec_LHS_OnlyOnce) {
std::string src = R"(
@group(0) @binding(0) var<storage, read_write> non_uniform : i32;
fn bar(p : ptr<function, i32>) -> i32 {
if (*p == 0) {
workgroupBarrier();
}
*p = non_uniform;
return 0;
}
fn foo(){
var f : i32 = 0;
var arr : array<i32, 4>;
arr[bar(&f)]++;
}
)";
RunTest(src, true);
}
} // namespace
} // namespace tint::resolver