From 51be3420b89f36ce3a9e27306dc0743915e2153b Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 8 Mar 2023 21:13:22 +0000 Subject: [PATCH] tint/writer/glsl: Fix emission of lowest i32 value GLSL has the same behavior as MSL, in that -2147483648 is parsed as a unary minus on '2147483648'. 2147483648 overflows an i32, so this actually gets treated as -0. Change-Id: Ibebd8b78a8840f18c438ed1d3d24dee486a65816 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123202 Reviewed-by: Stephen White Commit-Queue: Ben Clayton Commit-Queue: Ben Clayton Kokoro: Kokoro --- src/tint/writer/glsl/generator_impl.cc | 46 +++++++++++++------ .../glsl/generator_impl_unary_op_test.cc | 12 +++++ test/tint/bug/tint/1083.wgsl.expected.glsl | 2 +- test/tint/bug/tint/1520.spvasm.expected.glsl | 2 +- .../reverseBits/222177.wgsl.expected.glsl | 6 +-- .../reverseBits/4dbd6f.wgsl.expected.glsl | 6 +-- .../reverseBits/7c4269.wgsl.expected.glsl | 6 +-- .../reverseBits/c21bc1.wgsl.expected.glsl | 6 +-- .../div/scalar-scalar/i32.wgsl.expected.glsl | 2 +- .../div/scalar-vec3/i32.wgsl.expected.glsl | 2 +- .../div/vec3-scalar/i32.wgsl.expected.glsl | 2 +- .../div/vec3-vec3/i32.wgsl.expected.glsl | 2 +- .../scalar-scalar/i32.wgsl.expected.glsl | 2 +- .../scalar-vec3/i32.wgsl.expected.glsl | 2 +- .../vec3-scalar/i32.wgsl.expected.glsl | 2 +- .../vec3-vec3/i32.wgsl.expected.glsl | 2 +- .../scalar-scalar/i32.wgsl.expected.glsl | 2 +- .../scalar-vec3/i32.wgsl.expected.glsl | 2 +- .../vec3-scalar/i32.wgsl.expected.glsl | 2 +- .../vec3-vec3/i32.wgsl.expected.glsl | 2 +- .../scalar-scalar/i32.wgsl.expected.glsl | 2 +- .../scalar-vec3/i32.wgsl.expected.glsl | 2 +- .../vec3-scalar/i32.wgsl.expected.glsl | 2 +- .../vec3-vec3/i32.wgsl.expected.glsl | 2 +- .../mod/scalar-scalar/i32.wgsl.expected.glsl | 2 +- .../mod/scalar-vec3/i32.wgsl.expected.glsl | 2 +- .../mod/vec3-scalar/i32.wgsl.expected.glsl | 2 +- .../mod/vec3-vec3/i32.wgsl.expected.glsl | 2 +- .../scalar-scalar/i32.wgsl.expected.glsl | 2 +- .../scalar-vec3/i32.wgsl.expected.glsl | 2 +- .../vec3-scalar/i32.wgsl.expected.glsl | 2 +- .../vec3-vec3/i32.wgsl.expected.glsl | 2 +- .../scalar-scalar/i32.wgsl.expected.glsl | 2 +- .../scalar-vec3/i32.wgsl.expected.glsl | 2 +- .../vec3-scalar/i32.wgsl.expected.glsl | 2 +- .../vec3-vec3/i32.wgsl.expected.glsl | 2 +- .../scalar-scalar/i32.wgsl.expected.glsl | 2 +- .../scalar-vec3/i32.wgsl.expected.glsl | 2 +- .../vec3-scalar/i32.wgsl.expected.glsl | 2 +- .../vec3-vec3/i32.wgsl.expected.glsl | 2 +- .../literals/intmin.wgsl.expected.glsl | 2 +- .../divide_by_zero.wgsl.expected.glsl | 4 +- .../function.wgsl.expected.glsl | 2 +- .../private.wgsl.expected.glsl | 2 +- .../scalar/divide.wgsl.expected.glsl | 2 +- .../scalar/modulo.wgsl.expected.glsl | 2 +- .../vector/divide.wgsl.expected.glsl | 2 +- .../vector/modulo-scalar.wgsl.expected.glsl | 2 +- .../vector/modulo.wgsl.expected.glsl | 2 +- .../workgroup.wgsl.expected.glsl | 2 +- 50 files changed, 100 insertions(+), 72 deletions(-) diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 02c1baca3b..e1d3061484 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -83,8 +84,15 @@ using namespace tint::number_suffixes; // NOLINT +namespace tint::writer::glsl { namespace { +const char kTempNamePrefix[] = "tint_tmp"; + +bool last_is_break(const ast::BlockStatement* stmts) { + return IsAnyOf(stmts->Last()); +} + bool IsRelational(tint::ast::BinaryOp op) { return op == tint::ast::BinaryOp::kEqual || op == tint::ast::BinaryOp::kNotEqual || op == tint::ast::BinaryOp::kLessThan || op == tint::ast::BinaryOp::kGreaterThan || @@ -102,15 +110,15 @@ bool RequiresOESSampleVariables(tint::builtin::BuiltinValue builtin) { } } -} // namespace - -namespace tint::writer::glsl { -namespace { - -const char kTempNamePrefix[] = "tint_tmp"; - -bool last_is_break(const ast::BlockStatement* stmts) { - return IsAnyOf(stmts->Last()); +void PrintI32(utils::StringStream& out, int32_t value) { + // GLSL parses `-2147483648` as a unary minus and `2147483648` as separate tokens, and the + // latter doesn't fit into an (32-bit) `int`. Emit `(-2147483647 - 1)` instead, which ensures + // the expression type is `int`. + if (auto int_min = std::numeric_limits::min(); value == int_min) { + out << "(" << int_min + 1 << " - 1)"; + } else { + out << value; + } } void PrintF32(utils::StringStream& out, float value) { @@ -2367,7 +2375,7 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value return true; }, [&](const type::I32*) { - out << constant->ValueAs(); + PrintI32(out, constant->ValueAs()); return true; }, [&](const type::U32*) { @@ -2483,12 +2491,20 @@ bool GeneratorImpl::EmitLiteral(utils::StringStream& out, const ast::LiteralExpr } return true; }, - [&](const ast::IntLiteralExpression* l) { - out << l->value; - if (l->suffix == ast::IntLiteralExpression::Suffix::kU) { - out << "u"; + [&](const ast::IntLiteralExpression* i) { + switch (i->suffix) { + case ast::IntLiteralExpression::Suffix::kNone: + case ast::IntLiteralExpression::Suffix::kI: { + PrintI32(out, static_cast(i->value)); + return true; + } + case ast::IntLiteralExpression::Suffix::kU: { + out << i->value << "u"; + return true; + } } - return true; + diagnostics_.add_error(diag::System::Writer, "unknown integer literal suffix type"); + return false; }, [&](Default) { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); diff --git a/src/tint/writer/glsl/generator_impl_unary_op_test.cc b/src/tint/writer/glsl/generator_impl_unary_op_test.cc index b7c5fd17d1..27e9d2c1a2 100644 --- a/src/tint/writer/glsl/generator_impl_unary_op_test.cc +++ b/src/tint/writer/glsl/generator_impl_unary_op_test.cc @@ -80,5 +80,17 @@ TEST_F(GlslUnaryOpTest, Negation) { ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error(); EXPECT_EQ(out.str(), "-(expr)"); } + +TEST_F(GlslUnaryOpTest, IntMin) { + auto* op = Expr(i32(std::numeric_limits::min())); + WrapInFunction(op); + + GeneratorImpl& gen = Build(); + + utils::StringStream out; + ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.error(); + EXPECT_EQ(out.str(), "(-2147483647 - 1)"); +} + } // namespace } // namespace tint::writer::glsl diff --git a/test/tint/bug/tint/1083.wgsl.expected.glsl b/test/tint/bug/tint/1083.wgsl.expected.glsl index 28c473ff21..c5d5cd0df9 100644 --- a/test/tint/bug/tint/1083.wgsl.expected.glsl +++ b/test/tint/bug/tint/1083.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es int tint_div(int lhs, int rhs) { - return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs)); + return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs)); } void f() { diff --git a/test/tint/bug/tint/1520.spvasm.expected.glsl b/test/tint/bug/tint/1520.spvasm.expected.glsl index 0ae257902d..f83736dcab 100644 --- a/test/tint/bug/tint/1520.spvasm.expected.glsl +++ b/test/tint/bug/tint/1520.spvasm.expected.glsl @@ -25,7 +25,7 @@ vec4 sk_FragColor = vec4(0.0f, 0.0f, 0.0f, 0.0f); bool sk_Clockwise = false; vec4 vcolor_S0 = vec4(0.0f, 0.0f, 0.0f, 0.0f); ivec4 tint_div(ivec4 lhs, ivec4 rhs) { - return (lhs / mix(rhs, ivec4(1), bvec4(uvec4(equal(rhs, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4(-2147483648))) & uvec4(equal(rhs, ivec4(-1)))))))); + return (lhs / mix(rhs, ivec4(1), bvec4(uvec4(equal(rhs, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4((-2147483647 - 1)))) & uvec4(equal(rhs, ivec4(-1)))))))); } bool test_int_S1_c0_b() { diff --git a/test/tint/builtins/gen/literal/reverseBits/222177.wgsl.expected.glsl b/test/tint/builtins/gen/literal/reverseBits/222177.wgsl.expected.glsl index 36ce45cb1b..02f74584e3 100644 --- a/test/tint/builtins/gen/literal/reverseBits/222177.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/reverseBits/222177.wgsl.expected.glsl @@ -5,7 +5,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_222177() { - ivec2 res = ivec2(-2147483648); + ivec2 res = ivec2((-2147483647 - 1)); prevent_dce.inner = res; } @@ -30,7 +30,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_222177() { - ivec2 res = ivec2(-2147483648); + ivec2 res = ivec2((-2147483647 - 1)); prevent_dce.inner = res; } @@ -49,7 +49,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_222177() { - ivec2 res = ivec2(-2147483648); + ivec2 res = ivec2((-2147483647 - 1)); prevent_dce.inner = res; } diff --git a/test/tint/builtins/gen/literal/reverseBits/4dbd6f.wgsl.expected.glsl b/test/tint/builtins/gen/literal/reverseBits/4dbd6f.wgsl.expected.glsl index 10cf2225f7..97ee386a92 100644 --- a/test/tint/builtins/gen/literal/reverseBits/4dbd6f.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/reverseBits/4dbd6f.wgsl.expected.glsl @@ -5,7 +5,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_4dbd6f() { - ivec4 res = ivec4(-2147483648); + ivec4 res = ivec4((-2147483647 - 1)); prevent_dce.inner = res; } @@ -30,7 +30,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_4dbd6f() { - ivec4 res = ivec4(-2147483648); + ivec4 res = ivec4((-2147483647 - 1)); prevent_dce.inner = res; } @@ -49,7 +49,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_4dbd6f() { - ivec4 res = ivec4(-2147483648); + ivec4 res = ivec4((-2147483647 - 1)); prevent_dce.inner = res; } diff --git a/test/tint/builtins/gen/literal/reverseBits/7c4269.wgsl.expected.glsl b/test/tint/builtins/gen/literal/reverseBits/7c4269.wgsl.expected.glsl index d5229b825a..8343f12fcb 100644 --- a/test/tint/builtins/gen/literal/reverseBits/7c4269.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/reverseBits/7c4269.wgsl.expected.glsl @@ -5,7 +5,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_7c4269() { - int res = -2147483648; + int res = (-2147483647 - 1); prevent_dce.inner = res; } @@ -30,7 +30,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_7c4269() { - int res = -2147483648; + int res = (-2147483647 - 1); prevent_dce.inner = res; } @@ -49,7 +49,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_7c4269() { - int res = -2147483648; + int res = (-2147483647 - 1); prevent_dce.inner = res; } diff --git a/test/tint/builtins/gen/literal/reverseBits/c21bc1.wgsl.expected.glsl b/test/tint/builtins/gen/literal/reverseBits/c21bc1.wgsl.expected.glsl index dab6ac272d..477beef06b 100644 --- a/test/tint/builtins/gen/literal/reverseBits/c21bc1.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/reverseBits/c21bc1.wgsl.expected.glsl @@ -5,7 +5,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_c21bc1() { - ivec3 res = ivec3(-2147483648); + ivec3 res = ivec3((-2147483647 - 1)); prevent_dce.inner = res; } @@ -30,7 +30,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_c21bc1() { - ivec3 res = ivec3(-2147483648); + ivec3 res = ivec3((-2147483647 - 1)); prevent_dce.inner = res; } @@ -49,7 +49,7 @@ layout(binding = 0, std430) buffer prevent_dce_block_ssbo { } prevent_dce; void reverseBits_c21bc1() { - ivec3 res = ivec3(-2147483648); + ivec3 res = ivec3((-2147483647 - 1)); prevent_dce.inner = res; } diff --git a/test/tint/expressions/binary/div/scalar-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div/scalar-scalar/i32.wgsl.expected.glsl index db43bc2b0c..4b0eef2f1a 100644 --- a/test/tint/expressions/binary/div/scalar-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div/scalar-scalar/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es int tint_div(int lhs, int rhs) { - return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs)); + return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs)); } void f() { diff --git a/test/tint/expressions/binary/div/scalar-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div/scalar-vec3/i32.wgsl.expected.glsl index 324ae7bb62..a136f22f51 100644 --- a/test/tint/expressions/binary/div/scalar-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div/scalar-vec3/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_div(int lhs, ivec3 rhs) { ivec3 l = ivec3(lhs); - return (l / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1)))))))); + return (l / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div/vec3-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div/vec3-scalar/i32.wgsl.expected.glsl index 1451a224c5..d2b60b8a45 100644 --- a/test/tint/expressions/binary/div/vec3-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div/vec3-scalar/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_div(ivec3 lhs, int rhs) { ivec3 r = ivec3(rhs); - return (lhs / mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(r, ivec3(-1)))))))); + return (lhs / mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(r, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div/vec3-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div/vec3-vec3/i32.wgsl.expected.glsl index db941fa4bc..ce3f657fa2 100644 --- a/test/tint/expressions/binary/div/vec3-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div/vec3-vec3/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es ivec3 tint_div(ivec3 lhs, ivec3 rhs) { - return (lhs / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1)))))))); + return (lhs / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_constant/scalar-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_constant/scalar-scalar/i32.wgsl.expected.glsl index 5cdd98871e..aac159761f 100644 --- a/test/tint/expressions/binary/div_by_zero/by_constant/scalar-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_constant/scalar-scalar/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es int tint_div(int lhs, int rhs) { - return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs)); + return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs)); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_constant/scalar-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_constant/scalar-vec3/i32.wgsl.expected.glsl index a33eaa70bf..cd04914329 100644 --- a/test/tint/expressions/binary/div_by_zero/by_constant/scalar-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_constant/scalar-vec3/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_div(int lhs, ivec3 rhs) { ivec3 l = ivec3(lhs); - return (l / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1)))))))); + return (l / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_constant/vec3-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_constant/vec3-scalar/i32.wgsl.expected.glsl index 28ba692625..4afe9491fa 100644 --- a/test/tint/expressions/binary/div_by_zero/by_constant/vec3-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_constant/vec3-scalar/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_div(ivec3 lhs, int rhs) { ivec3 r = ivec3(rhs); - return (lhs / mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(r, ivec3(-1)))))))); + return (lhs / mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(r, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_constant/vec3-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_constant/vec3-vec3/i32.wgsl.expected.glsl index 2ea6128504..1e3782678e 100644 --- a/test/tint/expressions/binary/div_by_zero/by_constant/vec3-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_constant/vec3-vec3/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es ivec3 tint_div(ivec3 lhs, ivec3 rhs) { - return (lhs / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1)))))))); + return (lhs / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_expression/scalar-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_expression/scalar-scalar/i32.wgsl.expected.glsl index 9109801818..b4550b4ff0 100644 --- a/test/tint/expressions/binary/div_by_zero/by_expression/scalar-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_expression/scalar-scalar/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es int tint_div(int lhs, int rhs) { - return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs)); + return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs)); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_expression/scalar-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_expression/scalar-vec3/i32.wgsl.expected.glsl index 0a46644c4a..54021cdcb4 100644 --- a/test/tint/expressions/binary/div_by_zero/by_expression/scalar-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_expression/scalar-vec3/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_div(int lhs, ivec3 rhs) { ivec3 l = ivec3(lhs); - return (l / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1)))))))); + return (l / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_expression/vec3-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_expression/vec3-scalar/i32.wgsl.expected.glsl index 4221f2a899..de877e277f 100644 --- a/test/tint/expressions/binary/div_by_zero/by_expression/vec3-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_expression/vec3-scalar/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_div(ivec3 lhs, int rhs) { ivec3 r = ivec3(rhs); - return (lhs / mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(r, ivec3(-1)))))))); + return (lhs / mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(r, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_expression/vec3-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_expression/vec3-vec3/i32.wgsl.expected.glsl index 36f0cc23a1..d6cb57eed5 100644 --- a/test/tint/expressions/binary/div_by_zero/by_expression/vec3-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_expression/vec3-vec3/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es ivec3 tint_div(ivec3 lhs, ivec3 rhs) { - return (lhs / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1)))))))); + return (lhs / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_identifier/scalar-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_identifier/scalar-scalar/i32.wgsl.expected.glsl index 5cdd98871e..aac159761f 100644 --- a/test/tint/expressions/binary/div_by_zero/by_identifier/scalar-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_identifier/scalar-scalar/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es int tint_div(int lhs, int rhs) { - return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs)); + return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs)); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_identifier/scalar-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_identifier/scalar-vec3/i32.wgsl.expected.glsl index a33eaa70bf..cd04914329 100644 --- a/test/tint/expressions/binary/div_by_zero/by_identifier/scalar-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_identifier/scalar-vec3/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_div(int lhs, ivec3 rhs) { ivec3 l = ivec3(lhs); - return (l / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1)))))))); + return (l / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_identifier/vec3-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_identifier/vec3-scalar/i32.wgsl.expected.glsl index 28ba692625..4afe9491fa 100644 --- a/test/tint/expressions/binary/div_by_zero/by_identifier/vec3-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_identifier/vec3-scalar/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_div(ivec3 lhs, int rhs) { ivec3 r = ivec3(rhs); - return (lhs / mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(r, ivec3(-1)))))))); + return (lhs / mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(r, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/div_by_zero/by_identifier/vec3-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/div_by_zero/by_identifier/vec3-vec3/i32.wgsl.expected.glsl index 2ea6128504..1e3782678e 100644 --- a/test/tint/expressions/binary/div_by_zero/by_identifier/vec3-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/div_by_zero/by_identifier/vec3-vec3/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es ivec3 tint_div(ivec3 lhs, ivec3 rhs) { - return (lhs / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1)))))))); + return (lhs / mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1)))))))); } void f() { diff --git a/test/tint/expressions/binary/mod/scalar-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod/scalar-scalar/i32.wgsl.expected.glsl index 47c1572a2b..da05027c2a 100644 --- a/test/tint/expressions/binary/mod/scalar-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod/scalar-scalar/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es int tint_mod(int lhs, int rhs) { - int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs); + int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs); if (((uint((lhs | rhs_or_one)) & 2147483648u) != 0u)) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod/scalar-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod/scalar-vec3/i32.wgsl.expected.glsl index ab6b883925..28b2b1c4bc 100644 --- a/test/tint/expressions/binary/mod/scalar-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod/scalar-vec3/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_mod(int lhs, ivec3 rhs) { ivec3 l = ivec3(lhs); - ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1))))))); + ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1))))))); if (any(notEqual((uvec3((l | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (l - ((l / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod/vec3-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod/vec3-scalar/i32.wgsl.expected.glsl index 987c55453f..1178af2d36 100644 --- a/test/tint/expressions/binary/mod/vec3-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod/vec3-scalar/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_mod(ivec3 lhs, int rhs) { ivec3 r = ivec3(rhs); - ivec3 rhs_or_one = mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(r, ivec3(-1))))))); + ivec3 rhs_or_one = mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(r, ivec3(-1))))))); if (any(notEqual((uvec3((lhs | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod/vec3-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod/vec3-vec3/i32.wgsl.expected.glsl index 1e34296c77..f1c30a0d3b 100644 --- a/test/tint/expressions/binary/mod/vec3-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod/vec3-vec3/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es ivec3 tint_mod(ivec3 lhs, ivec3 rhs) { - ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1))))))); + ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1))))))); if (any(notEqual((uvec3((lhs | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_constant/scalar-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_constant/scalar-scalar/i32.wgsl.expected.glsl index b2f5da8a54..da82cf0672 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_constant/scalar-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_constant/scalar-scalar/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es int tint_mod(int lhs, int rhs) { - int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs); + int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs); if (((uint((lhs | rhs_or_one)) & 2147483648u) != 0u)) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_constant/scalar-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_constant/scalar-vec3/i32.wgsl.expected.glsl index 14f1a4ec32..ef41fb8c54 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_constant/scalar-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_constant/scalar-vec3/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_mod(int lhs, ivec3 rhs) { ivec3 l = ivec3(lhs); - ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1))))))); + ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1))))))); if (any(notEqual((uvec3((l | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (l - ((l / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_constant/vec3-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_constant/vec3-scalar/i32.wgsl.expected.glsl index 579b7559c2..b1ddb82a12 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_constant/vec3-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_constant/vec3-scalar/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_mod(ivec3 lhs, int rhs) { ivec3 r = ivec3(rhs); - ivec3 rhs_or_one = mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(r, ivec3(-1))))))); + ivec3 rhs_or_one = mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(r, ivec3(-1))))))); if (any(notEqual((uvec3((lhs | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_constant/vec3-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_constant/vec3-vec3/i32.wgsl.expected.glsl index c24178a1a0..fcb2b3731d 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_constant/vec3-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_constant/vec3-vec3/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es ivec3 tint_mod(ivec3 lhs, ivec3 rhs) { - ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1))))))); + ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1))))))); if (any(notEqual((uvec3((lhs | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_expression/scalar-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_expression/scalar-scalar/i32.wgsl.expected.glsl index c68ce313ac..1ce033d614 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_expression/scalar-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_expression/scalar-scalar/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es int tint_mod(int lhs, int rhs) { - int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs); + int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs); if (((uint((lhs | rhs_or_one)) & 2147483648u) != 0u)) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_expression/scalar-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_expression/scalar-vec3/i32.wgsl.expected.glsl index 0a57a091fa..b11b632cd7 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_expression/scalar-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_expression/scalar-vec3/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_mod(int lhs, ivec3 rhs) { ivec3 l = ivec3(lhs); - ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1))))))); + ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1))))))); if (any(notEqual((uvec3((l | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (l - ((l / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_expression/vec3-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_expression/vec3-scalar/i32.wgsl.expected.glsl index 1b929ace4e..405f4269d8 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_expression/vec3-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_expression/vec3-scalar/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_mod(ivec3 lhs, int rhs) { ivec3 r = ivec3(rhs); - ivec3 rhs_or_one = mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(r, ivec3(-1))))))); + ivec3 rhs_or_one = mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(r, ivec3(-1))))))); if (any(notEqual((uvec3((lhs | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_expression/vec3-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_expression/vec3-vec3/i32.wgsl.expected.glsl index 533cb4f834..56a740d61f 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_expression/vec3-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_expression/vec3-vec3/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es ivec3 tint_mod(ivec3 lhs, ivec3 rhs) { - ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1))))))); + ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1))))))); if (any(notEqual((uvec3((lhs | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_identifier/scalar-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_identifier/scalar-scalar/i32.wgsl.expected.glsl index b2f5da8a54..da82cf0672 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_identifier/scalar-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_identifier/scalar-scalar/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es int tint_mod(int lhs, int rhs) { - int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs); + int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs); if (((uint((lhs | rhs_or_one)) & 2147483648u) != 0u)) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_identifier/scalar-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_identifier/scalar-vec3/i32.wgsl.expected.glsl index 14f1a4ec32..ef41fb8c54 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_identifier/scalar-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_identifier/scalar-vec3/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_mod(int lhs, ivec3 rhs) { ivec3 l = ivec3(lhs); - ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1))))))); + ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(l, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1))))))); if (any(notEqual((uvec3((l | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (l - ((l / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_identifier/vec3-scalar/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_identifier/vec3-scalar/i32.wgsl.expected.glsl index 579b7559c2..b1ddb82a12 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_identifier/vec3-scalar/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_identifier/vec3-scalar/i32.wgsl.expected.glsl @@ -2,7 +2,7 @@ ivec3 tint_mod(ivec3 lhs, int rhs) { ivec3 r = ivec3(rhs); - ivec3 rhs_or_one = mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(r, ivec3(-1))))))); + ivec3 rhs_or_one = mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(r, ivec3(-1))))))); if (any(notEqual((uvec3((lhs | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/binary/mod_by_zero/by_identifier/vec3-vec3/i32.wgsl.expected.glsl b/test/tint/expressions/binary/mod_by_zero/by_identifier/vec3-vec3/i32.wgsl.expected.glsl index c24178a1a0..fcb2b3731d 100644 --- a/test/tint/expressions/binary/mod_by_zero/by_identifier/vec3-vec3/i32.wgsl.expected.glsl +++ b/test/tint/expressions/binary/mod_by_zero/by_identifier/vec3-vec3/i32.wgsl.expected.glsl @@ -1,7 +1,7 @@ #version 310 es ivec3 tint_mod(ivec3 lhs, ivec3 rhs) { - ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(rhs, ivec3(-1))))))); + ivec3 rhs_or_one = mix(rhs, ivec3(1), bvec3(uvec3(equal(rhs, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3((-2147483647 - 1)))) & uvec3(equal(rhs, ivec3(-1))))))); if (any(notEqual((uvec3((lhs | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/expressions/literals/intmin.wgsl.expected.glsl b/test/tint/expressions/literals/intmin.wgsl.expected.glsl index 410c45d2a7..81faa0ca8b 100644 --- a/test/tint/expressions/literals/intmin.wgsl.expected.glsl +++ b/test/tint/expressions/literals/intmin.wgsl.expected.glsl @@ -5,7 +5,7 @@ void unused_entry_point() { return; } int add_int_min_explicit() { - int a = -2147483648; + int a = (-2147483647 - 1); int b = (a + 1); int c = -2147483647; return c; diff --git a/test/tint/statements/compound_assign/divide_by_zero.wgsl.expected.glsl b/test/tint/statements/compound_assign/divide_by_zero.wgsl.expected.glsl index 4fdb12838f..2bd98b6eec 100644 --- a/test/tint/statements/compound_assign/divide_by_zero.wgsl.expected.glsl +++ b/test/tint/statements/compound_assign/divide_by_zero.wgsl.expected.glsl @@ -12,11 +12,11 @@ void unused_entry_point() { int a = 0; float b = 0.0f; int tint_div(int lhs, int rhs) { - return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs)); + return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs)); } int tint_mod(int lhs, int rhs) { - int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs); + int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs); if (((uint((lhs | rhs_or_one)) & 2147483648u) != 0u)) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/statements/compound_assign/function.wgsl.expected.glsl b/test/tint/statements/compound_assign/function.wgsl.expected.glsl index 5c71b85358..5b8138c7ca 100644 --- a/test/tint/statements/compound_assign/function.wgsl.expected.glsl +++ b/test/tint/statements/compound_assign/function.wgsl.expected.glsl @@ -5,7 +5,7 @@ void unused_entry_point() { return; } int tint_div(int lhs, int rhs) { - return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs)); + return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs)); } void foo() { diff --git a/test/tint/statements/compound_assign/private.wgsl.expected.glsl b/test/tint/statements/compound_assign/private.wgsl.expected.glsl index bbfe95eb20..17a522327a 100644 --- a/test/tint/statements/compound_assign/private.wgsl.expected.glsl +++ b/test/tint/statements/compound_assign/private.wgsl.expected.glsl @@ -8,7 +8,7 @@ int a = 0; vec4 b = vec4(0.0f, 0.0f, 0.0f, 0.0f); mat2 c = mat2(0.0f, 0.0f, 0.0f, 0.0f); int tint_div(int lhs, int rhs) { - return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs)); + return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs)); } void foo() { diff --git a/test/tint/statements/compound_assign/scalar/divide.wgsl.expected.glsl b/test/tint/statements/compound_assign/scalar/divide.wgsl.expected.glsl index 81ef9d0fe9..669b33edb7 100644 --- a/test/tint/statements/compound_assign/scalar/divide.wgsl.expected.glsl +++ b/test/tint/statements/compound_assign/scalar/divide.wgsl.expected.glsl @@ -13,7 +13,7 @@ layout(binding = 0, std430) buffer v_block_ssbo { } v; int tint_div(int lhs, int rhs) { - return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs)); + return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs)); } void foo() { diff --git a/test/tint/statements/compound_assign/scalar/modulo.wgsl.expected.glsl b/test/tint/statements/compound_assign/scalar/modulo.wgsl.expected.glsl index 1ebe67ebf5..863264d11c 100644 --- a/test/tint/statements/compound_assign/scalar/modulo.wgsl.expected.glsl +++ b/test/tint/statements/compound_assign/scalar/modulo.wgsl.expected.glsl @@ -13,7 +13,7 @@ layout(binding = 0, std430) buffer v_block_ssbo { } v; int tint_mod(int lhs, int rhs) { - int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs); + int rhs_or_one = (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs); if (((uint((lhs | rhs_or_one)) & 2147483648u) != 0u)) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/statements/compound_assign/vector/divide.wgsl.expected.glsl b/test/tint/statements/compound_assign/vector/divide.wgsl.expected.glsl index 1c33d31dd4..3eee1a510d 100644 --- a/test/tint/statements/compound_assign/vector/divide.wgsl.expected.glsl +++ b/test/tint/statements/compound_assign/vector/divide.wgsl.expected.glsl @@ -13,7 +13,7 @@ layout(binding = 0, std430) buffer v_block_ssbo { } v; ivec4 tint_div(ivec4 lhs, ivec4 rhs) { - return (lhs / mix(rhs, ivec4(1), bvec4(uvec4(equal(rhs, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4(-2147483648))) & uvec4(equal(rhs, ivec4(-1)))))))); + return (lhs / mix(rhs, ivec4(1), bvec4(uvec4(equal(rhs, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4((-2147483647 - 1)))) & uvec4(equal(rhs, ivec4(-1)))))))); } void foo() { diff --git a/test/tint/statements/compound_assign/vector/modulo-scalar.wgsl.expected.glsl b/test/tint/statements/compound_assign/vector/modulo-scalar.wgsl.expected.glsl index da6ab7210b..8d04681c1e 100644 --- a/test/tint/statements/compound_assign/vector/modulo-scalar.wgsl.expected.glsl +++ b/test/tint/statements/compound_assign/vector/modulo-scalar.wgsl.expected.glsl @@ -14,7 +14,7 @@ layout(binding = 0, std430) buffer v_block_ssbo { ivec4 tint_mod(ivec4 lhs, int rhs) { ivec4 r = ivec4(rhs); - ivec4 rhs_or_one = mix(r, ivec4(1), bvec4(uvec4(equal(r, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4(-2147483648))) & uvec4(equal(r, ivec4(-1))))))); + ivec4 rhs_or_one = mix(r, ivec4(1), bvec4(uvec4(equal(r, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4((-2147483647 - 1)))) & uvec4(equal(r, ivec4(-1))))))); if (any(notEqual((uvec4((lhs | rhs_or_one)) & uvec4(2147483648u)), uvec4(0u)))) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/statements/compound_assign/vector/modulo.wgsl.expected.glsl b/test/tint/statements/compound_assign/vector/modulo.wgsl.expected.glsl index a4bd3e649e..c8745d46fd 100644 --- a/test/tint/statements/compound_assign/vector/modulo.wgsl.expected.glsl +++ b/test/tint/statements/compound_assign/vector/modulo.wgsl.expected.glsl @@ -13,7 +13,7 @@ layout(binding = 0, std430) buffer v_block_ssbo { } v; ivec4 tint_mod(ivec4 lhs, ivec4 rhs) { - ivec4 rhs_or_one = mix(rhs, ivec4(1), bvec4(uvec4(equal(rhs, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4(-2147483648))) & uvec4(equal(rhs, ivec4(-1))))))); + ivec4 rhs_or_one = mix(rhs, ivec4(1), bvec4(uvec4(equal(rhs, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4((-2147483647 - 1)))) & uvec4(equal(rhs, ivec4(-1))))))); if (any(notEqual((uvec4((lhs | rhs_or_one)) & uvec4(2147483648u)), uvec4(0u)))) { return (lhs - ((lhs / rhs_or_one) * rhs_or_one)); } else { diff --git a/test/tint/statements/compound_assign/workgroup.wgsl.expected.glsl b/test/tint/statements/compound_assign/workgroup.wgsl.expected.glsl index 797f37d03b..3d11704983 100644 --- a/test/tint/statements/compound_assign/workgroup.wgsl.expected.glsl +++ b/test/tint/statements/compound_assign/workgroup.wgsl.expected.glsl @@ -8,7 +8,7 @@ shared int a; shared vec4 b; shared mat2 c; int tint_div(int lhs, int rhs) { - return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs)); + return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == (-2147483647 - 1))) & uint((rhs == -1))))) ? 1 : rhs)); } void foo() {