From 69253ee8a527594ffc64732b608abbddb6075273 Mon Sep 17 00:00:00 2001 From: James Price Date: Mon, 13 Mar 2023 18:14:56 +0000 Subject: [PATCH] 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 Commit-Queue: James Price Reviewed-by: Ben Clayton --- src/tint/resolver/uniformity_test.cc | 498 +++++++++++++-------------- 1 file changed, 249 insertions(+), 249 deletions(-) diff --git a/src/tint/resolver/uniformity_test.cc b/src/tint/resolver/uniformity_test.cc index fe36da28dc..863df846d1 100644 --- a/src/tint/resolver/uniformity_test.cc +++ b/src/tint/resolver/uniformity_test.cc @@ -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 non_uniform : i32; + +fn b(p : ptr) -> i32 { + *p = non_uniform; + return 0; +} + +fn a(p : ptr) -> i32 { + if (*p == 0) { + workgroupBarrier(); + } + return 0; +} + +fn foo() { + var i = 0; + var arr : array; + 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 non_uniform : i32; + +fn a(p : ptr) -> i32 { + *p = non_uniform; + return 0; +} + +fn b(p : ptr) -> i32 { + if (*p == 0) { + workgroupBarrier(); + } + return 0; +} + +fn foo() { + var i = 0; + var arr : array; + 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 non_uniform : i32; + +fn b(p : ptr) -> i32 { + *p = non_uniform; + return 0; +} + +fn a(p : ptr) -> i32 { + if (*p == 0) { + workgroupBarrier(); + } + return 0; +} + +fn foo() { + var i = 0; + var arr : array; + 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 non_uniform : i32; + +fn a(p : ptr) -> i32 { + *p = non_uniform; + return 0; +} + +fn b(p : ptr) -> i32 { + if (*p == 0) { + workgroupBarrier(); + } + return 0; +} + +fn foo() { + var i = 0; + var arr : array; + 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 non_uniform : i32; + +fn bar(p : ptr) -> i32 { + *p = non_uniform; + return 0; +} + +fn foo() { + var i = 0; + var arr : array; + 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 non_uniform : i32; + +fn bar(p : ptr) -> i32 { + *p = 0; + return 0; +} + +fn foo() { + var i = non_uniform; + var arr : array; + 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 non_uniform : i32; + +fn bar(p : ptr) -> i32 { + if (*p == 0) { + workgroupBarrier(); + } + *p = non_uniform; + return 0; +} + +fn foo(){ + var f : i32 = 0; + var arr : array; + arr[bar(&f)] += 1; +} +)"; + + RunTest(src, true); +} + +TEST_F(UniformityAnalysisTest, IncDec_LHS_OnlyOnce) { + std::string src = R"( +@group(0) @binding(0) var non_uniform : i32; + +fn bar(p : ptr) -> i32 { + if (*p == 0) { + workgroupBarrier(); + } + *p = non_uniform; + return 0; +} + +fn foo(){ + var f : i32 = 0; + var arr : array; + arr[bar(&f)]++; +} +)"; + + RunTest(src, true); +} + TEST_F(UniformityAnalysisTest, ShortCircuiting_UniformLHS) { std::string src = R"( @group(0) @binding(0) var 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 non_uniform : i32; - -fn b(p : ptr) -> i32 { - *p = non_uniform; - return 0; -} - -fn a(p : ptr) -> i32 { - if (*p == 0) { - workgroupBarrier(); - } - return 0; -} - -fn foo() { - var i = 0; - var arr : array; - 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 non_uniform : i32; - -fn a(p : ptr) -> i32 { - *p = non_uniform; - return 0; -} - -fn b(p : ptr) -> i32 { - if (*p == 0) { - workgroupBarrier(); - } - return 0; -} - -fn foo() { - var i = 0; - var arr : array; - 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 non_uniform : i32; - -fn b(p : ptr) -> i32 { - *p = non_uniform; - return 0; -} - -fn a(p : ptr) -> i32 { - if (*p == 0) { - workgroupBarrier(); - } - return 0; -} - -fn foo() { - var i = 0; - var arr : array; - 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 non_uniform : i32; - -fn a(p : ptr) -> i32 { - *p = non_uniform; - return 0; -} - -fn b(p : ptr) -> i32 { - if (*p == 0) { - workgroupBarrier(); - } - return 0; -} - -fn foo() { - var i = 0; - var arr : array; - 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 non_uniform : i32; - -fn bar(p : ptr) -> i32 { - *p = non_uniform; - return 0; -} - -fn foo() { - var i = 0; - var arr : array; - 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 non_uniform : i32; - -fn bar(p : ptr) -> i32 { - *p = 0; - return 0; -} - -fn foo() { - var i = non_uniform; - var arr : array; - 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 non_uniform : i32; - -fn bar(p : ptr) -> i32 { - if (*p == 0) { - workgroupBarrier(); - } - *p = non_uniform; - return 0; -} - -fn foo(){ - var f : i32 = 0; - var arr : array; - arr[bar(&f)] += 1; -} -)"; - - RunTest(src, true); -} - -TEST_F(UniformityAnalysisTest, IncDec_LHS_OnlyOnce) { - std::string src = R"( -@group(0) @binding(0) var non_uniform : i32; - -fn bar(p : ptr) -> i32 { - if (*p == 0) { - workgroupBarrier(); - } - *p = non_uniform; - return 0; -} - -fn foo(){ - var f : i32 = 0; - var arr : array; - arr[bar(&f)]++; -} -)"; - - RunTest(src, true); -} - } // namespace } // namespace tint::resolver