Re-allow dynamic indexing of 'let' arrays and matrices

Spec change: https://github.com/gpuweb/gpuweb/pull/2427
Reverses: tint:867

This reverts and fixes commits:
 b6fdcc54df6e012578e69550788e2b4b2b611c32
 10442eff7db4271d53eed553795e655068488276

Added a bunch of end-to-end tests.

Fixed: tint:1352
Change-Id: I34968243bbec1cab838c8ba50a6f027146bbfd06
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/75401
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/docs/origin-trial-changes.md b/docs/origin-trial-changes.md
index c4a3f1a..64c5a3e 100644
--- a/docs/origin-trial-changes.md
+++ b/docs/origin-trial-changes.md
@@ -13,6 +13,7 @@
 
 * Vector and matrix element type can now be inferred from constructor argument types. [tint:1334](https://crbug.com/tint/1334)
 * Added builtins `degrees()` and `radians()` for converting between degrees and radians. [tint:1329](https://crbug.com/tint/1329)
+* `let` arrays and matrices can now be dynamically indexed. [tint:1352](https://crbug.com/tint/1352)
 
 ## Changes for M98
 
diff --git a/src/BUILD.gn b/src/BUILD.gn
index 1003f27..f517b74 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -483,6 +483,8 @@
     "transform/transform.h",
     "transform/unshadow.cc",
     "transform/unshadow.h",
+    "transform/var_for_dynamic_index.cc",
+    "transform/var_for_dynamic_index.h",
     "transform/vectorize_scalar_matrix_constructors.cc",
     "transform/vectorize_scalar_matrix_constructors.h",
     "transform/vertex_pulling.cc",
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4bea019..9399b6b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -350,6 +350,8 @@
   transform/unshadow.h
   transform/vectorize_scalar_matrix_constructors.cc
   transform/vectorize_scalar_matrix_constructors.h
+  transform/var_for_dynamic_index.cc
+  transform/var_for_dynamic_index.h
   transform/vertex_pulling.cc
   transform/vertex_pulling.h
   transform/wrap_arrays_in_structs.cc
@@ -987,6 +989,7 @@
       transform/single_entry_point_test.cc
       transform/test_helper.h
       transform/unshadow_test.cc
+      transform/var_for_dynamic_index_test.cc
       transform/vectorize_scalar_matrix_constructors_test.cc
       transform/vertex_pulling_test.cc
       transform/wrap_arrays_in_structs_test.cc
diff --git a/src/reader/spirv/function_composite_test.cc b/src/reader/spirv/function_composite_test.cc
index d25846f..cca7ceb 100644
--- a/src/reader/spirv/function_composite_test.cc
+++ b/src/reader/spirv/function_composite_test.cc
@@ -45,6 +45,7 @@
 
   %uint_10 = OpConstant %uint 10
   %uint_20 = OpConstant %uint 20
+  %uint_1 = OpConstant %uint 1
   %uint_3 = OpConstant %uint 3
   %uint_4 = OpConstant %uint 4
   %uint_5 = OpConstant %uint 5
@@ -220,8 +221,9 @@
   ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
   auto fe = p->function_emitter(100);
   EXPECT_FALSE(fe.EmitBody());
-  EXPECT_THAT(p->error(), Eq("OpCompositeExtract %1 index value 900 is out of "
-                             "bounds for vector of 2 elements"));
+  EXPECT_EQ(p->error(),
+            "OpCompositeExtract %1 index value 900 is out of bounds for vector "
+            "of 2 elements");
 }
 
 TEST_F(SpvParserTest_CompositeExtract, Matrix) {
@@ -261,8 +263,9 @@
   ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
   auto fe = p->function_emitter(100);
   EXPECT_FALSE(fe.EmitBody()) << p->error();
-  EXPECT_THAT(p->error(), Eq("OpCompositeExtract %2 index value 3 is out of "
-                             "bounds for matrix of 3 elements"));
+  EXPECT_EQ(p->error(),
+            "OpCompositeExtract %2 index value 3 is out of bounds for matrix "
+            "of 3 elements");
 }
 
 TEST_F(SpvParserTest_CompositeExtract, Matrix_Vector) {
@@ -411,8 +414,9 @@
   ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
   auto fe = p->function_emitter(100);
   EXPECT_FALSE(fe.EmitBody());
-  EXPECT_THAT(p->error(), Eq("OpCompositeExtract %2 index value 40 is out of "
-                             "bounds for structure %26 having 3 members"));
+  EXPECT_EQ(p->error(),
+            "OpCompositeExtract %2 index value 40 is out of bounds for "
+            "structure %27 having 3 members");
 }
 
 TEST_F(SpvParserTest_CompositeExtract, Struct_Array_Matrix_Vector) {
@@ -475,8 +479,9 @@
   ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
   auto fe = p->function_emitter(100);
   EXPECT_FALSE(fe.EmitBody());
-  EXPECT_THAT(p->error(), Eq("OpCompositeInsert %1 index value 900 is out of "
-                             "bounds for vector of 2 elements"));
+  EXPECT_EQ(p->error(),
+            "OpCompositeInsert %1 index value 900 is out of bounds for vector "
+            "of 2 elements");
 }
 
 TEST_F(SpvParserTest_CompositeInsert, Matrix) {
@@ -519,8 +524,9 @@
   ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
   auto fe = p->function_emitter(100);
   EXPECT_FALSE(fe.EmitBody()) << p->error();
-  EXPECT_THAT(p->error(), Eq("OpCompositeInsert %2 index value 3 is out of "
-                             "bounds for matrix of 3 elements"));
+  EXPECT_EQ(p->error(),
+            "OpCompositeInsert %2 index value 3 is out of bounds for matrix of "
+            "3 elements");
 }
 
 TEST_F(SpvParserTest_CompositeInsert, Matrix_Vector) {
@@ -611,8 +617,8 @@
   EXPECT_TRUE(fe.EmitBody()) << p->error();
   auto ast_body = fe.ast_body();
   auto body_str = test::ToString(p->program(), ast_body);
-  EXPECT_THAT(body_str, HasSubstr(R"(var x_35 : S;
-let x_1 : S = x_35;
+  EXPECT_THAT(body_str, HasSubstr(R"(var x_36 : S;
+let x_1 : S = x_36;
 var x_2_1 : S = x_1;
 x_2_1.field2 = 30;
 let x_2 : S = x_2_1;
@@ -691,8 +697,9 @@
   ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
   auto fe = p->function_emitter(100);
   EXPECT_FALSE(fe.EmitBody());
-  EXPECT_THAT(p->error(), Eq("OpCompositeInsert %2 index value 40 is out of "
-                             "bounds for structure %26 having 3 members"));
+  EXPECT_EQ(p->error(),
+            "OpCompositeInsert %2 index value 40 is out of bounds for "
+            "structure %27 having 3 members");
 }
 
 TEST_F(SpvParserTest_CompositeInsert, Struct_Array_Matrix_Vector) {
@@ -715,8 +722,8 @@
   EXPECT_TRUE(fe.EmitBody()) << p->error();
   auto ast_body = fe.ast_body();
   auto body_str = test::ToString(p->program(), ast_body);
-  EXPECT_THAT(body_str, HasSubstr(R"(var x_37 : S_1;
-let x_1 : S_1 = x_37;
+  EXPECT_THAT(body_str, HasSubstr(R"(var x_38 : S_1;
+let x_1 : S_1 = x_38;
 var x_2_1 : S_1 = x_1;
 x_2_1.field1[2u][0u].y = 70.0;
 let x_2 : S_1 = x_2_1;
@@ -901,7 +908,7 @@
      %100 = OpFunction %void None %voidfn
      %entry = OpLabel
      %1 = OpCopyObject %v2uint %v2uint_3_4
-     %2 = OpCopyObject %uint %uint_3
+     %2 = OpCopyObject %uint %uint_1
      %10 = OpVectorExtractDynamic %uint %1 %2
      OpReturn
      OpFunctionEnd
diff --git a/src/resolver/array_accessor_test.cc b/src/resolver/array_accessor_test.cc
index 9edd685..2698e2b 100644
--- a/src/resolver/array_accessor_test.cc
+++ b/src/resolver/array_accessor_test.cc
@@ -59,9 +59,8 @@
   auto* acc = IndexAccessor("my_const", Expr(Source{{12, 34}}, idx));
   WrapInFunction(Decl(idx), acc);
 
-  EXPECT_FALSE(r()->Resolve());
-  EXPECT_EQ(r()->error(),
-            "12:34 error: index must be signed or unsigned integer literal");
+  EXPECT_TRUE(r()->Resolve());
+  EXPECT_EQ(r()->error(), "");
 }
 
 TEST_F(ResolverIndexAccessorTest, Matrix_XDimension_Dynamic) {
@@ -70,9 +69,8 @@
   auto* acc = IndexAccessor("my_var", Expr(Source{{12, 34}}, idx));
   WrapInFunction(Decl(idx), acc);
 
-  EXPECT_FALSE(r()->Resolve());
-  EXPECT_EQ(r()->error(),
-            "12:34 error: index must be signed or unsigned integer literal");
+  EXPECT_TRUE(r()->Resolve());
+  EXPECT_EQ(r()->error(), "");
 }
 
 TEST_F(ResolverIndexAccessorTest, Matrix_BothDimension_Dynamic) {
@@ -82,9 +80,8 @@
       IndexAccessor(IndexAccessor("my_var", Expr(Source{{12, 34}}, idx)), 1);
   WrapInFunction(Decl(idx), acc);
 
-  EXPECT_FALSE(r()->Resolve());
-  EXPECT_EQ(r()->error(),
-            "12:34 error: index must be signed or unsigned integer literal");
+  EXPECT_TRUE(r()->Resolve());
+  EXPECT_EQ(r()->error(), "");
 }
 
 TEST_F(ResolverIndexAccessorTest, Matrix) {
@@ -221,9 +218,8 @@
        },
        ast::DecorationList{});
 
-  EXPECT_FALSE(r()->Resolve());
-  EXPECT_EQ(r()->error(),
-            "12:34 error: index must be signed or unsigned integer literal");
+  EXPECT_TRUE(r()->Resolve());
+  EXPECT_EQ(r()->error(), "");
 }
 
 TEST_F(ResolverIndexAccessorTest, Array_Literal_F32) {
diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc
index 68ed46d..7cf80f5 100644
--- a/src/resolver/resolver.cc
+++ b/src/resolver/resolver.cc
@@ -1197,18 +1197,6 @@
     return nullptr;
   }
 
-  if (obj_ty->IsAnyOf<sem::Array, sem::Matrix>()) {
-    if (!obj_raw_ty->Is<sem::Reference>()) {
-      // TODO(bclayton): expand this to allow any const_expr expression
-      // https://github.com/gpuweb/gpuweb/issues/1272
-      if (!idx->Declaration()->As<ast::IntLiteralExpression>()) {
-        AddError("index must be signed or unsigned integer literal",
-                 idx->Declaration()->source);
-        return nullptr;
-      }
-    }
-  }
-
   // If we're extracting from a reference, we return a reference.
   if (auto* ref = obj_raw_ty->As<sem::Reference>()) {
     ty = builder_->create<sem::Reference>(ty, ref->StorageClass(),
diff --git a/src/sem/constant.h b/src/sem/constant.h
index 4f5e198..ebd97a0 100644
--- a/src/sem/constant.h
+++ b/src/sem/constant.h
@@ -126,6 +126,13 @@
     return func(~0);
   }
 
+  /// @param index the index of the scalar value
+  /// @return the value of the scalar `static_cast` to type T.
+  template <typename T>
+  T ElementAs(size_t index) const {
+    return WithScalarAt(index, [](auto val) { return static_cast<T>(val); });
+  }
+
  private:
   const sem::Type* type_ = nullptr;
   const sem::Type* elem_type_ = nullptr;
diff --git a/src/transform/var_for_dynamic_index.cc b/src/transform/var_for_dynamic_index.cc
new file mode 100644
index 0000000..192701f
--- /dev/null
+++ b/src/transform/var_for_dynamic_index.cc
@@ -0,0 +1,91 @@
+// Copyright 2021 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/transform/var_for_dynamic_index.h"
+
+#include <utility>
+
+#include "src/program_builder.h"
+#include "src/sem/array.h"
+#include "src/sem/block_statement.h"
+#include "src/sem/expression.h"
+#include "src/sem/statement.h"
+#include "src/transform/for_loop_to_loop.h"
+
+namespace tint {
+namespace transform {
+
+VarForDynamicIndex::VarForDynamicIndex() = default;
+
+VarForDynamicIndex::~VarForDynamicIndex() = default;
+
+void VarForDynamicIndex::Run(CloneContext& ctx, const DataMap&, DataMap&) {
+  ProgramBuilder out;
+  if (!Requires<ForLoopToLoop>(ctx)) {
+    return;
+  }
+
+  auto& sem = ctx.src->Sem();
+
+  for (auto* node : ctx.src->ASTNodes().Objects()) {
+    if (auto* access_expr = node->As<ast::IndexAccessorExpression>()) {
+      // Found an array accessor expression
+      auto* index_expr = access_expr->index;
+      auto* object_expr = access_expr->object;
+
+      if (sem.Get(index_expr)->ConstantValue()) {
+        // Index expression resolves to a compile time value.
+        // As this isn't a dynamic index, we can ignore this.
+        continue;
+      }
+
+      auto* indexed = sem.Get(object_expr);
+      if (!indexed->Type()->IsAnyOf<sem::Array, sem::Matrix>()) {
+        // This transform currently only cares about array and matrices.
+        continue;
+      }
+
+      // Construct a `var` declaration to hold the value in memory.
+      // TODO(bclayton): group multiple accesses in the same object.
+      // e.g. arr[i] + arr[i+1] // Don't create two vars for this
+      auto var_name = ctx.dst->Symbols().New("var_for_index");
+      auto* var_decl = ctx.dst->Decl(
+          ctx.dst->Var(var_name, nullptr, ctx.Clone(object_expr)));
+
+      // Statement that owns the expression
+      auto* stmt = indexed->Stmt();
+      // Block that owns the statement
+      auto* block = stmt->Parent()->As<sem::BlockStatement>();
+      if (!block) {
+        TINT_ICE(Transform, ctx.dst->Diagnostics())
+            << "statement parent was not a block";
+        continue;
+      }
+
+      // Insert the `var` declaration before the statement that performs the
+      // indexing. Note that for indexing chains, AST node ordering guarantees
+      // that the inner-most index variable will be placed first in the block.
+      ctx.InsertBefore(block->Declaration()->statements, stmt->Declaration(),
+                       var_decl);
+
+      // Replace the original index expression with the new `var`.
+      ctx.Replace(object_expr, ctx.dst->Expr(var_name));
+    }
+  }
+
+  ctx.Clone();
+}
+
+}  // namespace transform
+}  // namespace tint
diff --git a/src/transform/var_for_dynamic_index.h b/src/transform/var_for_dynamic_index.h
new file mode 100644
index 0000000..ece5751
--- /dev/null
+++ b/src/transform/var_for_dynamic_index.h
@@ -0,0 +1,49 @@
+// Copyright 2021 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SRC_TRANSFORM_VAR_FOR_DYNAMIC_INDEX_H_
+#define SRC_TRANSFORM_VAR_FOR_DYNAMIC_INDEX_H_
+
+#include "src/transform/transform.h"
+
+namespace tint {
+namespace transform {
+
+/// A transform that extracts array and matrix values that are dynamically
+/// indexed to a temporary `var` local before performing the index. This
+/// transform is used by the SPIR-V writer as there is no SPIR-V instruction
+/// that can dynamically index a non-pointer composite.
+/// Requires the ForLoopToLoop transform to be run first.
+class VarForDynamicIndex : public Transform {
+ public:
+  /// Constructor
+  VarForDynamicIndex();
+
+  /// Destructor
+  ~VarForDynamicIndex() override;
+
+ protected:
+  /// Runs the transform using the CloneContext built for transforming a
+  /// program. Run() is responsible for calling Clone() on the CloneContext.
+  /// @param ctx the CloneContext primed with the input program and
+  /// ProgramBuilder
+  /// @param inputs optional extra transform-specific input data
+  /// @param outputs optional extra transform-specific output data
+  void Run(CloneContext& ctx, const DataMap& inputs, DataMap& outputs) override;
+};
+
+}  // namespace transform
+}  // namespace tint
+
+#endif  // SRC_TRANSFORM_VAR_FOR_DYNAMIC_INDEX_H_
diff --git a/src/transform/var_for_dynamic_index_test.cc b/src/transform/var_for_dynamic_index_test.cc
new file mode 100644
index 0000000..0f386ae
--- /dev/null
+++ b/src/transform/var_for_dynamic_index_test.cc
@@ -0,0 +1,327 @@
+// Copyright 2021 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/transform/var_for_dynamic_index.h"
+#include "src/transform/for_loop_to_loop.h"
+
+#include "src/transform/test_helper.h"
+
+namespace tint {
+namespace transform {
+namespace {
+
+using VarForDynamicIndexTest = TransformTest;
+
+TEST_F(VarForDynamicIndexTest, EmptyModule) {
+  auto* src = "";
+  auto* expect = "";
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, ArrayIndexDynamic) {
+  auto* src = R"(
+fn f() {
+  var i : i32;
+  let p = array<i32, 4>(1, 2, 3, 4);
+  let x = p[i];
+}
+)";
+
+  auto* expect = R"(
+fn f() {
+  var i : i32;
+  let p = array<i32, 4>(1, 2, 3, 4);
+  var var_for_index = p;
+  let x = var_for_index[i];
+}
+)";
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, MatrixIndexDynamic) {
+  auto* src = R"(
+fn f() {
+  var i : i32;
+  let p = mat2x2(1.0, 2.0, 3.0, 4.0);
+  let x = p[i];
+}
+)";
+
+  auto* expect = R"(
+fn f() {
+  var i : i32;
+  let p = mat2x2(1.0, 2.0, 3.0, 4.0);
+  var var_for_index = p;
+  let x = var_for_index[i];
+}
+)";
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, ArrayIndexDynamicChain) {
+  auto* src = R"(
+fn f() {
+  var i : i32;
+  var j : i32;
+  let p = array<array<i32, 2>, 2>(array<i32, 2>(1, 2), array<i32, 2>(3, 4));
+  let x = p[i][j];
+}
+)";
+
+  // TODO(bclayton): Optimize this case:
+  // This output is not as efficient as it could be.
+  // We only actually need to hoist the inner-most array to a `var`
+  // (`var_for_index`), as later indexing operations will be working with
+  // references, not values.
+
+  auto* expect = R"(
+fn f() {
+  var i : i32;
+  var j : i32;
+  let p = array<array<i32, 2>, 2>(array<i32, 2>(1, 2), array<i32, 2>(3, 4));
+  var var_for_index = p;
+  var var_for_index_1 = var_for_index[i];
+  let x = var_for_index_1[j];
+}
+)";
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, ArrayIndexInForLoopInit) {
+  auto* src = R"(
+fn f() {
+  var i : i32;
+  let p = array<array<i32, 2>, 2>(array<i32, 2>(1, 2), array<i32, 2>(3, 4));
+  for(let x = p[i]; ; ) {
+    break;
+  }
+}
+)";
+
+  auto* expect = R"(
+fn f() {
+  var i : i32;
+  let p = array<array<i32, 2>, 2>(array<i32, 2>(1, 2), array<i32, 2>(3, 4));
+  {
+    var var_for_index = p;
+    let x = var_for_index[i];
+    loop {
+      break;
+    }
+  }
+}
+)";
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, MatrixIndexInForLoopInit) {
+  auto* src = R"(
+fn f() {
+  var i : i32;
+  let p = mat2x2(1.0, 2.0, 3.0, 4.0);
+  for(let x = p[i]; ; ) {
+    break;
+  }
+}
+)";
+
+  auto* expect = R"(
+fn f() {
+  var i : i32;
+  let p = mat2x2(1.0, 2.0, 3.0, 4.0);
+  {
+    var var_for_index = p;
+    let x = var_for_index[i];
+    loop {
+      break;
+    }
+  }
+}
+)";
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, ArrayIndexInForLoopCond) {
+  auto* src = R"(
+fn f() {
+  var i : i32;
+  let p = array<i32, 2>(1, 2);
+  for(; p[i] < 3; ) {
+    break;
+  }
+}
+)";
+
+  auto* expect = R"(
+fn f() {
+  var i : i32;
+  let p = array<i32, 2>(1, 2);
+  loop {
+    var var_for_index = p;
+    if (!((var_for_index[i] < 3))) {
+      break;
+    }
+    break;
+  }
+}
+)";
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, MatrixIndexInForLoopCond) {
+  auto* src = R"(
+fn f() {
+  var i : i32;
+  let p = mat2x2(1.0, 2.0, 3.0, 4.0);
+  for(; p[i].x < 3.0; ) {
+    break;
+  }
+}
+)";
+
+  auto* expect = R"(
+fn f() {
+  var i : i32;
+  let p = mat2x2(1.0, 2.0, 3.0, 4.0);
+  loop {
+    var var_for_index = p;
+    if (!((var_for_index[i].x < 3.0))) {
+      break;
+    }
+    break;
+  }
+}
+)";
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, ArrayIndexLiteral) {
+  auto* src = R"(
+fn f() {
+  let p = array<i32, 4>(1, 2, 3, 4);
+  let x = p[1];
+}
+)";
+
+  auto* expect = src;
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, MatrixIndexLiteral) {
+  auto* src = R"(
+fn f() {
+  let p = mat2x2(1.0, 2.0, 3.0, 4.0);
+  let x = p[1];
+}
+)";
+
+  auto* expect = src;
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, ArrayIndexConstantLet) {
+  auto* src = R"(
+fn f() {
+  let p = array<i32, 4>(1, 2, 3, 4);
+  let c = 1;
+  let x = p[c];
+}
+)";
+
+  auto* expect = src;
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, MatrixIndexConstantLet) {
+  auto* src = R"(
+fn f() {
+  let p = mat2x2(1.0, 2.0, 3.0, 4.0);
+  let c = 1;
+  let x = p[c];
+}
+)";
+
+  auto* expect = src;
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, ArrayIndexLiteralChain) {
+  auto* src = R"(
+fn f() {
+  let p = array<array<i32, 2>, 2>(array<i32, 2>(1, 2), array<i32, 2>(3, 4));
+  let x = p[0][1];
+}
+)";
+
+  auto* expect = src;
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(VarForDynamicIndexTest, MatrixIndexLiteralChain) {
+  auto* src = R"(
+fn f() {
+  let p = mat2x2(1.0, 2.0, 3.0, 4.0);
+  let x = p[0][1];
+}
+)";
+
+  auto* expect = src;
+
+  auto got = Run<ForLoopToLoop, VarForDynamicIndex>(src);
+
+  EXPECT_EQ(expect, str(got));
+}
+
+}  // namespace
+}  // namespace transform
+}  // namespace tint
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index 19cae15..cec7b77 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -49,6 +49,7 @@
 #include "src/transform/manager.h"
 #include "src/transform/simplify_pointers.h"
 #include "src/transform/unshadow.h"
