HoistToDeclBefore: revert hoisting of references

The goal of this utility is to hoist copies of expressions to ensure
order of evaluation of expressions. Hoisting references makes no
difference.

Bug: tint:1300
Change-Id: I3e7c2e53c9618aeb06836604e39383de016b072c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/81040
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/tint/transform/utils/hoist_to_decl_before.cc b/src/tint/transform/utils/hoist_to_decl_before.cc
index 3f66150..508b974 100644
--- a/src/tint/transform/utils/hoist_to_decl_before.cc
+++ b/src/tint/transform/utils/hoist_to_decl_before.cc
@@ -266,23 +266,12 @@
   bool HoistToDeclBefore(const sem::Expression* before_expr,
                          const ast::Expression* expr,
                          bool as_const,
-                         const char* decl_name = "") {
+                         const char* decl_name) {
     auto name = b.Symbols().New(decl_name);
 
-    auto* sem_expr = ctx.src->Sem().Get(expr);
-    bool is_ref =
-        sem_expr &&
-        !sem_expr->Is<sem::VariableUser>()  // Don't need to take a ref to a var
-        && sem_expr->Type()->Is<sem::Reference>();
-
-    auto* expr_clone = ctx.Clone(expr);
-    if (is_ref) {
-      expr_clone = b.AddressOf(expr_clone);
-    }
-
     // Construct the let/var that holds the hoisted expr
-    auto* v = as_const ? b.Const(name, nullptr, expr_clone)
-                       : b.Var(name, nullptr, expr_clone);
+    auto* v = as_const ? b.Const(name, nullptr, ctx.Clone(expr))
+                       : b.Var(name, nullptr, ctx.Clone(expr));
     auto* decl = b.Decl(v);
 
     if (!InsertBefore(before_expr, decl)) {
@@ -290,11 +279,7 @@
     }
 
     // Replace the initializer expression with a reference to the let
-    const ast::Expression* new_expr = b.Expr(name);
-    if (is_ref) {
-      new_expr = b.Deref(new_expr);
-    }
-    ctx.Replace(expr, new_expr);
+    ctx.Replace(expr, b.Expr(name));
     return true;
   }
 
diff --git a/src/tint/transform/utils/hoist_to_decl_before_test.cc b/src/tint/transform/utils/hoist_to_decl_before_test.cc
index 2e6f0ab..70dc8bc 100644
--- a/src/tint/transform/utils/hoist_to_decl_before_test.cc
+++ b/src/tint/transform/utils/hoist_to_decl_before_test.cc
@@ -243,8 +243,8 @@
   auto* expect = R"(
 fn f() {
   var a : array<i32, 10>;
-  let tint_symbol = &(a[0]);
-  var b = *(tint_symbol);
+  let tint_symbol = a[0];
+  var b = tint_symbol;
 }
 )";
 
@@ -279,8 +279,8 @@
   auto* expect = R"(
 fn f() {
   var a : array<array<i32, 10>, 10>;
-  let tint_symbol = &(a[0][0]);
-  var b = *(tint_symbol);
+  let tint_symbol = a[0][0];
+  var b = tint_symbol;
 }
 )";