tint: Fix phony assignments in DemoteToHelper

We just need to skip these.

Bug: tint:1723
Change-Id: I311fe0432ecf1f69936eaf08eb57123a6a738175
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/109340
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2022-11-09 18:27:12 +00:00 committed by Dawn LUCI CQ
parent 97519c2cd3
commit 78ae4c243b
2 changed files with 36 additions and 0 deletions

View File

@ -114,6 +114,11 @@ Transform::ApplyResult DemoteToHelper::Apply(const Program* src, const DataMap&,
return;
}
// Skip phony assignments.
if (assign->lhs->Is<ast::PhonyExpression>()) {
return;
}
// Skip writes to invocation-private address spaces.
auto* ref = sem.Get(assign->lhs)->Type()->As<sem::Reference>();
switch (ref->AddressSpace()) {

View File

@ -1096,5 +1096,36 @@ fn foo(@location(0) in : f32, @location(1) coord : vec2<f32>) -> @location(0) i3
EXPECT_EQ(expect, str(got));
}
TEST_F(DemoteToHelperTest, PhonyAssignment) {
auto* src = R"(
@fragment
fn foo(@location(0) in : f32) {
if (in == 0.0) {
discard;
}
_ = in;
}
)";
auto* expect = R"(
var<private> tint_discarded = false;
@fragment
fn foo(@location(0) in : f32) {
if ((in == 0.0)) {
tint_discarded = true;
}
_ = in;
if (tint_discarded) {
discard;
}
}
)";
auto got = Run<DemoteToHelper>(src);
EXPECT_EQ(expect, str(got));
}
} // namespace
} // namespace tint::transform