[tint] Fold trivial lets in SPIR-V reader

This significantly reduces the amount of let declarations that are
generated when converting SPIR-V to WGSL. The resulting WGSL is much
smaller and more readable, and faster to parse and process.

A few SPIR-V E2E test inputs were changed as they were generating
invalid constant expressions after inlining.

Change-Id: I1bebf37f6c877e0e0e905f83709503d32b441699
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/140040
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/test/tint/ptr_ref/load/global/i32.spvasm.expected.dxc.hlsl b/test/tint/ptr_ref/load/global/i32.spvasm.expected.dxc.hlsl
index 949fd0b..a75ddfa 100644
--- a/test/tint/ptr_ref/load/global/i32.spvasm.expected.dxc.hlsl
+++ b/test/tint/ptr_ref/load/global/i32.spvasm.expected.dxc.hlsl
@@ -1,8 +1,7 @@
 static int I = 0;
 
 void main_1() {
-  const int x_9 = I;
-  const int x_11 = (x_9 + 1);
+  const int x_11 = (I + 1);
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/global/i32.spvasm.expected.fxc.hlsl b/test/tint/ptr_ref/load/global/i32.spvasm.expected.fxc.hlsl
index 949fd0b..a75ddfa 100644
--- a/test/tint/ptr_ref/load/global/i32.spvasm.expected.fxc.hlsl
+++ b/test/tint/ptr_ref/load/global/i32.spvasm.expected.fxc.hlsl
@@ -1,8 +1,7 @@
 static int I = 0;
 
 void main_1() {
-  const int x_9 = I;
-  const int x_11 = (x_9 + 1);
+  const int x_11 = (I + 1);
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/global/i32.spvasm.expected.glsl b/test/tint/ptr_ref/load/global/i32.spvasm.expected.glsl
index 5ce6b58..5a32b52 100644
--- a/test/tint/ptr_ref/load/global/i32.spvasm.expected.glsl
+++ b/test/tint/ptr_ref/load/global/i32.spvasm.expected.glsl
@@ -2,8 +2,7 @@
 
 int I = 0;
 void main_1() {
-  int x_9 = I;
-  int x_11 = (x_9 + 1);
+  int x_11 = (I + 1);
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/global/i32.spvasm.expected.msl b/test/tint/ptr_ref/load/global/i32.spvasm.expected.msl
index b50a51a..418fee2 100644
--- a/test/tint/ptr_ref/load/global/i32.spvasm.expected.msl
+++ b/test/tint/ptr_ref/load/global/i32.spvasm.expected.msl
@@ -6,8 +6,7 @@
 };
 
 void main_1(thread tint_private_vars_struct* const tint_private_vars) {
-  int const x_9 = (*(tint_private_vars)).I;
-  int const x_11 = as_type<int>((as_type<uint>(x_9) + as_type<uint>(1)));
+  int const x_11 = as_type<int>((as_type<uint>((*(tint_private_vars)).I) + as_type<uint>(1)));
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/global/i32.spvasm.expected.wgsl b/test/tint/ptr_ref/load/global/i32.spvasm.expected.wgsl
index f8aef94..0cedff6 100644
--- a/test/tint/ptr_ref/load/global/i32.spvasm.expected.wgsl
+++ b/test/tint/ptr_ref/load/global/i32.spvasm.expected.wgsl
@@ -1,8 +1,7 @@
 var<private> I = 0i;
 
 fn main_1() {
-  let x_9 = I;
-  let x_11 = (x_9 + 1i);
+  let x_11 = (I + 1i);
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.dxc.hlsl b/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.dxc.hlsl
index 4025850..27509c8 100644
--- a/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.dxc.hlsl
+++ b/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.dxc.hlsl
@@ -6,8 +6,7 @@
 
 void main_1() {
   int i = 0;
-  const int x_15 = V.i;
-  i = x_15;
+  i = V.i;
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.fxc.hlsl b/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.fxc.hlsl
index 4025850..27509c8 100644
--- a/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.fxc.hlsl
+++ b/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.fxc.hlsl
@@ -6,8 +6,7 @@
 
 void main_1() {
   int i = 0;
-  const int x_15 = V.i;
-  i = x_15;
+  i = V.i;
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.glsl b/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.glsl
index a735c2b..9029f31 100644
--- a/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.glsl
+++ b/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.glsl
@@ -7,8 +7,7 @@
 S V = S(0);
 void main_1() {
   int i = 0;
-  int x_15 = V.i;
-  i = x_15;
+  i = V.i;
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.msl b/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.msl
index 1f820c4..ded2dd2 100644
--- a/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.msl
+++ b/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.msl
@@ -11,8 +11,7 @@
 
 void main_1(thread tint_private_vars_struct* const tint_private_vars) {
   int i = 0;
-  int const x_15 = (*(tint_private_vars)).V.i;
-  i = x_15;
+  i = (*(tint_private_vars)).V.i;
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.wgsl b/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.wgsl
index 69f3fc1..9dced1e 100644
--- a/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.wgsl
+++ b/test/tint/ptr_ref/load/global/struct_field.spvasm.expected.wgsl
@@ -6,8 +6,7 @@
 
 fn main_1() {
   var i : i32;
-  let x_15 = V.i;
-  i = x_15;
+  i = V.i;
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/local/i32.spvasm.expected.dxc.hlsl b/test/tint/ptr_ref/load/local/i32.spvasm.expected.dxc.hlsl
index e93814c..3f9ee13 100644
--- a/test/tint/ptr_ref/load/local/i32.spvasm.expected.dxc.hlsl
+++ b/test/tint/ptr_ref/load/local/i32.spvasm.expected.dxc.hlsl
@@ -1,8 +1,7 @@
 void main_1() {
   int i = 0;
   i = 123;
-  const int x_10 = i;
-  const int x_12 = (x_10 + 1);
+  const int x_12 = (i + 1);
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/local/i32.spvasm.expected.fxc.hlsl b/test/tint/ptr_ref/load/local/i32.spvasm.expected.fxc.hlsl
index e93814c..3f9ee13 100644
--- a/test/tint/ptr_ref/load/local/i32.spvasm.expected.fxc.hlsl
+++ b/test/tint/ptr_ref/load/local/i32.spvasm.expected.fxc.hlsl
@@ -1,8 +1,7 @@
 void main_1() {
   int i = 0;
   i = 123;
-  const int x_10 = i;
-  const int x_12 = (x_10 + 1);
+  const int x_12 = (i + 1);
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/local/i32.spvasm.expected.glsl b/test/tint/ptr_ref/load/local/i32.spvasm.expected.glsl
index 4c49a4e..5320612 100644
--- a/test/tint/ptr_ref/load/local/i32.spvasm.expected.glsl
+++ b/test/tint/ptr_ref/load/local/i32.spvasm.expected.glsl
@@ -3,8 +3,7 @@
 void main_1() {
   int i = 0;
   i = 123;
-  int x_10 = i;
-  int x_12 = (x_10 + 1);
+  int x_12 = (i + 1);
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/local/i32.spvasm.expected.msl b/test/tint/ptr_ref/load/local/i32.spvasm.expected.msl
index 5e52f4a..6a331b8 100644
--- a/test/tint/ptr_ref/load/local/i32.spvasm.expected.msl
+++ b/test/tint/ptr_ref/load/local/i32.spvasm.expected.msl
@@ -4,8 +4,7 @@
 void main_1() {
   int i = 0;
   i = 123;
-  int const x_10 = i;
-  int const x_12 = as_type<int>((as_type<uint>(x_10) + as_type<uint>(1)));
+  int const x_12 = as_type<int>((as_type<uint>(i) + as_type<uint>(1)));
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/local/i32.spvasm.expected.wgsl b/test/tint/ptr_ref/load/local/i32.spvasm.expected.wgsl
index dd291f6..66c361a 100644
--- a/test/tint/ptr_ref/load/local/i32.spvasm.expected.wgsl
+++ b/test/tint/ptr_ref/load/local/i32.spvasm.expected.wgsl
@@ -1,8 +1,7 @@
 fn main_1() {
   var i = 0i;
   i = 123i;
-  let x_10 = i;
-  let x_12 = (x_10 + 1i);
+  let x_12 = (i + 1i);
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.dxc.hlsl b/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.dxc.hlsl
index 5404bcd..254d4c7 100644
--- a/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.dxc.hlsl
+++ b/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.dxc.hlsl
@@ -5,8 +5,7 @@
 void main_1() {
   int i = 0;
   S V = (S)0;
-  const int x_14 = V.i;
-  i = x_14;
+  i = V.i;
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.fxc.hlsl b/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.fxc.hlsl
index 5404bcd..254d4c7 100644
--- a/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.fxc.hlsl
+++ b/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.fxc.hlsl
@@ -5,8 +5,7 @@
 void main_1() {
   int i = 0;
   S V = (S)0;
-  const int x_14 = V.i;
-  i = x_14;
+  i = V.i;
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.glsl b/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.glsl
index d2dcda2..93114a3 100644
--- a/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.glsl
+++ b/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.glsl
@@ -7,8 +7,7 @@
 void main_1() {
   int i = 0;
   S V = S(0);
-  int x_14 = V.i;
-  i = x_14;
+  i = V.i;
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.msl b/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.msl
index 686dc6e..bd7ea0c 100644
--- a/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.msl
+++ b/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.msl
@@ -8,8 +8,7 @@
 void main_1() {
   int i = 0;
   S V = {};
-  int const x_14 = V.i;
-  i = x_14;
+  i = V.i;
   return;
 }
 
diff --git a/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.wgsl b/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.wgsl
index 9a92214..58337a3 100644
--- a/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.wgsl
+++ b/test/tint/ptr_ref/load/local/struct_field.spvasm.expected.wgsl
@@ -5,8 +5,7 @@
 fn main_1() {
   var i : i32;
   var V : S;
-  let x_14 = V.i;
-  i = x_14;
+  i = V.i;
   return;
 }