+#include "src/transform/var_for_dynamic_index.h"
 #include "src/transform/vectorize_scalar_matrix_constructors.h"
 #include "src/transform/zero_init_workgroup_memory.h"
 #include "src/utils/defer.h"
@@ -268,6 +269,7 @@
   manager.Add<transform::CanonicalizeEntryPointIO>();
   manager.Add<transform::AddEmptyEntryPoint>();
   manager.Add<transform::AddSpirvBlockDecoration>();
+  manager.Add<transform::VarForDynamicIndex>();
 
   data.Add<transform::CanonicalizeEntryPointIO::Config>(
       transform::CanonicalizeEntryPointIO::Config(
@@ -915,12 +917,17 @@
   auto extract = result_op();
   auto extract_id = extract.to_i();
 
-  // If the index is a literal, we use OpCompositeExtract.
-  if (auto* literal = expr->index->As<ast::IntLiteralExpression>()) {
-    if (!push_function_inst(spv::Op::OpCompositeExtract,
-                            {Operand::Int(result_type_id), extract,
-                             Operand::Int(info->source_id),
-                             Operand::Int(literal->ValueAsU32())})) {
+  // If the index is compile-time constant, we use OpCompositeExtract.
+  auto* idx = builder_.Sem().Get(expr->index);
+  if (auto idx_constval = idx->ConstantValue()) {
+    if (!push_function_inst(
+            spv::Op::OpCompositeExtract,
+            {
+                Operand::Int(result_type_id),
+                extract,
+                Operand::Int(info->source_id),
+                Operand::Int(idx_constval.ElementAs<uint32_t>(0)),
+            })) {
       return false;
     }
 
@@ -1107,6 +1114,9 @@
   }
   info.source_type = TypeOf(source);
 
+  // Note: Dynamic index on array and matrix values (lets) should have been
+  // promoted to storage with the VarForDynamicIndex transform.
+
   for (auto* accessor : accessors) {
     if (auto* array = accessor->As<ast::IndexAccessorExpression>()) {
       if (!GenerateIndexAccessor(array, &info)) {
diff --git a/src/writer/spirv/builder_accessor_expression_test.cc b/src/writer/spirv/builder_accessor_expression_test.cc
index 75f90e0..ff00575 100644
--- a/src/writer/spirv/builder_accessor_expression_test.cc
+++ b/src/writer/spirv/builder_accessor_expression_test.cc
@@ -940,12 +940,12 @@
 }
 
 TEST_F(BuilderTest, IndexAccessor_Array_Dynamic) {
-  // var a : array<f32, 3>;
+  // let a : array<f32, 3>;
   // idx : i32
   // a[idx]
 
-  auto* var = Var("a", ty.array<f32, 3>(),
-                  Construct(ty.array<f32, 3>(), 0.0f, 0.5f, 1.0f));
+  auto* var = Const("a", ty.array<f32, 3>(),
+                    Construct(ty.array<f32, 3>(), 0.0f, 0.5f, 1.0f));
 
   auto* idx = Var("idx", ty.i32());
   auto* expr = IndexAccessor("a", idx);
@@ -966,21 +966,21 @@
 %10 = OpConstant %6 0.5
 %11 = OpConstant %6 1
 %12 = OpConstantComposite %5 %9 %10 %11
-%14 = OpTypePointer Function %5
-%15 = OpConstantNull %5
-%18 = OpTypeInt 32 1
-%17 = OpTypePointer Function %18
-%19 = OpConstantNull %18
+%15 = OpTypeInt 32 1
+%14 = OpTypePointer Function %15
+%16 = OpConstantNull %15
+%18 = OpTypePointer Function %5
+%19 = OpConstantNull %5
 %21 = OpTypePointer Function %6
 )");
   EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
-            R"(%13 = OpVariable %14 Function %15
-%16 = OpVariable %17 Function %19
+            R"(%13 = OpVariable %14 Function %16
+%17 = OpVariable %18 Function %19
 )");
   EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
-            R"(OpStore %13 %12
-%20 = OpLoad %18 %16
-%22 = OpAccessChain %21 %13 %20
+            R"(OpStore %17 %12
+%20 = OpLoad %15 %13
+%22 = OpAccessChain %21 %17 %20
 %23 = OpLoad %6 %22
 OpReturn
 )");
@@ -989,14 +989,14 @@
 }
 
 TEST_F(BuilderTest, IndexAccessor_Matrix_Dynamic) {
-  // var a : mat2x2<f32>(vec2<f32>(1., 2.), vec2<f32>(3., 4.));
+  // let a : mat2x2<f32>(vec2<f32>(1., 2.), vec2<f32>(3., 4.));
   // idx : i32
   // a[idx]
 
   auto* var =
-      Var("a", ty.mat2x2<f32>(),
-          Construct(ty.mat2x2<f32>(), Construct(ty.vec2<f32>(), 1.f, 2.f),
-                    Construct(ty.vec2<f32>(), 3.f, 4.f)));
+      Const("a", ty.mat2x2<f32>(),
+            Construct(ty.mat2x2<f32>(), Construct(ty.vec2<f32>(), 1.f, 2.f),
+                      Construct(ty.vec2<f32>(), 3.f, 4.f)));
 
   auto* idx = Var("idx", ty.i32());
   auto* expr = IndexAccessor("a", idx);
@@ -1019,21 +1019,21 @@
 %12 = OpConstant %7 4
 %13 = OpConstantComposite %6 %11 %12
 %14 = OpConstantComposite %5 %10 %13
-%16 = OpTypePointer Function %5
-%17 = OpConstantNull %5
-%20 = OpTypeInt 32 1
-%19 = OpTypePointer Function %20
-%21 = OpConstantNull %20
+%17 = OpTypeInt 32 1
+%16 = OpTypePointer Function %17
+%18 = OpConstantNull %17
+%20 = OpTypePointer Function %5
+%21 = OpConstantNull %5
 %23 = OpTypePointer Function %6
 )");
   EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
-            R"(%15 = OpVariable %16 Function %17
-%18 = OpVariable %19 Function %21
+            R"(%15 = OpVariable %16 Function %18
+%19 = OpVariable %20 Function %21
 )");
   EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
-            R"(OpStore %15 %14
-%22 = OpLoad %20 %18
-%24 = OpAccessChain %23 %15 %22
+            R"(OpStore %19 %14
+%22 = OpLoad %17 %15
+%24 = OpAccessChain %23 %19 %22
 %25 = OpLoad %6 %24
 OpReturn
 )");
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 9b72af6..223ed34 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -330,6 +330,7 @@
     "../src/transform/test_helper.h",
     "../src/transform/transform_test.cc",
     "../src/transform/unshadow_test.cc",
+    "../src/transform/var_for_dynamic_index_test.cc",
     "../src/transform/vectorize_scalar_matrix_constructors_test.cc",
     "../src/transform/vertex_pulling_test.cc",
     "../src/transform/wrap_arrays_in_structs_test.cc",
diff --git a/test/bug/tint/824.wgsl b/test/bug/tint/824.wgsl
index 302e7bb..ed907e3 100644
--- a/test/bug/tint/824.wgsl
+++ b/test/bug/tint/824.wgsl
@@ -6,7 +6,7 @@
     [[builtin(vertex_index)]] VertexIndex : u32,
     [[builtin(instance_index)]] InstanceIndex : u32) -> Output {
     // TODO: remove workaround for Tint unary array access broke
-    var zv : array<vec2<f32>, 4> = array<vec2<f32>, 4>(
+    let zv : array<vec2<f32>, 4> = array<vec2<f32>, 4>(
         vec2<f32>(0.2, 0.2),
         vec2<f32>(0.3, 0.3),
         vec2<f32>(-0.1, -0.1),
@@ -14,7 +14,7 @@
     let z : f32 = zv[InstanceIndex].x;
     var output : Output;
     output.Position = vec4<f32>(0.5, 0.5, z, 1.0);
-    var colors : array<vec4<f32>, 4> = array<vec4<f32>, 4>(
+    let colors : array<vec4<f32>, 4> = array<vec4<f32>, 4>(
         vec4<f32>(1.0, 0.0, 0.0, 1.0),
         vec4<f32>(0.0, 1.0, 0.0, 1.0),
         vec4<f32>(0.0, 0.0, 1.0, 1.0),
@@ -22,4 +22,4 @@
     );
     output.color = colors[InstanceIndex];
     return output;
-}
\ No newline at end of file
+}
diff --git a/test/bug/tint/824.wgsl.expected.hlsl b/test/bug/tint/824.wgsl.expected.hlsl
index 58c4707..71b1f38 100644
--- a/test/bug/tint/824.wgsl.expected.hlsl
+++ b/test/bug/tint/824.wgsl.expected.hlsl
@@ -12,11 +12,11 @@
 };
 
 Output main_inner(uint VertexIndex, uint InstanceIndex) {
-  float2 zv[4] = {float2(0.200000003f, 0.200000003f), float2(0.300000012f, 0.300000012f), float2(-0.100000001f, -0.100000001f), float2(1.100000024f, 1.100000024f)};
+  const float2 zv[4] = {float2(0.200000003f, 0.200000003f), float2(0.300000012f, 0.300000012f), float2(-0.100000001f, -0.100000001f), float2(1.100000024f, 1.100000024f)};
   const float z = zv[InstanceIndex].x;
   Output output = (Output)0;
   output.Position = float4(0.5f, 0.5f, z, 1.0f);
-  float4 colors[4] = {float4(1.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(1.0f, 1.0f, 1.0f, 1.0f)};
+  const float4 colors[4] = {float4(1.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(1.0f, 1.0f, 1.0f, 1.0f)};
   output.color = colors[InstanceIndex];
   return output;
 }
diff --git a/test/bug/tint/824.wgsl.expected.msl b/test/bug/tint/824.wgsl.expected.msl
index 906762b..2f4f000 100644
--- a/test/bug/tint/824.wgsl.expected.msl
+++ b/test/bug/tint/824.wgsl.expected.msl
@@ -17,11 +17,11 @@
 };
 
 Output tint_symbol_inner(uint VertexIndex, uint InstanceIndex) {
-  tint_array_wrapper zv = {.arr={float2(0.200000003f, 0.200000003f), float2(0.300000012f, 0.300000012f), float2(-0.100000001f, -0.100000001f), float2(1.100000024f, 1.100000024f)}};
+  tint_array_wrapper const zv = {.arr={float2(0.200000003f, 0.200000003f), float2(0.300000012f, 0.300000012f), float2(-0.100000001f, -0.100000001f), float2(1.100000024f, 1.100000024f)}};
   float const z = zv.arr[InstanceIndex][0];
   Output output = {};
   output.Position = float4(0.5f, 0.5f, z, 1.0f);
-  tint_array_wrapper_1 colors = {.arr={float4(1.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(1.0f, 1.0f, 1.0f, 1.0f)}};
+  tint_array_wrapper_1 const colors = {.arr={float4(1.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(1.0f, 1.0f, 1.0f, 1.0f)}};
   output.color = colors.arr[InstanceIndex];
   return output;
 }
diff --git a/test/bug/tint/824.wgsl.expected.spvasm b/test/bug/tint/824.wgsl.expected.spvasm
index dc41468..1af29d5 100644
--- a/test/bug/tint/824.wgsl.expected.spvasm
+++ b/test/bug/tint/824.wgsl.expected.spvasm
@@ -17,9 +17,9 @@
                OpName %main_inner "main_inner"
                OpName %VertexIndex "VertexIndex"
                OpName %InstanceIndex "InstanceIndex"
-               OpName %zv "zv"
+               OpName %var_for_index "var_for_index"
                OpName %output "output"
-               OpName %colors "colors"
+               OpName %var_for_index_1 "var_for_index_1"
                OpName %main "main"
                OpDecorate %VertexIndex_1 BuiltIn VertexIndex
                OpDecorate %InstanceIndex_1 BuiltIn InstanceIndex
@@ -82,18 +82,18 @@
 %VertexIndex = OpFunctionParameter %uint
 %InstanceIndex = OpFunctionParameter %uint
          %19 = OpLabel
-         %zv = OpVariable %_ptr_Function__arr_v2float_uint_4 Function %34
+%var_for_index = OpVariable %_ptr_Function__arr_v2float_uint_4 Function %34
      %output = OpVariable %_ptr_Function_Output Function %41
-     %colors = OpVariable %_ptr_Function__arr_v4float_uint_4 Function %56
-               OpStore %zv %31
-         %37 = OpAccessChain %_ptr_Function_float %zv %InstanceIndex %uint_0
+%var_for_index_1 = OpVariable %_ptr_Function__arr_v4float_uint_4 Function %56
+               OpStore %var_for_index %31
+         %37 = OpAccessChain %_ptr_Function_float %var_for_index %InstanceIndex %uint_0
          %38 = OpLoad %float %37
          %43 = OpAccessChain %_ptr_Function_v4float %output %uint_0
          %46 = OpCompositeConstruct %v4float %float_0_5 %float_0_5 %38 %float_1
                OpStore %43 %46
-               OpStore %colors %53
+               OpStore %var_for_index_1 %53
          %58 = OpAccessChain %_ptr_Function_v4float %output %uint_1
-         %59 = OpAccessChain %_ptr_Function_v4float %colors %InstanceIndex
+         %59 = OpAccessChain %_ptr_Function_v4float %var_for_index_1 %InstanceIndex
          %60 = OpLoad %v4float %59
                OpStore %58 %60
          %61 = OpLoad %Output %output
diff --git a/test/bug/tint/824.wgsl.expected.wgsl b/test/bug/tint/824.wgsl.expected.wgsl
index e6f7ee0..6d051de 100644
--- a/test/bug/tint/824.wgsl.expected.wgsl
+++ b/test/bug/tint/824.wgsl.expected.wgsl
@@ -7,11 +7,11 @@
 
 [[stage(vertex)]]
 fn main([[builtin(vertex_index)]] VertexIndex : u32, [[builtin(instance_index)]] InstanceIndex : u32) -> Output {
-  var zv : array<vec2<f32>, 4> = array<vec2<f32>, 4>(vec2<f32>(0.200000003, 0.200000003), vec2<f32>(0.300000012, 0.300000012), vec2<f32>(-0.100000001, -0.100000001), vec2<f32>(1.100000024, 1.100000024));
+  let zv : array<vec2<f32>, 4> = array<vec2<f32>, 4>(vec2<f32>(0.200000003, 0.200000003), vec2<f32>(0.300000012, 0.300000012), vec2<f32>(-0.100000001, -0.100000001), vec2<f32>(1.100000024, 1.100000024));
   let z : f32 = zv[InstanceIndex].x;
   var output : Output;
   output.Position = vec4<f32>(0.5, 0.5, z, 1.0);
-  var colors : array<vec4<f32>, 4> = array<vec4<f32>, 4>(vec4<f32>(1.0, 0.0, 0.0, 1.0), vec4<f32>(0.0, 1.0, 0.0, 1.0), vec4<f32>(0.0, 0.0, 1.0, 1.0), vec4<f32>(1.0, 1.0, 1.0, 1.0));
+  let colors : array<vec4<f32>, 4> = array<vec4<f32>, 4>(vec4<f32>(1.0, 0.0, 0.0, 1.0), vec4<f32>(0.0, 1.0, 0.0, 1.0), vec4<f32>(0.0, 0.0, 1.0, 1.0), vec4<f32>(1.0, 1.0, 1.0, 1.0));
   output.color = colors[InstanceIndex];
   return output;
 }
diff --git a/test/bug/tint/825.wgsl b/test/bug/tint/825.wgsl
index 00ada3b..92a0b7e 100644
--- a/test/bug/tint/825.wgsl
+++ b/test/bug/tint/825.wgsl
@@ -1,6 +1,6 @@
 fn f() {
   var i : i32;
   var j : i32;
-  var m : mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
+  let m : mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
   let f : f32 = m[i][j];
-}
\ No newline at end of file
+}
diff --git a/test/bug/tint/825.wgsl.expected.hlsl b/test/bug/tint/825.wgsl.expected.hlsl
index febe29b..f38475d 100644
--- a/test/bug/tint/825.wgsl.expected.hlsl
+++ b/test/bug/tint/825.wgsl.expected.hlsl
@@ -6,6 +6,6 @@
 void f() {
   int i = 0;
   int j = 0;
-  float2x2 m = float2x2(float2(1.0f, 2.0f), float2(3.0f, 4.0f));
+  const float2x2 m = float2x2(float2(1.0f, 2.0f), float2(3.0f, 4.0f));
   const float f_1 = m[i][j];
 }
diff --git a/test/bug/tint/825.wgsl.expected.msl b/test/bug/tint/825.wgsl.expected.msl
index 4630243..b3f1c1a 100644
--- a/test/bug/tint/825.wgsl.expected.msl
+++ b/test/bug/tint/825.wgsl.expected.msl
@@ -4,7 +4,7 @@
 void f() {
   int i = 0;
   int j = 0;
-  float2x2 m = float2x2(float2(1.0f, 2.0f), float2(3.0f, 4.0f));
+  float2x2 const m = float2x2(float2(1.0f, 2.0f), float2(3.0f, 4.0f));
   float const f_1 = m[i][j];
 }
 
diff --git a/test/bug/tint/825.wgsl.expected.spvasm b/test/bug/tint/825.wgsl.expected.spvasm
index 0b9dbf6..d7996bf 100644
--- a/test/bug/tint/825.wgsl.expected.spvasm
+++ b/test/bug/tint/825.wgsl.expected.spvasm
@@ -11,7 +11,7 @@
                OpName %f "f"
                OpName %i "i"
                OpName %j "j"
-               OpName %m "m"
+               OpName %var_for_index "var_for_index"
        %void = OpTypeVoid
           %1 = OpTypeFunction %void
         %int = OpTypeInt 32 1
@@ -38,11 +38,11 @@
           %6 = OpLabel
           %i = OpVariable %_ptr_Function_int Function %10
           %j = OpVariable %_ptr_Function_int Function %10
-          %m = OpVariable %_ptr_Function_mat2v2float Function %24
-               OpStore %m %21
+%var_for_index = OpVariable %_ptr_Function_mat2v2float Function %24
+               OpStore %var_for_index %21
          %25 = OpLoad %int %i
          %26 = OpLoad %int %j
-         %28 = OpAccessChain %_ptr_Function_float %m %25 %26
+         %28 = OpAccessChain %_ptr_Function_float %var_for_index %25 %26
          %29 = OpLoad %float %28
                OpReturn
                OpFunctionEnd
diff --git a/test/bug/tint/825.wgsl.expected.wgsl b/test/bug/tint/825.wgsl.expected.wgsl
index a945c40..92a0b7e 100644
--- a/test/bug/tint/825.wgsl.expected.wgsl
+++ b/test/bug/tint/825.wgsl.expected.wgsl
@@ -1,6 +1,6 @@
 fn f() {
   var i : i32;
   var j : i32;
-  var m : mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
+  let m : mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
   let f : f32 = m[i][j];
 }
diff --git a/test/expressions/index/let/let/literal/array.wgsl b/test/expressions/index/let/let/literal/array.wgsl
new file mode 100644
index 0000000..414d397
--- /dev/null
+++ b/test/expressions/index/let/let/literal/array.wgsl
@@ -0,0 +1,5 @@
+fn f() -> i32 {
+  let a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  let i = 1;
+  return a[i];
+}
diff --git a/test/expressions/index/let/let/literal/array.wgsl.expected.hlsl b/test/expressions/index/let/let/literal/array.wgsl.expected.hlsl
new file mode 100644
index 0000000..7174cfa
--- /dev/null
+++ b/test/expressions/index/let/let/literal/array.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+int f() {
+  const int a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+  return a[1];
+}
diff --git a/test/expressions/index/let/let/literal/array.wgsl.expected.msl b/test/expressions/index/let/let/literal/array.wgsl.expected.msl
new file mode 100644
index 0000000..57bf97d
--- /dev/null
+++ b/test/expressions/index/let/let/literal/array.wgsl.expected.msl
@@ -0,0 +1,13 @@
+#include <metal_stdlib>
+
+using namespace metal;
+struct tint_array_wrapper {
+  int arr[8];
+};
+
+int f() {
+  tint_array_wrapper const a = {.arr={1, 2, 3, 4, 5, 6, 7, 8}};
+  int const i = 1;
+  return a.arr[i];
+}
+
diff --git a/test/expressions/index/let/let/literal/array.wgsl.expected.spvasm b/test/expressions/index/let/let/literal/array.wgsl.expected.spvasm
new file mode 100644
index 0000000..1dc9cda
--- /dev/null
+++ b/test/expressions/index/let/let/literal/array.wgsl.expected.spvasm
@@ -0,0 +1,37 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 22
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpDecorate %_arr_int_uint_8 ArrayStride 4
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %int
+       %uint = OpTypeInt 32 0
+     %uint_8 = OpConstant %uint 8
+%_arr_int_uint_8 = OpTypeArray %int %uint_8
+      %int_1 = OpConstant %int 1
+      %int_2 = OpConstant %int 2
+      %int_3 = OpConstant %int 3
+      %int_4 = OpConstant %int 4
+      %int_5 = OpConstant %int 5
+      %int_6 = OpConstant %int 6
+      %int_7 = OpConstant %int 7
+      %int_8 = OpConstant %int 8
+         %20 = OpConstantComposite %_arr_int_uint_8 %int_1 %int_2 %int_3 %int_4 %int_5 %int_6 %int_7 %int_8
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %int None %5
+          %8 = OpLabel
+         %21 = OpCompositeExtract %int %20 1
+               OpReturnValue %21
+               OpFunctionEnd
diff --git a/test/expressions/index/let/let/literal/array.wgsl.expected.wgsl b/test/expressions/index/let/let/literal/array.wgsl.expected.wgsl
new file mode 100644
index 0000000..414d397
--- /dev/null
+++ b/test/expressions/index/let/let/literal/array.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f() -> i32 {
+  let a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  let i = 1;
+  return a[i];
+}
diff --git a/test/expressions/index/let/let/literal/matrix.wgsl b/test/expressions/index/let/let/literal/matrix.wgsl
new file mode 100644
index 0000000..33b717d
--- /dev/null
+++ b/test/expressions/index/let/let/literal/matrix.wgsl
@@ -0,0 +1,5 @@
+fn f() -> vec3<f32> {
+  let m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  let i = 1;
+  return m[i];
+}
diff --git a/test/expressions/index/let/let/literal/matrix.wgsl.expected.hlsl b/test/expressions/index/let/let/literal/matrix.wgsl.expected.hlsl
new file mode 100644
index 0000000..f209d03
--- /dev/null
+++ b/test/expressions/index/let/let/literal/matrix.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float3 f() {
+  const float3x3 m = float3x3(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
+  return m[1];
+}
diff --git a/test/expressions/index/let/let/literal/matrix.wgsl.expected.msl b/test/expressions/index/let/let/literal/matrix.wgsl.expected.msl
new file mode 100644
index 0000000..ca9238e
--- /dev/null
+++ b/test/expressions/index/let/let/literal/matrix.wgsl.expected.msl
@@ -0,0 +1,9 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float3 f() {
+  float3x3 const m = float3x3(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f));
+  int const i = 1;
+  return m[i];
+}
+
diff --git a/test/expressions/index/let/let/literal/matrix.wgsl.expected.spvasm b/test/expressions/index/let/let/literal/matrix.wgsl.expected.spvasm
new file mode 100644
index 0000000..0e46829
--- /dev/null
+++ b/test/expressions/index/let/let/literal/matrix.wgsl.expected.spvasm
@@ -0,0 +1,41 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 27
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+    %v3float = OpTypeVector %float 3
+          %5 = OpTypeFunction %v3float
+%mat3v3float = OpTypeMatrix %v3float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %14 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+    %float_4 = OpConstant %float 4
+    %float_5 = OpConstant %float 5
+    %float_6 = OpConstant %float 6
+         %18 = OpConstantComposite %v3float %float_4 %float_5 %float_6
+    %float_7 = OpConstant %float 7
+    %float_8 = OpConstant %float 8
+    %float_9 = OpConstant %float 9
+         %22 = OpConstantComposite %v3float %float_7 %float_8 %float_9
+         %23 = OpConstantComposite %mat3v3float %14 %18 %22
+        %int = OpTypeInt 32 1
+      %int_1 = OpConstant %int 1
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %v3float None %5
+          %9 = OpLabel
+         %26 = OpCompositeExtract %v3float %23 1
+               OpReturnValue %26
+               OpFunctionEnd
diff --git a/test/expressions/index/let/let/literal/matrix.wgsl.expected.wgsl b/test/expressions/index/let/let/literal/matrix.wgsl.expected.wgsl
new file mode 100644
index 0000000..33b717d
--- /dev/null
+++ b/test/expressions/index/let/let/literal/matrix.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f() -> vec3<f32> {
+  let m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  let i = 1;
+  return m[i];
+}
diff --git a/test/expressions/index/let/let/literal/vector.wgsl b/test/expressions/index/let/let/literal/vector.wgsl
new file mode 100644
index 0000000..d113acb
--- /dev/null
+++ b/test/expressions/index/let/let/literal/vector.wgsl
@@ -0,0 +1,5 @@
+fn f() -> f32 {
+  let v = vec3<f32>(1.0, 2.0, 3.0);
+  let i = 1;
+  return v[i];
+}
diff --git a/test/expressions/index/let/let/literal/vector.wgsl.expected.hlsl b/test/expressions/index/let/let/literal/vector.wgsl.expected.hlsl
new file mode 100644
index 0000000..ede6118
--- /dev/null
+++ b/test/expressions/index/let/let/literal/vector.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float f() {
+  const float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[1];
+}
diff --git a/test/expressions/index/let/let/literal/vector.wgsl.expected.msl b/test/expressions/index/let/let/literal/vector.wgsl.expected.msl
new file mode 100644
index 0000000..587f5cf
--- /dev/null
+++ b/test/expressions/index/let/let/literal/vector.wgsl.expected.msl
@@ -0,0 +1,9 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float f() {
+  float3 const v = float3(1.0f, 2.0f, 3.0f);
+  int const i = 1;
+  return v[i];
+}
+
diff --git a/test/expressions/index/let/let/literal/vector.wgsl.expected.spvasm b/test/expressions/index/let/let/literal/vector.wgsl.expected.spvasm
new file mode 100644
index 0000000..d274e46
--- /dev/null
+++ b/test/expressions/index/let/let/literal/vector.wgsl.expected.spvasm
@@ -0,0 +1,31 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 17
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+          %5 = OpTypeFunction %float
+    %v3float = OpTypeVector %float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %13 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+        %int = OpTypeInt 32 1
+      %int_1 = OpConstant %int 1
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %float None %5
+          %8 = OpLabel
+         %16 = OpCompositeExtract %float %13 1
+               OpReturnValue %16
+               OpFunctionEnd
diff --git a/test/expressions/index/let/let/literal/vector.wgsl.expected.wgsl b/test/expressions/index/let/let/literal/vector.wgsl.expected.wgsl
new file mode 100644
index 0000000..d113acb
--- /dev/null
+++ b/test/expressions/index/let/let/literal/vector.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f() -> f32 {
+  let v = vec3<f32>(1.0, 2.0, 3.0);
+  let i = 1;
+  return v[i];
+}
diff --git a/test/expressions/index/let/let/param/array.wgsl b/test/expressions/index/let/let/param/array.wgsl
new file mode 100644
index 0000000..b4f524b
--- /dev/null
+++ b/test/expressions/index/let/let/param/array.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> i32 {
+  let a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  let i = x;
+  return a[i];
+}
diff --git a/test/expressions/index/let/let/param/array.wgsl.expected.hlsl b/test/expressions/index/let/let/param/array.wgsl.expected.hlsl
new file mode 100644
index 0000000..520cdf8
--- /dev/null
+++ b/test/expressions/index/let/let/param/array.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+int f(int x) {
+  const int a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+  return a[x];
+}
diff --git a/test/expressions/index/let/let/param/array.wgsl.expected.msl b/test/expressions/index/let/let/param/array.wgsl.expected.msl
new file mode 100644
index 0000000..7b941e4
--- /dev/null
+++ b/test/expressions/index/let/let/param/array.wgsl.expected.msl
@@ -0,0 +1,13 @@
+#include <metal_stdlib>
+
+using namespace metal;
+struct tint_array_wrapper {
+  int arr[8];
+};
+
+int f(int x) {
+  tint_array_wrapper const a = {.arr={1, 2, 3, 4, 5, 6, 7, 8}};
+  int const i = x;
+  return a.arr[i];
+}
+
diff --git a/test/expressions/index/let/let/param/array.wgsl.expected.spvasm b/test/expressions/index/let/let/param/array.wgsl.expected.spvasm
new file mode 100644
index 0000000..57ee30c
--- /dev/null
+++ b/test/expressions/index/let/let/param/array.wgsl.expected.spvasm
@@ -0,0 +1,46 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 28
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %x "x"
+               OpName %var_for_index "var_for_index"
+               OpDecorate %_arr_int_uint_8 ArrayStride 4
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %int %int
+       %uint = OpTypeInt 32 0
+     %uint_8 = OpConstant %uint 8
+%_arr_int_uint_8 = OpTypeArray %int %uint_8
+      %int_1 = OpConstant %int 1
+      %int_2 = OpConstant %int 2
+      %int_3 = OpConstant %int 3
+      %int_4 = OpConstant %int 4
+      %int_5 = OpConstant %int 5
+      %int_6 = OpConstant %int 6
+      %int_7 = OpConstant %int 7
+      %int_8 = OpConstant %int 8
+         %21 = OpConstantComposite %_arr_int_uint_8 %int_1 %int_2 %int_3 %int_4 %int_5 %int_6 %int_7 %int_8
+%_ptr_Function__arr_int_uint_8 = OpTypePointer Function %_arr_int_uint_8
+         %24 = OpConstantNull %_arr_int_uint_8
+%_ptr_Function_int = OpTypePointer Function %int
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %int None %5
+          %x = OpFunctionParameter %int
+          %9 = OpLabel
+%var_for_index = OpVariable %_ptr_Function__arr_int_uint_8 Function %24
+               OpStore %var_for_index %21
+         %26 = OpAccessChain %_ptr_Function_int %var_for_index %x
+         %27 = OpLoad %int %26
+               OpReturnValue %27
+               OpFunctionEnd
diff --git a/test/expressions/index/let/let/param/array.wgsl.expected.wgsl b/test/expressions/index/let/let/param/array.wgsl.expected.wgsl
new file mode 100644
index 0000000..b4f524b
--- /dev/null
+++ b/test/expressions/index/let/let/param/array.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> i32 {
+  let a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  let i = x;
+  return a[i];
+}
diff --git a/test/expressions/index/let/let/param/matrix.wgsl b/test/expressions/index/let/let/param/matrix.wgsl
new file mode 100644
index 0000000..f9561bf
--- /dev/null
+++ b/test/expressions/index/let/let/param/matrix.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> vec3<f32> {
+  let m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  let i = x;
+  return m[i];
+}
diff --git a/test/expressions/index/let/let/param/matrix.wgsl.expected.hlsl b/test/expressions/index/let/let/param/matrix.wgsl.expected.hlsl
new file mode 100644
index 0000000..9dd1ad7
--- /dev/null
+++ b/test/expressions/index/let/let/param/matrix.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float3 f(int x) {
+  const float3x3 m = float3x3(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
+  return m[x];
+}
diff --git a/test/expressions/index/let/let/param/matrix.wgsl.expected.msl b/test/expressions/index/let/let/param/matrix.wgsl.expected.msl
new file mode 100644
index 0000000..647d17a
--- /dev/null
+++ b/test/expressions/index/let/let/param/matrix.wgsl.expected.msl
@@ -0,0 +1,9 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float3 f(int x) {
+  float3x3 const m = float3x3(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f));
+  int const i = x;
+  return m[i];
+}
+
diff --git a/test/expressions/index/let/let/param/matrix.wgsl.expected.spvasm b/test/expressions/index/let/let/param/matrix.wgsl.expected.spvasm
new file mode 100644
index 0000000..0d54e21
--- /dev/null
+++ b/test/expressions/index/let/let/param/matrix.wgsl.expected.spvasm
@@ -0,0 +1,49 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 32
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %x "x"
+               OpName %var_for_index "var_for_index"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+    %v3float = OpTypeVector %float 3
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %v3float %int
+%mat3v3float = OpTypeMatrix %v3float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %16 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+    %float_4 = OpConstant %float 4
+    %float_5 = OpConstant %float 5
+    %float_6 = OpConstant %float 6
+         %20 = OpConstantComposite %v3float %float_4 %float_5 %float_6
+    %float_7 = OpConstant %float 7
+    %float_8 = OpConstant %float 8
+    %float_9 = OpConstant %float 9
+         %24 = OpConstantComposite %v3float %float_7 %float_8 %float_9
+         %25 = OpConstantComposite %mat3v3float %16 %20 %24
+%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
+         %28 = OpConstantNull %mat3v3float
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %v3float None %5
+          %x = OpFunctionParameter %int
+         %11 = OpLabel
+%var_for_index = OpVariable %_ptr_Function_mat3v3float Function %28
+               OpStore %var_for_index %25
+         %30 = OpAccessChain %_ptr_Function_v3float %var_for_index %x
+         %31 = OpLoad %v3float %30
+               OpReturnValue %31
+               OpFunctionEnd
diff --git a/test/expressions/index/let/let/param/matrix.wgsl.expected.wgsl b/test/expressions/index/let/let/param/matrix.wgsl.expected.wgsl
new file mode 100644
index 0000000..f9561bf
--- /dev/null
+++ b/test/expressions/index/let/let/param/matrix.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> vec3<f32> {
+  let m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  let i = x;
+  return m[i];
+}
diff --git a/test/expressions/index/let/let/param/vector.wgsl b/test/expressions/index/let/let/param/vector.wgsl
new file mode 100644
index 0000000..b23729a
--- /dev/null
+++ b/test/expressions/index/let/let/param/vector.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> f32 {
+  let v = vec3<f32>(1.0, 2.0, 3.0);
+  let i = x;
+  return v[i];
+}
diff --git a/test/expressions/index/let/let/param/vector.wgsl.expected.hlsl b/test/expressions/index/let/let/param/vector.wgsl.expected.hlsl
new file mode 100644
index 0000000..5629258
--- /dev/null
+++ b/test/expressions/index/let/let/param/vector.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float f(int x) {
+  const float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[x];
+}
diff --git a/test/expressions/index/let/let/param/vector.wgsl.expected.msl b/test/expressions/index/let/let/param/vector.wgsl.expected.msl
new file mode 100644
index 0000000..b0d8ca9
--- /dev/null
+++ b/test/expressions/index/let/let/param/vector.wgsl.expected.msl
@@ -0,0 +1,9 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float f(int x) {
+  float3 const v = float3(1.0f, 2.0f, 3.0f);
+  int const i = x;
+  return v[i];
+}
+
diff --git a/test/expressions/index/let/let/param/vector.wgsl.expected.spvasm b/test/expressions/index/let/let/param/vector.wgsl.expected.spvasm
new file mode 100644
index 0000000..d1bfae5
--- /dev/null
+++ b/test/expressions/index/let/let/param/vector.wgsl.expected.spvasm
@@ -0,0 +1,32 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 17
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %x "x"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %float %int
+    %v3float = OpTypeVector %float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %15 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %float None %5
+          %x = OpFunctionParameter %int
+         %10 = OpLabel
+         %16 = OpVectorExtractDynamic %float %15 %x
+               OpReturnValue %16
+               OpFunctionEnd
diff --git a/test/expressions/index/let/let/param/vector.wgsl.expected.wgsl b/test/expressions/index/let/let/param/vector.wgsl.expected.wgsl
new file mode 100644
index 0000000..b23729a
--- /dev/null
+++ b/test/expressions/index/let/let/param/vector.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> f32 {
+  let v = vec3<f32>(1.0, 2.0, 3.0);
+  let i = x;
+  return v[i];
+}
diff --git a/test/expressions/index/let/literal/array.wgsl b/test/expressions/index/let/literal/array.wgsl
new file mode 100644
index 0000000..1435ee7
--- /dev/null
+++ b/test/expressions/index/let/literal/array.wgsl
@@ -0,0 +1,4 @@
+fn f() -> i32 {
+  let a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  return a[1];
+}
diff --git a/test/expressions/index/let/literal/array.wgsl.expected.hlsl b/test/expressions/index/let/literal/array.wgsl.expected.hlsl
new file mode 100644
index 0000000..7174cfa
--- /dev/null
+++ b/test/expressions/index/let/literal/array.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+int f() {
+  const int a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+  return a[1];
+}
diff --git a/test/expressions/index/let/literal/array.wgsl.expected.msl b/test/expressions/index/let/literal/array.wgsl.expected.msl
new file mode 100644
index 0000000..d4d28b1
--- /dev/null
+++ b/test/expressions/index/let/literal/array.wgsl.expected.msl
@@ -0,0 +1,12 @@
+#include <metal_stdlib>
+
+using namespace metal;
+struct tint_array_wrapper {
+  int arr[8];
+};
+
+int f() {
+  tint_array_wrapper const a = {.arr={1, 2, 3, 4, 5, 6, 7, 8}};
+  return a.arr[1];
+}
+
diff --git a/test/expressions/index/let/literal/array.wgsl.expected.spvasm b/test/expressions/index/let/literal/array.wgsl.expected.spvasm
new file mode 100644
index 0000000..1dc9cda
--- /dev/null
+++ b/test/expressions/index/let/literal/array.wgsl.expected.spvasm
@@ -0,0 +1,37 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 22
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpDecorate %_arr_int_uint_8 ArrayStride 4
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %int
+       %uint = OpTypeInt 32 0
+     %uint_8 = OpConstant %uint 8
+%_arr_int_uint_8 = OpTypeArray %int %uint_8
+      %int_1 = OpConstant %int 1
+      %int_2 = OpConstant %int 2
+      %int_3 = OpConstant %int 3
+      %int_4 = OpConstant %int 4
+      %int_5 = OpConstant %int 5
+      %int_6 = OpConstant %int 6
+      %int_7 = OpConstant %int 7
+      %int_8 = OpConstant %int 8
+         %20 = OpConstantComposite %_arr_int_uint_8 %int_1 %int_2 %int_3 %int_4 %int_5 %int_6 %int_7 %int_8
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %int None %5
+          %8 = OpLabel
+         %21 = OpCompositeExtract %int %20 1
+               OpReturnValue %21
+               OpFunctionEnd
diff --git a/test/expressions/index/let/literal/array.wgsl.expected.wgsl b/test/expressions/index/let/literal/array.wgsl.expected.wgsl
new file mode 100644
index 0000000..1435ee7
--- /dev/null
+++ b/test/expressions/index/let/literal/array.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f() -> i32 {
+  let a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  return a[1];
+}
diff --git a/test/expressions/index/let/literal/matrix.wgsl b/test/expressions/index/let/literal/matrix.wgsl
new file mode 100644
index 0000000..a6f9e38
--- /dev/null
+++ b/test/expressions/index/let/literal/matrix.wgsl
@@ -0,0 +1,4 @@
+fn f() -> vec3<f32> {
+  let m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  return m[1];
+}
diff --git a/test/expressions/index/let/literal/matrix.wgsl.expected.hlsl b/test/expressions/index/let/literal/matrix.wgsl.expected.hlsl
new file mode 100644
index 0000000..f209d03
--- /dev/null
+++ b/test/expressions/index/let/literal/matrix.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float3 f() {
+  const float3x3 m = float3x3(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
+  return m[1];
+}
diff --git a/test/expressions/index/let/literal/matrix.wgsl.expected.msl b/test/expressions/index/let/literal/matrix.wgsl.expected.msl
new file mode 100644
index 0000000..92a23c4
--- /dev/null
+++ b/test/expressions/index/let/literal/matrix.wgsl.expected.msl
@@ -0,0 +1,8 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float3 f() {
+  float3x3 const m = float3x3(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f));
+  return m[1];
+}
+
diff --git a/test/expressions/index/let/literal/matrix.wgsl.expected.spvasm b/test/expressions/index/let/literal/matrix.wgsl.expected.spvasm
new file mode 100644
index 0000000..0e46829
--- /dev/null
+++ b/test/expressions/index/let/literal/matrix.wgsl.expected.spvasm
@@ -0,0 +1,41 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 27
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+    %v3float = OpTypeVector %float 3
+          %5 = OpTypeFunction %v3float
+%mat3v3float = OpTypeMatrix %v3float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %14 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+    %float_4 = OpConstant %float 4
+    %float_5 = OpConstant %float 5
+    %float_6 = OpConstant %float 6
+         %18 = OpConstantComposite %v3float %float_4 %float_5 %float_6
+    %float_7 = OpConstant %float 7
+    %float_8 = OpConstant %float 8
+    %float_9 = OpConstant %float 9
+         %22 = OpConstantComposite %v3float %float_7 %float_8 %float_9
+         %23 = OpConstantComposite %mat3v3float %14 %18 %22
+        %int = OpTypeInt 32 1
+      %int_1 = OpConstant %int 1
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %v3float None %5
+          %9 = OpLabel
+         %26 = OpCompositeExtract %v3float %23 1
+               OpReturnValue %26
+               OpFunctionEnd
diff --git a/test/expressions/index/let/literal/matrix.wgsl.expected.wgsl b/test/expressions/index/let/literal/matrix.wgsl.expected.wgsl
new file mode 100644
index 0000000..a6f9e38
--- /dev/null
+++ b/test/expressions/index/let/literal/matrix.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f() -> vec3<f32> {
+  let m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  return m[1];
+}
diff --git a/test/expressions/index/let/literal/vector.wgsl b/test/expressions/index/let/literal/vector.wgsl
new file mode 100644
index 0000000..7749978
--- /dev/null
+++ b/test/expressions/index/let/literal/vector.wgsl
@@ -0,0 +1,4 @@
+fn f() -> f32 {
+  let v = vec3<f32>(1.0, 2.0, 3.0);
+  return v[1];
+}
diff --git a/test/expressions/index/let/literal/vector.wgsl.expected.hlsl b/test/expressions/index/let/literal/vector.wgsl.expected.hlsl
new file mode 100644
index 0000000..ede6118
--- /dev/null
+++ b/test/expressions/index/let/literal/vector.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float f() {
+  const float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[1];
+}
diff --git a/test/expressions/index/let/literal/vector.wgsl.expected.msl b/test/expressions/index/let/literal/vector.wgsl.expected.msl
new file mode 100644
index 0000000..94dc06a
--- /dev/null
+++ b/test/expressions/index/let/literal/vector.wgsl.expected.msl
@@ -0,0 +1,8 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float f() {
+  float3 const v = float3(1.0f, 2.0f, 3.0f);
+  return v[1];
+}
+
diff --git a/test/expressions/index/let/literal/vector.wgsl.expected.spvasm b/test/expressions/index/let/literal/vector.wgsl.expected.spvasm
new file mode 100644
index 0000000..d274e46
--- /dev/null
+++ b/test/expressions/index/let/literal/vector.wgsl.expected.spvasm
@@ -0,0 +1,31 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 17
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+          %5 = OpTypeFunction %float
+    %v3float = OpTypeVector %float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %13 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+        %int = OpTypeInt 32 1
+      %int_1 = OpConstant %int 1
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %float None %5
+          %8 = OpLabel
+         %16 = OpCompositeExtract %float %13 1
+               OpReturnValue %16
+               OpFunctionEnd
diff --git a/test/expressions/index/let/literal/vector.wgsl.expected.wgsl b/test/expressions/index/let/literal/vector.wgsl.expected.wgsl
new file mode 100644
index 0000000..7749978
--- /dev/null
+++ b/test/expressions/index/let/literal/vector.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f() -> f32 {
+  let v = vec3<f32>(1.0, 2.0, 3.0);
+  return v[1];
+}
diff --git a/test/expressions/index/let/param/array.wgsl b/test/expressions/index/let/param/array.wgsl
new file mode 100644
index 0000000..12182e7
--- /dev/null
+++ b/test/expressions/index/let/param/array.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> i32 {
+  let a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  return a[i];
+}
diff --git a/test/expressions/index/let/param/array.wgsl.expected.hlsl b/test/expressions/index/let/param/array.wgsl.expected.hlsl
new file mode 100644
index 0000000..28830b2
--- /dev/null
+++ b/test/expressions/index/let/param/array.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+int f(int i) {
+  const int a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+  return a[i];
+}
diff --git a/test/expressions/index/let/param/array.wgsl.expected.msl b/test/expressions/index/let/param/array.wgsl.expected.msl
new file mode 100644
index 0000000..eac5c42
--- /dev/null
+++ b/test/expressions/index/let/param/array.wgsl.expected.msl
@@ -0,0 +1,12 @@
+#include <metal_stdlib>
+
+using namespace metal;
+struct tint_array_wrapper {
+  int arr[8];
+};
+
+int f(int i) {
+  tint_array_wrapper const a = {.arr={1, 2, 3, 4, 5, 6, 7, 8}};
+  return a.arr[i];
+}
+
diff --git a/test/expressions/index/let/param/array.wgsl.expected.spvasm b/test/expressions/index/let/param/array.wgsl.expected.spvasm
new file mode 100644
index 0000000..43c8d10
--- /dev/null
+++ b/test/expressions/index/let/param/array.wgsl.expected.spvasm
@@ -0,0 +1,46 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 28
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %i "i"
+               OpName %var_for_index "var_for_index"
+               OpDecorate %_arr_int_uint_8 ArrayStride 4
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %int %int
+       %uint = OpTypeInt 32 0
+     %uint_8 = OpConstant %uint 8
+%_arr_int_uint_8 = OpTypeArray %int %uint_8
+      %int_1 = OpConstant %int 1
+      %int_2 = OpConstant %int 2
+      %int_3 = OpConstant %int 3
+      %int_4 = OpConstant %int 4
+      %int_5 = OpConstant %int 5
+      %int_6 = OpConstant %int 6
+      %int_7 = OpConstant %int 7
+      %int_8 = OpConstant %int 8
+         %21 = OpConstantComposite %_arr_int_uint_8 %int_1 %int_2 %int_3 %int_4 %int_5 %int_6 %int_7 %int_8
+%_ptr_Function__arr_int_uint_8 = OpTypePointer Function %_arr_int_uint_8
+         %24 = OpConstantNull %_arr_int_uint_8
+%_ptr_Function_int = OpTypePointer Function %int
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %int None %5
+          %i = OpFunctionParameter %int
+          %9 = OpLabel
+%var_for_index = OpVariable %_ptr_Function__arr_int_uint_8 Function %24
+               OpStore %var_for_index %21
+         %26 = OpAccessChain %_ptr_Function_int %var_for_index %i
+         %27 = OpLoad %int %26
+               OpReturnValue %27
+               OpFunctionEnd
diff --git a/test/expressions/index/let/param/array.wgsl.expected.wgsl b/test/expressions/index/let/param/array.wgsl.expected.wgsl
new file mode 100644
index 0000000..12182e7
--- /dev/null
+++ b/test/expressions/index/let/param/array.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> i32 {
+  let a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  return a[i];
+}
diff --git a/test/expressions/index/let/param/matrix.wgsl b/test/expressions/index/let/param/matrix.wgsl
new file mode 100644
index 0000000..dc0cff2
--- /dev/null
+++ b/test/expressions/index/let/param/matrix.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> vec3<f32> {
+  let m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  return m[i];
+}
diff --git a/test/expressions/index/let/param/matrix.wgsl.expected.hlsl b/test/expressions/index/let/param/matrix.wgsl.expected.hlsl
new file mode 100644
index 0000000..5609c2a
--- /dev/null
+++ b/test/expressions/index/let/param/matrix.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float3 f(int i) {
+  const float3x3 m = float3x3(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
+  return m[i];
+}
diff --git a/test/expressions/index/let/param/matrix.wgsl.expected.msl b/test/expressions/index/let/param/matrix.wgsl.expected.msl
new file mode 100644
index 0000000..49218fd
--- /dev/null
+++ b/test/expressions/index/let/param/matrix.wgsl.expected.msl
@@ -0,0 +1,8 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float3 f(int i) {
+  float3x3 const m = float3x3(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f));
+  return m[i];
+}
+
diff --git a/test/expressions/index/let/param/matrix.wgsl.expected.spvasm b/test/expressions/index/let/param/matrix.wgsl.expected.spvasm
new file mode 100644
index 0000000..9a5d8aa
--- /dev/null
+++ b/test/expressions/index/let/param/matrix.wgsl.expected.spvasm
@@ -0,0 +1,49 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 32
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %i "i"
+               OpName %var_for_index "var_for_index"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+    %v3float = OpTypeVector %float 3
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %v3float %int
+%mat3v3float = OpTypeMatrix %v3float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %16 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+    %float_4 = OpConstant %float 4
+    %float_5 = OpConstant %float 5
+    %float_6 = OpConstant %float 6
+         %20 = OpConstantComposite %v3float %float_4 %float_5 %float_6
+    %float_7 = OpConstant %float 7
+    %float_8 = OpConstant %float 8
+    %float_9 = OpConstant %float 9
+         %24 = OpConstantComposite %v3float %float_7 %float_8 %float_9
+         %25 = OpConstantComposite %mat3v3float %16 %20 %24
+%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
+         %28 = OpConstantNull %mat3v3float
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %v3float None %5
+          %i = OpFunctionParameter %int
+         %11 = OpLabel
+%var_for_index = OpVariable %_ptr_Function_mat3v3float Function %28
+               OpStore %var_for_index %25
+         %30 = OpAccessChain %_ptr_Function_v3float %var_for_index %i
+         %31 = OpLoad %v3float %30
+               OpReturnValue %31
+               OpFunctionEnd
diff --git a/test/expressions/index/let/param/matrix.wgsl.expected.wgsl b/test/expressions/index/let/param/matrix.wgsl.expected.wgsl
new file mode 100644
index 0000000..dc0cff2
--- /dev/null
+++ b/test/expressions/index/let/param/matrix.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> vec3<f32> {
+  let m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  return m[i];
+}
diff --git a/test/expressions/index/let/param/vector.wgsl b/test/expressions/index/let/param/vector.wgsl
new file mode 100644
index 0000000..1aef165
--- /dev/null
+++ b/test/expressions/index/let/param/vector.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> f32 {
+  let v = vec3<f32>(1.0, 2.0, 3.0);
+  return v[i];
+}
diff --git a/test/expressions/index/let/param/vector.wgsl.expected.hlsl b/test/expressions/index/let/param/vector.wgsl.expected.hlsl
new file mode 100644
index 0000000..16cccbf
--- /dev/null
+++ b/test/expressions/index/let/param/vector.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float f(int i) {
+  const float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[i];
+}
diff --git a/test/expressions/index/let/param/vector.wgsl.expected.msl b/test/expressions/index/let/param/vector.wgsl.expected.msl
new file mode 100644
index 0000000..4d45110
--- /dev/null
+++ b/test/expressions/index/let/param/vector.wgsl.expected.msl
@@ -0,0 +1,8 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float f(int i) {
+  float3 const v = float3(1.0f, 2.0f, 3.0f);
+  return v[i];
+}
+
diff --git a/test/expressions/index/let/param/vector.wgsl.expected.spvasm b/test/expressions/index/let/param/vector.wgsl.expected.spvasm
new file mode 100644
index 0000000..96196dd
--- /dev/null
+++ b/test/expressions/index/let/param/vector.wgsl.expected.spvasm
@@ -0,0 +1,32 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 17
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %i "i"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %float %int
+    %v3float = OpTypeVector %float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %15 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %float None %5
+          %i = OpFunctionParameter %int
+         %10 = OpLabel
+         %16 = OpVectorExtractDynamic %float %15 %i
+               OpReturnValue %16
+               OpFunctionEnd
diff --git a/test/expressions/index/let/param/vector.wgsl.expected.wgsl b/test/expressions/index/let/param/vector.wgsl.expected.wgsl
new file mode 100644
index 0000000..1aef165
--- /dev/null
+++ b/test/expressions/index/let/param/vector.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> f32 {
+  let v = vec3<f32>(1.0, 2.0, 3.0);
+  return v[i];
+}
diff --git a/test/expressions/index/let/var/literal/array.wgsl b/test/expressions/index/let/var/literal/array.wgsl
new file mode 100644
index 0000000..c1781aa
--- /dev/null
+++ b/test/expressions/index/let/var/literal/array.wgsl
@@ -0,0 +1,5 @@
+fn f() -> i32 {
+  var a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  let i = 1;
+  return a[i];
+}
diff --git a/test/expressions/index/let/var/literal/array.wgsl.expected.hlsl b/test/expressions/index/let/var/literal/array.wgsl.expected.hlsl
new file mode 100644
index 0000000..4338718
--- /dev/null
+++ b/test/expressions/index/let/var/literal/array.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+int f() {
+  int a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+  return a[1];
+}
diff --git a/test/expressions/index/let/var/literal/array.wgsl.expected.msl b/test/expressions/index/let/var/literal/array.wgsl.expected.msl
new file mode 100644
index 0000000..808c688
--- /dev/null
+++ b/test/expressions/index/let/var/literal/array.wgsl.expected.msl
@@ -0,0 +1,13 @@
+#include <metal_stdlib>
+
+using namespace metal;
+struct tint_array_wrapper {
+  int arr[8];
+};
+
+int f() {
+  tint_array_wrapper a = {.arr={1, 2, 3, 4, 5, 6, 7, 8}};
+  int const i = 1;
+  return a.arr[i];
+}
+
diff --git a/test/expressions/index/let/var/literal/array.wgsl.expected.spvasm b/test/expressions/index/let/var/literal/array.wgsl.expected.spvasm
new file mode 100644
index 0000000..565f53e
--- /dev/null
+++ b/test/expressions/index/let/var/literal/array.wgsl.expected.spvasm
@@ -0,0 +1,44 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 27
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %a "a"
+               OpDecorate %_arr_int_uint_8 ArrayStride 4
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %int
+       %uint = OpTypeInt 32 0
+     %uint_8 = OpConstant %uint 8
+%_arr_int_uint_8 = OpTypeArray %int %uint_8
+      %int_1 = OpConstant %int 1
+      %int_2 = OpConstant %int 2
+      %int_3 = OpConstant %int 3
+      %int_4 = OpConstant %int 4
+      %int_5 = OpConstant %int 5
+      %int_6 = OpConstant %int 6
+      %int_7 = OpConstant %int 7
+      %int_8 = OpConstant %int 8
+         %20 = OpConstantComposite %_arr_int_uint_8 %int_1 %int_2 %int_3 %int_4 %int_5 %int_6 %int_7 %int_8
+%_ptr_Function__arr_int_uint_8 = OpTypePointer Function %_arr_int_uint_8
+         %23 = OpConstantNull %_arr_int_uint_8
+%_ptr_Function_int = OpTypePointer Function %int
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %int None %5
+          %8 = OpLabel
+          %a = OpVariable %_ptr_Function__arr_int_uint_8 Function %23
+               OpStore %a %20
+         %25 = OpAccessChain %_ptr_Function_int %a %int_1
+         %26 = OpLoad %int %25
+               OpReturnValue %26
+               OpFunctionEnd
diff --git a/test/expressions/index/let/var/literal/array.wgsl.expected.wgsl b/test/expressions/index/let/var/literal/array.wgsl.expected.wgsl
new file mode 100644
index 0000000..c1781aa
--- /dev/null
+++ b/test/expressions/index/let/var/literal/array.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f() -> i32 {
+  var a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  let i = 1;
+  return a[i];
+}
diff --git a/test/expressions/index/let/var/literal/matrix.wgsl b/test/expressions/index/let/var/literal/matrix.wgsl
new file mode 100644
index 0000000..a20885c
--- /dev/null
+++ b/test/expressions/index/let/var/literal/matrix.wgsl
@@ -0,0 +1,5 @@
+fn f() -> vec3<f32> {
+  var m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  let i = 1;
+  return m[i];
+}
diff --git a/test/expressions/index/let/var/literal/matrix.wgsl.expected.hlsl b/test/expressions/index/let/var/literal/matrix.wgsl.expected.hlsl
new file mode 100644
index 0000000..46a7995
--- /dev/null
+++ b/test/expressions/index/let/var/literal/matrix.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float3 f() {
+  float3x3 m = float3x3(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
+  return m[1];
+}
diff --git a/test/expressions/index/let/var/literal/matrix.wgsl.expected.msl b/test/expressions/index/let/var/literal/matrix.wgsl.expected.msl
new file mode 100644
index 0000000..0536bc1
--- /dev/null
+++ b/test/expressions/index/let/var/literal/matrix.wgsl.expected.msl
@@ -0,0 +1,9 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float3 f() {
+  float3x3 m = float3x3(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f));
+  int const i = 1;
+  return m[i];
+}
+
diff --git a/test/expressions/index/let/var/literal/matrix.wgsl.expected.spvasm b/test/expressions/index/let/var/literal/matrix.wgsl.expected.spvasm
new file mode 100644
index 0000000..be19a25
--- /dev/null
+++ b/test/expressions/index/let/var/literal/matrix.wgsl.expected.spvasm
@@ -0,0 +1,48 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 32
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %m "m"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+    %v3float = OpTypeVector %float 3
+          %5 = OpTypeFunction %v3float
+%mat3v3float = OpTypeMatrix %v3float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %14 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+    %float_4 = OpConstant %float 4
+    %float_5 = OpConstant %float 5
+    %float_6 = OpConstant %float 6
+         %18 = OpConstantComposite %v3float %float_4 %float_5 %float_6
+    %float_7 = OpConstant %float 7
+    %float_8 = OpConstant %float 8
+    %float_9 = OpConstant %float 9
+         %22 = OpConstantComposite %v3float %float_7 %float_8 %float_9
+         %23 = OpConstantComposite %mat3v3float %14 %18 %22
+%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
+         %26 = OpConstantNull %mat3v3float
+        %int = OpTypeInt 32 1
+      %int_1 = OpConstant %int 1
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %v3float None %5
+          %9 = OpLabel
+          %m = OpVariable %_ptr_Function_mat3v3float Function %26
+               OpStore %m %23
+         %30 = OpAccessChain %_ptr_Function_v3float %m %int_1
+         %31 = OpLoad %v3float %30
+               OpReturnValue %31
+               OpFunctionEnd
diff --git a/test/expressions/index/let/var/literal/matrix.wgsl.expected.wgsl b/test/expressions/index/let/var/literal/matrix.wgsl.expected.wgsl
new file mode 100644
index 0000000..a20885c
--- /dev/null
+++ b/test/expressions/index/let/var/literal/matrix.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f() -> vec3<f32> {
+  var m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  let i = 1;
+  return m[i];
+}
diff --git a/test/expressions/index/let/var/literal/vector.wgsl b/test/expressions/index/let/var/literal/vector.wgsl
new file mode 100644
index 0000000..74962a8
--- /dev/null
+++ b/test/expressions/index/let/var/literal/vector.wgsl
@@ -0,0 +1,5 @@
+fn f() -> f32 {
+  var v = vec3<f32>(1.0, 2.0, 3.0);
+  let i = 1;
+  return v[i];
+}
diff --git a/test/expressions/index/let/var/literal/vector.wgsl.expected.hlsl b/test/expressions/index/let/var/literal/vector.wgsl.expected.hlsl
new file mode 100644
index 0000000..7297f63
--- /dev/null
+++ b/test/expressions/index/let/var/literal/vector.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float f() {
+  float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[1];
+}
diff --git a/test/expressions/index/let/var/literal/vector.wgsl.expected.msl b/test/expressions/index/let/var/literal/vector.wgsl.expected.msl
new file mode 100644
index 0000000..07ca4fb
--- /dev/null
+++ b/test/expressions/index/let/var/literal/vector.wgsl.expected.msl
@@ -0,0 +1,9 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float f() {
+  float3 v = float3(1.0f, 2.0f, 3.0f);
+  int const i = 1;
+  return v[i];
+}
+
diff --git a/test/expressions/index/let/var/literal/vector.wgsl.expected.spvasm b/test/expressions/index/let/var/literal/vector.wgsl.expected.spvasm
new file mode 100644
index 0000000..fe71fc3
--- /dev/null
+++ b/test/expressions/index/let/var/literal/vector.wgsl.expected.spvasm
@@ -0,0 +1,38 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 22
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %v "v"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+          %5 = OpTypeFunction %float
+    %v3float = OpTypeVector %float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %13 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+         %16 = OpConstantNull %v3float
+        %int = OpTypeInt 32 1
+      %int_1 = OpConstant %int 1
+%_ptr_Function_float = OpTypePointer Function %float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %float None %5
+          %8 = OpLabel
+          %v = OpVariable %_ptr_Function_v3float Function %16
+               OpStore %v %13
+         %20 = OpAccessChain %_ptr_Function_float %v %int_1
+         %21 = OpLoad %float %20
+               OpReturnValue %21
+               OpFunctionEnd
diff --git a/test/expressions/index/let/var/literal/vector.wgsl.expected.wgsl b/test/expressions/index/let/var/literal/vector.wgsl.expected.wgsl
new file mode 100644
index 0000000..74962a8
--- /dev/null
+++ b/test/expressions/index/let/var/literal/vector.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f() -> f32 {
+  var v = vec3<f32>(1.0, 2.0, 3.0);
+  let i = 1;
+  return v[i];
+}
diff --git a/test/expressions/index/var/let/literal/array.wgsl b/test/expressions/index/var/let/literal/array.wgsl
new file mode 100644
index 0000000..c1781aa
--- /dev/null
+++ b/test/expressions/index/var/let/literal/array.wgsl
@@ -0,0 +1,5 @@
+fn f() -> i32 {
+  var a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  let i = 1;
+  return a[i];
+}
diff --git a/test/expressions/index/var/let/literal/array.wgsl.expected.hlsl b/test/expressions/index/var/let/literal/array.wgsl.expected.hlsl
new file mode 100644
index 0000000..4338718
--- /dev/null
+++ b/test/expressions/index/var/let/literal/array.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+int f() {
+  int a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+  return a[1];
+}
diff --git a/test/expressions/index/var/let/literal/array.wgsl.expected.msl b/test/expressions/index/var/let/literal/array.wgsl.expected.msl
new file mode 100644
index 0000000..808c688
--- /dev/null
+++ b/test/expressions/index/var/let/literal/array.wgsl.expected.msl
@@ -0,0 +1,13 @@
+#include <metal_stdlib>
+
+using namespace metal;
+struct tint_array_wrapper {
+  int arr[8];
+};
+
+int f() {
+  tint_array_wrapper a = {.arr={1, 2, 3, 4, 5, 6, 7, 8}};
+  int const i = 1;
+  return a.arr[i];
+}
+
diff --git a/test/expressions/index/var/let/literal/array.wgsl.expected.spvasm b/test/expressions/index/var/let/literal/array.wgsl.expected.spvasm
new file mode 100644
index 0000000..565f53e
--- /dev/null
+++ b/test/expressions/index/var/let/literal/array.wgsl.expected.spvasm
@@ -0,0 +1,44 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 27
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %a "a"
+               OpDecorate %_arr_int_uint_8 ArrayStride 4
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %int
+       %uint = OpTypeInt 32 0
+     %uint_8 = OpConstant %uint 8
+%_arr_int_uint_8 = OpTypeArray %int %uint_8
+      %int_1 = OpConstant %int 1
+      %int_2 = OpConstant %int 2
+      %int_3 = OpConstant %int 3
+      %int_4 = OpConstant %int 4
+      %int_5 = OpConstant %int 5
+      %int_6 = OpConstant %int 6
+      %int_7 = OpConstant %int 7
+      %int_8 = OpConstant %int 8
+         %20 = OpConstantComposite %_arr_int_uint_8 %int_1 %int_2 %int_3 %int_4 %int_5 %int_6 %int_7 %int_8
+%_ptr_Function__arr_int_uint_8 = OpTypePointer Function %_arr_int_uint_8
+         %23 = OpConstantNull %_arr_int_uint_8
+%_ptr_Function_int = OpTypePointer Function %int
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %int None %5
+          %8 = OpLabel
+          %a = OpVariable %_ptr_Function__arr_int_uint_8 Function %23
+               OpStore %a %20
+         %25 = OpAccessChain %_ptr_Function_int %a %int_1
+         %26 = OpLoad %int %25
+               OpReturnValue %26
+               OpFunctionEnd
diff --git a/test/expressions/index/var/let/literal/array.wgsl.expected.wgsl b/test/expressions/index/var/let/literal/array.wgsl.expected.wgsl
new file mode 100644
index 0000000..c1781aa
--- /dev/null
+++ b/test/expressions/index/var/let/literal/array.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f() -> i32 {
+  var a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  let i = 1;
+  return a[i];
+}
diff --git a/test/expressions/index/var/let/literal/matrix.wgsl b/test/expressions/index/var/let/literal/matrix.wgsl
new file mode 100644
index 0000000..a20885c
--- /dev/null
+++ b/test/expressions/index/var/let/literal/matrix.wgsl
@@ -0,0 +1,5 @@
+fn f() -> vec3<f32> {
+  var m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  let i = 1;
+  return m[i];
+}
diff --git a/test/expressions/index/var/let/literal/matrix.wgsl.expected.hlsl b/test/expressions/index/var/let/literal/matrix.wgsl.expected.hlsl
new file mode 100644
index 0000000..46a7995
--- /dev/null
+++ b/test/expressions/index/var/let/literal/matrix.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float3 f() {
+  float3x3 m = float3x3(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
+  return m[1];
+}
diff --git a/test/expressions/index/var/let/literal/matrix.wgsl.expected.msl b/test/expressions/index/var/let/literal/matrix.wgsl.expected.msl
new file mode 100644
index 0000000..0536bc1
--- /dev/null
+++ b/test/expressions/index/var/let/literal/matrix.wgsl.expected.msl
@@ -0,0 +1,9 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float3 f() {
+  float3x3 m = float3x3(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f));
+  int const i = 1;
+  return m[i];
+}
+
diff --git a/test/expressions/index/var/let/literal/matrix.wgsl.expected.spvasm b/test/expressions/index/var/let/literal/matrix.wgsl.expected.spvasm
new file mode 100644
index 0000000..be19a25
--- /dev/null
+++ b/test/expressions/index/var/let/literal/matrix.wgsl.expected.spvasm
@@ -0,0 +1,48 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 32
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %m "m"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+    %v3float = OpTypeVector %float 3
+          %5 = OpTypeFunction %v3float
+%mat3v3float = OpTypeMatrix %v3float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %14 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+    %float_4 = OpConstant %float 4
+    %float_5 = OpConstant %float 5
+    %float_6 = OpConstant %float 6
+         %18 = OpConstantComposite %v3float %float_4 %float_5 %float_6
+    %float_7 = OpConstant %float 7
+    %float_8 = OpConstant %float 8
+    %float_9 = OpConstant %float 9
+         %22 = OpConstantComposite %v3float %float_7 %float_8 %float_9
+         %23 = OpConstantComposite %mat3v3float %14 %18 %22
+%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
+         %26 = OpConstantNull %mat3v3float
+        %int = OpTypeInt 32 1
+      %int_1 = OpConstant %int 1
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %v3float None %5
+          %9 = OpLabel
+          %m = OpVariable %_ptr_Function_mat3v3float Function %26
+               OpStore %m %23
+         %30 = OpAccessChain %_ptr_Function_v3float %m %int_1
+         %31 = OpLoad %v3float %30
+               OpReturnValue %31
+               OpFunctionEnd
diff --git a/test/expressions/index/var/let/literal/matrix.wgsl.expected.wgsl b/test/expressions/index/var/let/literal/matrix.wgsl.expected.wgsl
new file mode 100644
index 0000000..a20885c
--- /dev/null
+++ b/test/expressions/index/var/let/literal/matrix.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f() -> vec3<f32> {
+  var m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  let i = 1;
+  return m[i];
+}
diff --git a/test/expressions/index/var/let/literal/vector.wgsl b/test/expressions/index/var/let/literal/vector.wgsl
new file mode 100644
index 0000000..74962a8
--- /dev/null
+++ b/test/expressions/index/var/let/literal/vector.wgsl
@@ -0,0 +1,5 @@
+fn f() -> f32 {
+  var v = vec3<f32>(1.0, 2.0, 3.0);
+  let i = 1;
+  return v[i];
+}
diff --git a/test/expressions/index/var/let/literal/vector.wgsl.expected.hlsl b/test/expressions/index/var/let/literal/vector.wgsl.expected.hlsl
new file mode 100644
index 0000000..7297f63
--- /dev/null
+++ b/test/expressions/index/var/let/literal/vector.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float f() {
+  float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[1];
+}
diff --git a/test/expressions/index/var/let/literal/vector.wgsl.expected.msl b/test/expressions/index/var/let/literal/vector.wgsl.expected.msl
new file mode 100644
index 0000000..07ca4fb
--- /dev/null
+++ b/test/expressions/index/var/let/literal/vector.wgsl.expected.msl
@@ -0,0 +1,9 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float f() {
+  float3 v = float3(1.0f, 2.0f, 3.0f);
+  int const i = 1;
+  return v[i];
+}
+
diff --git a/test/expressions/index/var/let/literal/vector.wgsl.expected.spvasm b/test/expressions/index/var/let/literal/vector.wgsl.expected.spvasm
new file mode 100644
index 0000000..fe71fc3
--- /dev/null
+++ b/test/expressions/index/var/let/literal/vector.wgsl.expected.spvasm
@@ -0,0 +1,38 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 22
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %v "v"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+          %5 = OpTypeFunction %float
+    %v3float = OpTypeVector %float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %13 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+         %16 = OpConstantNull %v3float
+        %int = OpTypeInt 32 1
+      %int_1 = OpConstant %int 1
+%_ptr_Function_float = OpTypePointer Function %float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %float None %5
+          %8 = OpLabel
+          %v = OpVariable %_ptr_Function_v3float Function %16
+               OpStore %v %13
+         %20 = OpAccessChain %_ptr_Function_float %v %int_1
+         %21 = OpLoad %float %20
+               OpReturnValue %21
+               OpFunctionEnd
diff --git a/test/expressions/index/var/let/literal/vector.wgsl.expected.wgsl b/test/expressions/index/var/let/literal/vector.wgsl.expected.wgsl
new file mode 100644
index 0000000..74962a8
--- /dev/null
+++ b/test/expressions/index/var/let/literal/vector.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f() -> f32 {
+  var v = vec3<f32>(1.0, 2.0, 3.0);
+  let i = 1;
+  return v[i];
+}
diff --git a/test/expressions/index/var/let/param/array.wgsl b/test/expressions/index/var/let/param/array.wgsl
new file mode 100644
index 0000000..ace4c30
--- /dev/null
+++ b/test/expressions/index/var/let/param/array.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> i32 {
+  var a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  let i = x;
+  return a[i];
+}
diff --git a/test/expressions/index/var/let/param/array.wgsl.expected.hlsl b/test/expressions/index/var/let/param/array.wgsl.expected.hlsl
new file mode 100644
index 0000000..09ebc7d
--- /dev/null
+++ b/test/expressions/index/var/let/param/array.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+int f(int x) {
+  int a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+  return a[x];
+}
diff --git a/test/expressions/index/var/let/param/array.wgsl.expected.msl b/test/expressions/index/var/let/param/array.wgsl.expected.msl
new file mode 100644
index 0000000..b1e207d
--- /dev/null
+++ b/test/expressions/index/var/let/param/array.wgsl.expected.msl
@@ -0,0 +1,13 @@
+#include <metal_stdlib>
+
+using namespace metal;
+struct tint_array_wrapper {
+  int arr[8];
+};
+
+int f(int x) {
+  tint_array_wrapper a = {.arr={1, 2, 3, 4, 5, 6, 7, 8}};
+  int const i = x;
+  return a.arr[i];
+}
+
diff --git a/test/expressions/index/var/let/param/array.wgsl.expected.spvasm b/test/expressions/index/var/let/param/array.wgsl.expected.spvasm
new file mode 100644
index 0000000..ca155d8
--- /dev/null
+++ b/test/expressions/index/var/let/param/array.wgsl.expected.spvasm
@@ -0,0 +1,46 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 28
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %x "x"
+               OpName %a "a"
+               OpDecorate %_arr_int_uint_8 ArrayStride 4
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %int %int
+       %uint = OpTypeInt 32 0
+     %uint_8 = OpConstant %uint 8
+%_arr_int_uint_8 = OpTypeArray %int %uint_8
+      %int_1 = OpConstant %int 1
+      %int_2 = OpConstant %int 2
+      %int_3 = OpConstant %int 3
+      %int_4 = OpConstant %int 4
+      %int_5 = OpConstant %int 5
+      %int_6 = OpConstant %int 6
+      %int_7 = OpConstant %int 7
+      %int_8 = OpConstant %int 8
+         %21 = OpConstantComposite %_arr_int_uint_8 %int_1 %int_2 %int_3 %int_4 %int_5 %int_6 %int_7 %int_8
+%_ptr_Function__arr_int_uint_8 = OpTypePointer Function %_arr_int_uint_8
+         %24 = OpConstantNull %_arr_int_uint_8
+%_ptr_Function_int = OpTypePointer Function %int
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %int None %5
+          %x = OpFunctionParameter %int
+          %9 = OpLabel
+          %a = OpVariable %_ptr_Function__arr_int_uint_8 Function %24
+               OpStore %a %21
+         %26 = OpAccessChain %_ptr_Function_int %a %x
+         %27 = OpLoad %int %26
+               OpReturnValue %27
+               OpFunctionEnd
diff --git a/test/expressions/index/var/let/param/array.wgsl.expected.wgsl b/test/expressions/index/var/let/param/array.wgsl.expected.wgsl
new file mode 100644
index 0000000..ace4c30
--- /dev/null
+++ b/test/expressions/index/var/let/param/array.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> i32 {
+  var a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  let i = x;
+  return a[i];
+}
diff --git a/test/expressions/index/var/let/param/matrix.wgsl b/test/expressions/index/var/let/param/matrix.wgsl
new file mode 100644
index 0000000..7b9043f
--- /dev/null
+++ b/test/expressions/index/var/let/param/matrix.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> vec3<f32> {
+  var m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  let i = x;
+  return m[i];
+}
diff --git a/test/expressions/index/var/let/param/matrix.wgsl.expected.hlsl b/test/expressions/index/var/let/param/matrix.wgsl.expected.hlsl
new file mode 100644
index 0000000..0920c91
--- /dev/null
+++ b/test/expressions/index/var/let/param/matrix.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float3 f(int x) {
+  float3x3 m = float3x3(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
+  return m[x];
+}
diff --git a/test/expressions/index/var/let/param/matrix.wgsl.expected.msl b/test/expressions/index/var/let/param/matrix.wgsl.expected.msl
new file mode 100644
index 0000000..f282e52
--- /dev/null
+++ b/test/expressions/index/var/let/param/matrix.wgsl.expected.msl
@@ -0,0 +1,9 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float3 f(int x) {
+  float3x3 m = float3x3(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f));
+  int const i = x;
+  return m[i];
+}
+
diff --git a/test/expressions/index/var/let/param/matrix.wgsl.expected.spvasm b/test/expressions/index/var/let/param/matrix.wgsl.expected.spvasm
new file mode 100644
index 0000000..6ba9971
--- /dev/null
+++ b/test/expressions/index/var/let/param/matrix.wgsl.expected.spvasm
@@ -0,0 +1,49 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 32
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %x "x"
+               OpName %m "m"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+    %v3float = OpTypeVector %float 3
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %v3float %int
+%mat3v3float = OpTypeMatrix %v3float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %16 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+    %float_4 = OpConstant %float 4
+    %float_5 = OpConstant %float 5
+    %float_6 = OpConstant %float 6
+         %20 = OpConstantComposite %v3float %float_4 %float_5 %float_6
+    %float_7 = OpConstant %float 7
+    %float_8 = OpConstant %float 8
+    %float_9 = OpConstant %float 9
+         %24 = OpConstantComposite %v3float %float_7 %float_8 %float_9
+         %25 = OpConstantComposite %mat3v3float %16 %20 %24
+%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
+         %28 = OpConstantNull %mat3v3float
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %v3float None %5
+          %x = OpFunctionParameter %int
+         %11 = OpLabel
+          %m = OpVariable %_ptr_Function_mat3v3float Function %28
+               OpStore %m %25
+         %30 = OpAccessChain %_ptr_Function_v3float %m %x
+         %31 = OpLoad %v3float %30
+               OpReturnValue %31
+               OpFunctionEnd
diff --git a/test/expressions/index/var/let/param/matrix.wgsl.expected.wgsl b/test/expressions/index/var/let/param/matrix.wgsl.expected.wgsl
new file mode 100644
index 0000000..7b9043f
--- /dev/null
+++ b/test/expressions/index/var/let/param/matrix.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> vec3<f32> {
+  var m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  let i = x;
+  return m[i];
+}
diff --git a/test/expressions/index/var/let/param/vector.wgsl b/test/expressions/index/var/let/param/vector.wgsl
new file mode 100644
index 0000000..f3e969b
--- /dev/null
+++ b/test/expressions/index/var/let/param/vector.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> f32 {
+  var v = vec3<f32>(1.0, 2.0, 3.0);
+  let i = x;
+  return v[i];
+}
diff --git a/test/expressions/index/var/let/param/vector.wgsl.expected.hlsl b/test/expressions/index/var/let/param/vector.wgsl.expected.hlsl
new file mode 100644
index 0000000..590b92e
--- /dev/null
+++ b/test/expressions/index/var/let/param/vector.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float f(int x) {
+  float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[x];
+}
diff --git a/test/expressions/index/var/let/param/vector.wgsl.expected.msl b/test/expressions/index/var/let/param/vector.wgsl.expected.msl
new file mode 100644
index 0000000..374fe2c
--- /dev/null
+++ b/test/expressions/index/var/let/param/vector.wgsl.expected.msl
@@ -0,0 +1,9 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float f(int x) {
+  float3 v = float3(1.0f, 2.0f, 3.0f);
+  int const i = x;
+  return v[i];
+}
+
diff --git a/test/expressions/index/var/let/param/vector.wgsl.expected.spvasm b/test/expressions/index/var/let/param/vector.wgsl.expected.spvasm
new file mode 100644
index 0000000..16da21e
--- /dev/null
+++ b/test/expressions/index/var/let/param/vector.wgsl.expected.spvasm
@@ -0,0 +1,39 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 22
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %x "x"
+               OpName %v "v"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %float %int
+    %v3float = OpTypeVector %float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %15 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+         %18 = OpConstantNull %v3float
+%_ptr_Function_float = OpTypePointer Function %float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %float None %5
+          %x = OpFunctionParameter %int
+         %10 = OpLabel
+          %v = OpVariable %_ptr_Function_v3float Function %18
+               OpStore %v %15
+         %20 = OpAccessChain %_ptr_Function_float %v %x
+         %21 = OpLoad %float %20
+               OpReturnValue %21
+               OpFunctionEnd
diff --git a/test/expressions/index/var/let/param/vector.wgsl.expected.wgsl b/test/expressions/index/var/let/param/vector.wgsl.expected.wgsl
new file mode 100644
index 0000000..f3e969b
--- /dev/null
+++ b/test/expressions/index/var/let/param/vector.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+fn f(x : i32) -> f32 {
+  var v = vec3<f32>(1.0, 2.0, 3.0);
+  let i = x;
+  return v[i];
+}
diff --git a/test/expressions/index/var/literal/array.wgsl b/test/expressions/index/var/literal/array.wgsl
new file mode 100644
index 0000000..ea2f45d
--- /dev/null
+++ b/test/expressions/index/var/literal/array.wgsl
@@ -0,0 +1,4 @@
+fn f() -> i32 {
+  var a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  return a[1];
+}
diff --git a/test/expressions/index/var/literal/array.wgsl.expected.hlsl b/test/expressions/index/var/literal/array.wgsl.expected.hlsl
new file mode 100644
index 0000000..4338718
--- /dev/null
+++ b/test/expressions/index/var/literal/array.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+int f() {
+  int a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+  return a[1];
+}
diff --git a/test/expressions/index/var/literal/array.wgsl.expected.msl b/test/expressions/index/var/literal/array.wgsl.expected.msl
new file mode 100644
index 0000000..ae2d9ca
--- /dev/null
+++ b/test/expressions/index/var/literal/array.wgsl.expected.msl
@@ -0,0 +1,12 @@
+#include <metal_stdlib>
+
+using namespace metal;
+struct tint_array_wrapper {
+  int arr[8];
+};
+
+int f() {
+  tint_array_wrapper a = {.arr={1, 2, 3, 4, 5, 6, 7, 8}};
+  return a.arr[1];
+}
+
diff --git a/test/expressions/index/var/literal/array.wgsl.expected.spvasm b/test/expressions/index/var/literal/array.wgsl.expected.spvasm
new file mode 100644
index 0000000..565f53e
--- /dev/null
+++ b/test/expressions/index/var/literal/array.wgsl.expected.spvasm
@@ -0,0 +1,44 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 27
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %a "a"
+               OpDecorate %_arr_int_uint_8 ArrayStride 4
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %int
+       %uint = OpTypeInt 32 0
+     %uint_8 = OpConstant %uint 8
+%_arr_int_uint_8 = OpTypeArray %int %uint_8
+      %int_1 = OpConstant %int 1
+      %int_2 = OpConstant %int 2
+      %int_3 = OpConstant %int 3
+      %int_4 = OpConstant %int 4
+      %int_5 = OpConstant %int 5
+      %int_6 = OpConstant %int 6
+      %int_7 = OpConstant %int 7
+      %int_8 = OpConstant %int 8
+         %20 = OpConstantComposite %_arr_int_uint_8 %int_1 %int_2 %int_3 %int_4 %int_5 %int_6 %int_7 %int_8
+%_ptr_Function__arr_int_uint_8 = OpTypePointer Function %_arr_int_uint_8
+         %23 = OpConstantNull %_arr_int_uint_8
+%_ptr_Function_int = OpTypePointer Function %int
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %int None %5
+          %8 = OpLabel
+          %a = OpVariable %_ptr_Function__arr_int_uint_8 Function %23
+               OpStore %a %20
+         %25 = OpAccessChain %_ptr_Function_int %a %int_1
+         %26 = OpLoad %int %25
+               OpReturnValue %26
+               OpFunctionEnd
diff --git a/test/expressions/index/var/literal/array.wgsl.expected.wgsl b/test/expressions/index/var/literal/array.wgsl.expected.wgsl
new file mode 100644
index 0000000..ea2f45d
--- /dev/null
+++ b/test/expressions/index/var/literal/array.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f() -> i32 {
+  var a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  return a[1];
+}
diff --git a/test/expressions/index/var/literal/matrix.wgsl b/test/expressions/index/var/literal/matrix.wgsl
new file mode 100644
index 0000000..8043ae4
--- /dev/null
+++ b/test/expressions/index/var/literal/matrix.wgsl
@@ -0,0 +1,4 @@
+fn f() -> vec3<f32> {
+  var m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  return m[1];
+}
diff --git a/test/expressions/index/var/literal/matrix.wgsl.expected.hlsl b/test/expressions/index/var/literal/matrix.wgsl.expected.hlsl
new file mode 100644
index 0000000..46a7995
--- /dev/null
+++ b/test/expressions/index/var/literal/matrix.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float3 f() {
+  float3x3 m = float3x3(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
+  return m[1];
+}
diff --git a/test/expressions/index/var/literal/matrix.wgsl.expected.msl b/test/expressions/index/var/literal/matrix.wgsl.expected.msl
new file mode 100644
index 0000000..e37137b
--- /dev/null
+++ b/test/expressions/index/var/literal/matrix.wgsl.expected.msl
@@ -0,0 +1,8 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float3 f() {
+  float3x3 m = float3x3(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f));
+  return m[1];
+}
+
diff --git a/test/expressions/index/var/literal/matrix.wgsl.expected.spvasm b/test/expressions/index/var/literal/matrix.wgsl.expected.spvasm
new file mode 100644
index 0000000..be19a25
--- /dev/null
+++ b/test/expressions/index/var/literal/matrix.wgsl.expected.spvasm
@@ -0,0 +1,48 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 32
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %m "m"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+    %v3float = OpTypeVector %float 3
+          %5 = OpTypeFunction %v3float
+%mat3v3float = OpTypeMatrix %v3float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %14 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+    %float_4 = OpConstant %float 4
+    %float_5 = OpConstant %float 5
+    %float_6 = OpConstant %float 6
+         %18 = OpConstantComposite %v3float %float_4 %float_5 %float_6
+    %float_7 = OpConstant %float 7
+    %float_8 = OpConstant %float 8
+    %float_9 = OpConstant %float 9
+         %22 = OpConstantComposite %v3float %float_7 %float_8 %float_9
+         %23 = OpConstantComposite %mat3v3float %14 %18 %22
+%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
+         %26 = OpConstantNull %mat3v3float
+        %int = OpTypeInt 32 1
+      %int_1 = OpConstant %int 1
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %v3float None %5
+          %9 = OpLabel
+          %m = OpVariable %_ptr_Function_mat3v3float Function %26
+               OpStore %m %23
+         %30 = OpAccessChain %_ptr_Function_v3float %m %int_1
+         %31 = OpLoad %v3float %30
+               OpReturnValue %31
+               OpFunctionEnd
diff --git a/test/expressions/index/var/literal/matrix.wgsl.expected.wgsl b/test/expressions/index/var/literal/matrix.wgsl.expected.wgsl
new file mode 100644
index 0000000..8043ae4
--- /dev/null
+++ b/test/expressions/index/var/literal/matrix.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f() -> vec3<f32> {
+  var m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  return m[1];
+}
diff --git a/test/expressions/index/var/literal/vector.wgsl b/test/expressions/index/var/literal/vector.wgsl
new file mode 100644
index 0000000..bd832ab
--- /dev/null
+++ b/test/expressions/index/var/literal/vector.wgsl
@@ -0,0 +1,4 @@
+fn f() -> f32 {
+  var v = vec3<f32>(1.0, 2.0, 3.0);
+  return v[1];
+}
diff --git a/test/expressions/index/var/literal/vector.wgsl.expected.hlsl b/test/expressions/index/var/literal/vector.wgsl.expected.hlsl
new file mode 100644
index 0000000..7297f63
--- /dev/null
+++ b/test/expressions/index/var/literal/vector.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float f() {
+  float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[1];
+}
diff --git a/test/expressions/index/var/literal/vector.wgsl.expected.msl b/test/expressions/index/var/literal/vector.wgsl.expected.msl
new file mode 100644
index 0000000..315ef51
--- /dev/null
+++ b/test/expressions/index/var/literal/vector.wgsl.expected.msl
@@ -0,0 +1,8 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float f() {
+  float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[1];
+}
+
diff --git a/test/expressions/index/var/literal/vector.wgsl.expected.spvasm b/test/expressions/index/var/literal/vector.wgsl.expected.spvasm
new file mode 100644
index 0000000..fe71fc3
--- /dev/null
+++ b/test/expressions/index/var/literal/vector.wgsl.expected.spvasm
@@ -0,0 +1,38 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 22
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %v "v"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+          %5 = OpTypeFunction %float
+    %v3float = OpTypeVector %float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %13 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+         %16 = OpConstantNull %v3float
+        %int = OpTypeInt 32 1
+      %int_1 = OpConstant %int 1
+%_ptr_Function_float = OpTypePointer Function %float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %float None %5
+          %8 = OpLabel
+          %v = OpVariable %_ptr_Function_v3float Function %16
+               OpStore %v %13
+         %20 = OpAccessChain %_ptr_Function_float %v %int_1
+         %21 = OpLoad %float %20
+               OpReturnValue %21
+               OpFunctionEnd
diff --git a/test/expressions/index/var/literal/vector.wgsl.expected.wgsl b/test/expressions/index/var/literal/vector.wgsl.expected.wgsl
new file mode 100644
index 0000000..bd832ab
--- /dev/null
+++ b/test/expressions/index/var/literal/vector.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f() -> f32 {
+  var v = vec3<f32>(1.0, 2.0, 3.0);
+  return v[1];
+}
diff --git a/test/expressions/index/var/param/array.wgsl b/test/expressions/index/var/param/array.wgsl
new file mode 100644
index 0000000..183d103
--- /dev/null
+++ b/test/expressions/index/var/param/array.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> i32 {
+  var a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  return a[i];
+}
diff --git a/test/expressions/index/var/param/array.wgsl.expected.hlsl b/test/expressions/index/var/param/array.wgsl.expected.hlsl
new file mode 100644
index 0000000..f0e32a0
--- /dev/null
+++ b/test/expressions/index/var/param/array.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+int f(int i) {
+  int a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+  return a[i];
+}
diff --git a/test/expressions/index/var/param/array.wgsl.expected.msl b/test/expressions/index/var/param/array.wgsl.expected.msl
new file mode 100644
index 0000000..9d03b80
--- /dev/null
+++ b/test/expressions/index/var/param/array.wgsl.expected.msl
@@ -0,0 +1,12 @@
+#include <metal_stdlib>
+
+using namespace metal;
+struct tint_array_wrapper {
+  int arr[8];
+};
+
+int f(int i) {
+  tint_array_wrapper a = {.arr={1, 2, 3, 4, 5, 6, 7, 8}};
+  return a.arr[i];
+}
+
diff --git a/test/expressions/index/var/param/array.wgsl.expected.spvasm b/test/expressions/index/var/param/array.wgsl.expected.spvasm
new file mode 100644
index 0000000..69364cb
--- /dev/null
+++ b/test/expressions/index/var/param/array.wgsl.expected.spvasm
@@ -0,0 +1,46 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 28
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %i "i"
+               OpName %a "a"
+               OpDecorate %_arr_int_uint_8 ArrayStride 4
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %int %int
+       %uint = OpTypeInt 32 0
+     %uint_8 = OpConstant %uint 8
+%_arr_int_uint_8 = OpTypeArray %int %uint_8
+      %int_1 = OpConstant %int 1
+      %int_2 = OpConstant %int 2
+      %int_3 = OpConstant %int 3
+      %int_4 = OpConstant %int 4
+      %int_5 = OpConstant %int 5
+      %int_6 = OpConstant %int 6
+      %int_7 = OpConstant %int 7
+      %int_8 = OpConstant %int 8
+         %21 = OpConstantComposite %_arr_int_uint_8 %int_1 %int_2 %int_3 %int_4 %int_5 %int_6 %int_7 %int_8
+%_ptr_Function__arr_int_uint_8 = OpTypePointer Function %_arr_int_uint_8
+         %24 = OpConstantNull %_arr_int_uint_8
+%_ptr_Function_int = OpTypePointer Function %int
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %int None %5
+          %i = OpFunctionParameter %int
+          %9 = OpLabel
+          %a = OpVariable %_ptr_Function__arr_int_uint_8 Function %24
+               OpStore %a %21
+         %26 = OpAccessChain %_ptr_Function_int %a %i
+         %27 = OpLoad %int %26
+               OpReturnValue %27
+               OpFunctionEnd
diff --git a/test/expressions/index/var/param/array.wgsl.expected.wgsl b/test/expressions/index/var/param/array.wgsl.expected.wgsl
new file mode 100644
index 0000000..183d103
--- /dev/null
+++ b/test/expressions/index/var/param/array.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> i32 {
+  var a = array<i32, 8>(1, 2, 3, 4, 5, 6, 7, 8);
+  return a[i];
+}
diff --git a/test/expressions/index/var/param/matrix.wgsl b/test/expressions/index/var/param/matrix.wgsl
new file mode 100644
index 0000000..7e249d7
--- /dev/null
+++ b/test/expressions/index/var/param/matrix.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> vec3<f32> {
+  var m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  return m[i];
+}
diff --git a/test/expressions/index/var/param/matrix.wgsl.expected.hlsl b/test/expressions/index/var/param/matrix.wgsl.expected.hlsl
new file mode 100644
index 0000000..2b104d6
--- /dev/null
+++ b/test/expressions/index/var/param/matrix.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float3 f(int i) {
+  float3x3 m = float3x3(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
+  return m[i];
+}
diff --git a/test/expressions/index/var/param/matrix.wgsl.expected.msl b/test/expressions/index/var/param/matrix.wgsl.expected.msl
new file mode 100644
index 0000000..3826f12
--- /dev/null
+++ b/test/expressions/index/var/param/matrix.wgsl.expected.msl
@@ -0,0 +1,8 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float3 f(int i) {
+  float3x3 m = float3x3(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f));
+  return m[i];
+}
+
diff --git a/test/expressions/index/var/param/matrix.wgsl.expected.spvasm b/test/expressions/index/var/param/matrix.wgsl.expected.spvasm
new file mode 100644
index 0000000..43a587a
--- /dev/null
+++ b/test/expressions/index/var/param/matrix.wgsl.expected.spvasm
@@ -0,0 +1,49 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 32
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %i "i"
+               OpName %m "m"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+    %v3float = OpTypeVector %float 3
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %v3float %int
+%mat3v3float = OpTypeMatrix %v3float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %16 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+    %float_4 = OpConstant %float 4
+    %float_5 = OpConstant %float 5
+    %float_6 = OpConstant %float 6
+         %20 = OpConstantComposite %v3float %float_4 %float_5 %float_6
+    %float_7 = OpConstant %float 7
+    %float_8 = OpConstant %float 8
+    %float_9 = OpConstant %float 9
+         %24 = OpConstantComposite %v3float %float_7 %float_8 %float_9
+         %25 = OpConstantComposite %mat3v3float %16 %20 %24
+%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
+         %28 = OpConstantNull %mat3v3float
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %v3float None %5
+          %i = OpFunctionParameter %int
+         %11 = OpLabel
+          %m = OpVariable %_ptr_Function_mat3v3float Function %28
+               OpStore %m %25
+         %30 = OpAccessChain %_ptr_Function_v3float %m %i
+         %31 = OpLoad %v3float %30
+               OpReturnValue %31
+               OpFunctionEnd
diff --git a/test/expressions/index/var/param/matrix.wgsl.expected.wgsl b/test/expressions/index/var/param/matrix.wgsl.expected.wgsl
new file mode 100644
index 0000000..7e249d7
--- /dev/null
+++ b/test/expressions/index/var/param/matrix.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> vec3<f32> {
+  var m = mat3x3<f32>(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+  return m[i];
+}
diff --git a/test/expressions/index/var/param/vector.wgsl b/test/expressions/index/var/param/vector.wgsl
new file mode 100644
index 0000000..8bf7c40
--- /dev/null
+++ b/test/expressions/index/var/param/vector.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> f32 {
+  var v = vec3<f32>(1.0, 2.0, 3.0);
+  return v[i];
+}
diff --git a/test/expressions/index/var/param/vector.wgsl.expected.hlsl b/test/expressions/index/var/param/vector.wgsl.expected.hlsl
new file mode 100644
index 0000000..d046c84
--- /dev/null
+++ b/test/expressions/index/var/param/vector.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+  return;
+}
+
+float f(int i) {
+  float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[i];
+}
diff --git a/test/expressions/index/var/param/vector.wgsl.expected.msl b/test/expressions/index/var/param/vector.wgsl.expected.msl
new file mode 100644
index 0000000..15f873e
--- /dev/null
+++ b/test/expressions/index/var/param/vector.wgsl.expected.msl
@@ -0,0 +1,8 @@
+#include <metal_stdlib>
+
+using namespace metal;
+float f(int i) {
+  float3 v = float3(1.0f, 2.0f, 3.0f);
+  return v[i];
+}
+
diff --git a/test/expressions/index/var/param/vector.wgsl.expected.spvasm b/test/expressions/index/var/param/vector.wgsl.expected.spvasm
new file mode 100644
index 0000000..b4951c8
--- /dev/null
+++ b/test/expressions/index/var/param/vector.wgsl.expected.spvasm
@@ -0,0 +1,39 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 22
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+               OpExecutionMode %unused_entry_point LocalSize 1 1 1
+               OpName %unused_entry_point "unused_entry_point"
+               OpName %f "f"
+               OpName %i "i"
+               OpName %v "v"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+      %float = OpTypeFloat 32
+        %int = OpTypeInt 32 1
+          %5 = OpTypeFunction %float %int
+    %v3float = OpTypeVector %float 3
+    %float_1 = OpConstant %float 1
+    %float_2 = OpConstant %float 2
+    %float_3 = OpConstant %float 3
+         %15 = OpConstantComposite %v3float %float_1 %float_2 %float_3
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+         %18 = OpConstantNull %v3float
+%_ptr_Function_float = OpTypePointer Function %float
+%unused_entry_point = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
+          %f = OpFunction %float None %5
+          %i = OpFunctionParameter %int
+         %10 = OpLabel
+          %v = OpVariable %_ptr_Function_v3float Function %18
+               OpStore %v %15
+         %20 = OpAccessChain %_ptr_Function_float %v %i
+         %21 = OpLoad %float %20
+               OpReturnValue %21
+               OpFunctionEnd
diff --git a/test/expressions/index/var/param/vector.wgsl.expected.wgsl b/test/expressions/index/var/param/vector.wgsl.expected.wgsl
new file mode 100644
index 0000000..8bf7c40
--- /dev/null
+++ b/test/expressions/index/var/param/vector.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f(i : i32) -> f32 {
+  var v = vec3<f32>(1.0, 2.0, 3.0);
+  return v[i];
+}
diff --git a/test/samples/triangle.wgsl b/test/samples/triangle.wgsl
index 5bbb43d..ba3cb52 100644
--- a/test/samples/triangle.wgsl
+++ b/test/samples/triangle.wgsl
@@ -13,13 +13,14 @@
 // limitations under the License.
 
 // Vertex shader
+let pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
+    vec2<f32>(0.0, 0.5),
+    vec2<f32>(-0.5, -0.5),
+    vec2<f32>(0.5, -0.5));
+
 [[stage(vertex)]]
 fn vtx_main([[builtin(vertex_index)]] VertexIndex : u32)
          -> [[builtin(position)]] vec4<f32> {
-  var pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
-      vec2<f32>(0.0, 0.5),
-      vec2<f32>(-0.5, -0.5),
-      vec2<f32>(0.5, -0.5));
   return vec4<f32>(pos[VertexIndex], 0.0, 1.0);
 }
 
diff --git a/test/samples/triangle.wgsl.expected.hlsl b/test/samples/triangle.wgsl.expected.hlsl
index 47ca492..c2bc195 100644
--- a/test/samples/triangle.wgsl.expected.hlsl
+++ b/test/samples/triangle.wgsl.expected.hlsl
@@ -1,3 +1,5 @@
+static const float2 pos[3] = {float2(0.0f, 0.5f), float2(-0.5f, -0.5f), float2(0.5f, -0.5f)};
+
 struct tint_symbol_1 {
   uint VertexIndex : SV_VertexID;
 };
@@ -6,7 +8,6 @@
 };
 
 float4 vtx_main_inner(uint VertexIndex) {
-  float2 pos[3] = {float2(0.0f, 0.5f), float2(-0.5f, -0.5f), float2(0.5f, -0.5f)};
   return float4(pos[VertexIndex], 0.0f, 1.0f);
 }
 
