tint: Simplify ++/-- handling in transform

Now that we have untyped literals, we can just add `1` rather than
adding either `1u` or `1i`.

Bug: tint:1488
Change-Id: I59512be8fc67b1bf45088478da7c93bed37a69b8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94141
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2022-06-18 14:22:15 +00:00 committed by Dawn LUCI CQ
parent 43dfe9356e
commit c7f7ca3d9e
2 changed files with 11 additions and 17 deletions

View File

@ -174,14 +174,8 @@ void ExpandCompoundAssignment::Run(CloneContext& ctx, const DataMap&, DataMap&)
state.Expand(assign, assign->lhs, ctx.Clone(assign->rhs), assign->op);
} else if (auto* inc_dec = node->As<ast::IncrementDecrementStatement>()) {
// For increment/decrement statements, `i++` becomes `i = i + 1`.
// TODO(jrprice): Simplify this when we have untyped literals.
auto* sem_lhs = ctx.src->Sem().Get(inc_dec->lhs);
const ast::IntLiteralExpression* one =
sem_lhs->Type()->UnwrapRef()->is_signed_integer_scalar()
? ctx.dst->Expr(1_i)->As<ast::IntLiteralExpression>()
: ctx.dst->Expr(1_u)->As<ast::IntLiteralExpression>();
auto op = inc_dec->increment ? ast::BinaryOp::kAdd : ast::BinaryOp::kSubtract;
state.Expand(inc_dec, inc_dec->lhs, one, op);
state.Expand(inc_dec, inc_dec->lhs, ctx.dst->Expr(1_a), op);
}
}
state.Finalize();

View File

@ -473,7 +473,7 @@ fn main() {
auto* expect = R"(
fn main() {
var v : i32;
v = (v + 1i);
v = (v + 1);
}
)";
@ -493,7 +493,7 @@ fn main() {
auto* expect = R"(
fn main() {
var v : u32;
v = (v + 1u);
v = (v + 1);
}
)";
@ -513,7 +513,7 @@ fn main() {
auto* expect = R"(
fn main() {
var v : i32;
v = (v - 1i);
v = (v - 1);
}
)";
@ -533,7 +533,7 @@ fn main() {
auto* expect = R"(
fn main() {
var v : u32;
v = (v - 1u);
v = (v - 1);
}
)";
@ -556,7 +556,7 @@ fn main() {
var v : i32;
let p = &(v);
let tint_symbol = &(*(p));
*(tint_symbol) = (*(tint_symbol) + 1i);
*(tint_symbol) = (*(tint_symbol) + 1);
}
)";
@ -584,7 +584,7 @@ struct S {
fn main() {
var s : S;
s.m = (s.m + 1i);
s.m = (s.m + 1);
}
)";
@ -617,7 +617,7 @@ fn idx() -> i32 {
fn main() {
let tint_symbol = &(a[idx()]);
*(tint_symbol) = (*(tint_symbol) + 1i);
*(tint_symbol) = (*(tint_symbol) + 1);
}
)";
@ -651,7 +651,7 @@ fn idx() -> i32 {
fn main() {
let tint_symbol = &(v);
let tint_symbol_1 = idx();
(*(tint_symbol))[tint_symbol_1] = ((*(tint_symbol))[tint_symbol_1] + 1i);
(*(tint_symbol))[tint_symbol_1] = ((*(tint_symbol))[tint_symbol_1] + 1);
}
)";
@ -671,7 +671,7 @@ fn main() {
auto* expect = R"(
fn main() {
var v : vec4<i32>;
v.y = (v.y + 1i);
v.y = (v.y + 1);
}
)";
@ -727,7 +727,7 @@ fn main() {
continuing {
let tint_symbol = &(a[idx1()]);
let tint_symbol_1 = idx2();
(*(tint_symbol))[tint_symbol_1] = ((*(tint_symbol))[tint_symbol_1] + 1i);
(*(tint_symbol))[tint_symbol_1] = ((*(tint_symbol))[tint_symbol_1] + 1);
}
}
}