diff --git a/test/samples/triangle.wgsl.expected.msl b/test/samples/triangle.wgsl.expected.msl
index 7b4bccf..fa2cab6 100644
--- a/test/samples/triangle.wgsl.expected.msl
+++ b/test/samples/triangle.wgsl.expected.msl
@@ -1,18 +1,18 @@
 #include <metal_stdlib>
 
 using namespace metal;
-struct tint_symbol {
-  float4 value [[position]];
-};
 struct tint_array_wrapper {
   float2 arr[3];
 };
+struct tint_symbol {
+  float4 value [[position]];
+};
 struct tint_symbol_1 {
   float4 value [[color(0)]];
 };
 
+constant tint_array_wrapper pos = {.arr={float2(0.0f, 0.5f), float2(-0.5f, -0.5f), float2(0.5f, -0.5f)}};
 float4 vtx_main_inner(uint VertexIndex) {
-  tint_array_wrapper pos = {.arr={float2(0.0f, 0.5f), float2(-0.5f, -0.5f), float2(0.5f, -0.5f)}};
   return float4(pos.arr[VertexIndex], 0.0f, 1.0f);
 }
 
diff --git a/test/samples/triangle.wgsl.expected.spvasm b/test/samples/triangle.wgsl.expected.spvasm
index 3d2c238..1816286 100644
--- a/test/samples/triangle.wgsl.expected.spvasm
+++ b/test/samples/triangle.wgsl.expected.spvasm
@@ -12,9 +12,10 @@
                OpName %value "value"
                OpName %vertex_point_size "vertex_point_size"
                OpName %value_1 "value_1"
+               OpName %pos "pos"
                OpName %vtx_main_inner "vtx_main_inner"
                OpName %VertexIndex "VertexIndex"
-               OpName %pos "pos"
+               OpName %var_for_index "var_for_index"
                OpName %vtx_main "vtx_main"
                OpName %frag_main_inner "frag_main_inner"
                OpName %frag_main "frag_main"
@@ -35,17 +36,17 @@
          %11 = OpConstantNull %float
 %vertex_point_size = OpVariable %_ptr_Output_float Output %11
     %value_1 = OpVariable %_ptr_Output_v4float Output %8
-         %13 = OpTypeFunction %v4float %uint
     %v2float = OpTypeVector %float 2
      %uint_3 = OpConstant %uint 3
 %_arr_v2float_uint_3 = OpTypeArray %v2float %uint_3
     %float_0 = OpConstant %float 0
   %float_0_5 = OpConstant %float 0.5
-         %22 = OpConstantComposite %v2float %float_0 %float_0_5
+         %18 = OpConstantComposite %v2float %float_0 %float_0_5
  %float_n0_5 = OpConstant %float -0.5
-         %24 = OpConstantComposite %v2float %float_n0_5 %float_n0_5
-         %25 = OpConstantComposite %v2float %float_0_5 %float_n0_5
-         %26 = OpConstantComposite %_arr_v2float_uint_3 %22 %24 %25
+         %20 = OpConstantComposite %v2float %float_n0_5 %float_n0_5
+         %21 = OpConstantComposite %v2float %float_0_5 %float_n0_5
+        %pos = OpConstantComposite %_arr_v2float_uint_3 %18 %20 %21
+         %23 = OpTypeFunction %v4float %uint
 %_ptr_Function__arr_v2float_uint_3 = OpTypePointer Function %_arr_v2float_uint_3
          %29 = OpConstantNull %_arr_v2float_uint_3
 %_ptr_Function_v2float = OpTypePointer Function %v2float
@@ -54,12 +55,12 @@
          %37 = OpTypeFunction %void
          %43 = OpTypeFunction %v4float
          %46 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
-%vtx_main_inner = OpFunction %v4float None %13
+%vtx_main_inner = OpFunction %v4float None %23
 %VertexIndex = OpFunctionParameter %uint
-         %16 = OpLabel
-        %pos = OpVariable %_ptr_Function__arr_v2float_uint_3 Function %29
-               OpStore %pos %26
-         %31 = OpAccessChain %_ptr_Function_v2float %pos %VertexIndex
+         %26 = OpLabel
+%var_for_index = OpVariable %_ptr_Function__arr_v2float_uint_3 Function %29
+               OpStore %var_for_index %pos
+         %31 = OpAccessChain %_ptr_Function_v2float %var_for_index %VertexIndex
          %32 = OpLoad %v2float %31
          %33 = OpCompositeExtract %float %32 0
          %34 = OpCompositeExtract %float %32 1
diff --git a/test/samples/triangle.wgsl.expected.wgsl b/test/samples/triangle.wgsl.expected.wgsl
index 5e1145b..bd398e0 100644
--- a/test/samples/triangle.wgsl.expected.wgsl
+++ b/test/samples/triangle.wgsl.expected.wgsl
@@ -1,6 +1,7 @@
+let pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(vec2<f32>(0.0, 0.5), vec2<f32>(-0.5, -0.5), vec2<f32>(0.5, -0.5));
+
 [[stage(vertex)]]
 fn vtx_main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4<f32> {
-  var pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(vec2<f32>(0.0, 0.5), vec2<f32>(-0.5, -0.5), vec2<f32>(0.5, -0.5));
   return vec4<f32>(pos[VertexIndex], 0.0, 1.0);
 }
 
diff --git a/test/unittest/reader/spirv/SpvParserTest_VectorExtractDynamic_UnsignedIndex.spvasm b/test/unittest/reader/spirv/SpvParserTest_VectorExtractDynamic_UnsignedIndex.spvasm
index 30794bf..dc831e5 100644
--- a/test/unittest/reader/spirv/SpvParserTest_VectorExtractDynamic_UnsignedIndex.spvasm
+++ b/test/unittest/reader/spirv/SpvParserTest_VectorExtractDynamic_UnsignedIndex.spvasm
@@ -15,6 +15,7 @@
 %float = OpTypeFloat 32
 %uint_10 = OpConstant %uint 10
 %uint_20 = OpConstant %uint 20
+%uint_1 = OpConstant %uint 1
 %uint_3 = OpConstant %uint 3
 %uint_4 = OpConstant %uint 4
 %uint_5 = OpConstant %uint 5
@@ -41,7 +42,7 @@
 %100 = OpFunction %void None %4
 %34 = OpLabel
 %1 = OpCopyObject %v2uint %29
-%2 = OpCopyObject %uint %uint_3
+%2 = OpCopyObject %uint %uint_1
 %10 = OpVectorExtractDynamic %uint %1 %2
 OpReturn
 OpFunctionEnd