Const eval for `distance`

This CL adds const-eval for the `distance` builtin.

Bug: tint:1581
Change-Id: Iee3af6474ace8e7baa230156f582f0a372f77cb7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/111583
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/intrinsics.def b/src/tint/intrinsics.def
index 11e1a3c..0752d5a 100644
--- a/src/tint/intrinsics.def
+++ b/src/tint/intrinsics.def
@@ -443,8 +443,8 @@
 @const fn degrees<T: fa_f32_f16>(T) -> T
 @const fn degrees<N: num, T: fa_f32_f16>(vec<N, T>) -> vec<N, T>
 @const fn determinant<N: num, T: fa_f32_f16>(mat<N, N, T>) -> T
-fn distance<T: f32_f16>(T, T) -> T
-fn distance<N: num, T: f32_f16>(vec<N, T>, vec<N, T>) -> T
+@const fn distance<T: fa_f32_f16>(T, T) -> T
+@const fn distance<N: num, T: fa_f32_f16>(vec<N, T>, vec<N, T>) -> T
 @const fn dot<N: num, T: fia_fiu32_f16>(vec<N, T>, vec<N, T>) -> T
 fn dot4I8Packed(u32, u32) -> i32
 fn dot4U8Packed(u32, u32) -> u32
diff --git a/src/tint/resolver/builtin_test.cc b/src/tint/resolver/builtin_test.cc
index 44f4bc5..ece7656 100644
--- a/src/tint/resolver/builtin_test.cc
+++ b/src/tint/resolver/builtin_test.cc
@@ -882,8 +882,8 @@
     EXPECT_EQ(r()->error(), R"(error: no matching call to distance(vec3<f32>, vec3<f32>, vec3<f32>)
 
 2 candidate functions:
-  distance(T, T) -> T  where: T is f32 or f16
-  distance(vecN<T>, vecN<T>) -> T  where: T is f32 or f16
+  distance(T, T) -> T  where: T is abstract-float, f32 or f16
+  distance(vecN<T>, vecN<T>) -> T  where: T is abstract-float, f32 or f16
 )");
 }
 
@@ -896,8 +896,8 @@
     EXPECT_EQ(r()->error(), R"(error: no matching call to distance(vec3<f32>)
 
 2 candidate functions:
-  distance(T, T) -> T  where: T is f32 or f16
-  distance(vecN<T>, vecN<T>) -> T  where: T is f32 or f16
+  distance(T, T) -> T  where: T is abstract-float, f32 or f16
+  distance(vecN<T>, vecN<T>) -> T  where: T is abstract-float, f32 or f16
 )");
 }
 
@@ -910,8 +910,8 @@
     EXPECT_EQ(r()->error(), R"(error: no matching call to distance()
 
 2 candidate functions:
-  distance(T, T) -> T  where: T is f32 or f16
-  distance(vecN<T>, vecN<T>) -> T  where: T is f32 or f16
+  distance(T, T) -> T  where: T is abstract-float, f32 or f16
+  distance(vecN<T>, vecN<T>) -> T  where: T is abstract-float, f32 or f16
 )");
 }
 
diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc
index 27630c7..424cd82 100644
--- a/src/tint/resolver/const_eval.cc
+++ b/src/tint/resolver/const_eval.cc
@@ -1165,6 +1165,27 @@
     return utils::Failure;
 }
 
+ConstEval::Result ConstEval::Length(const Source& source,
+                                    const sem::Type* ty,
+                                    const sem::Constant* c0) {
+    auto* vec_ty = c0->Type()->As<sem::Vector>();
+    // Evaluates to the absolute value of e if T is scalar.
+    if (vec_ty == nullptr) {
+        auto create = [&](auto e) {
+            using NumberT = decltype(e);
+            return CreateElement(builder, source, ty, NumberT{std::abs(e)});
+        };
+        return Dispatch_fa_f32_f16(create, c0);
+    }
+
+    // Evaluates to sqrt(e[0]^2 + e[1]^2 + ...) if T is a vector type.
+    auto d = Dot(source, c0, c0);
+    if (!d) {
+        return utils::Failure;
+    }
+    return Dispatch_fa_f32_f16(SqrtFunc(source, ty), d.Get());
+}
+
 auto ConstEval::Det2Func(const Source& source, const sem::Type* elem_ty) {
     return [=](auto a, auto b, auto c, auto d) -> ImplResult {
         if (auto r = Det2(source, a, b, c, d)) {
@@ -2221,6 +2242,27 @@
     }
     return r;
 }
+
+ConstEval::Result ConstEval::distance(const sem::Type* ty,
+                                      utils::VectorRef<const sem::Constant*> args,
+                                      const Source& source) {
+    auto err = [&]() -> ImplResult {
+        AddNote("when calculating distance", source);
+        return utils::Failure;
+    };
+
+    auto minus = OpMinus(args[0]->Type(), args, source);
+    if (!minus) {
+        return err();
+    }
+
+    auto len = Length(source, ty, minus.Get());
+    if (!len) {
+        return err();
+    }
+    return len;
+}
+
 ConstEval::Result ConstEval::dot(const sem::Type*,
                                  utils::VectorRef<const sem::Constant*> args,
                                  const Source& source) {
@@ -2566,26 +2608,7 @@
 ConstEval::Result ConstEval::length(const sem::Type* ty,
                                     utils::VectorRef<const sem::Constant*> args,
                                     const Source& source) {
-    auto calculate = [&]() -> ImplResult {
-        auto* vec_ty = args[0]->Type()->As<sem::Vector>();
-
-        // Evaluates to the absolute value of e if T is scalar.
-        if (vec_ty == nullptr) {
-            auto create = [&](auto e) {
-                using NumberT = decltype(e);
-                return CreateElement(builder, source, ty, NumberT{std::abs(e)});
-            };
-            return Dispatch_fa_f32_f16(create, args[0]);
-        }
-
-        // Evaluates to sqrt(e[0]^2 + e[1]^2 + ...) if T is a vector type.
-        auto d = Dot(source, args[0], args[0]);
-        if (!d) {
-            return utils::Failure;
-        }
-        return Dispatch_fa_f32_f16(SqrtFunc(source, ty), d.Get());
-    };
-    auto r = calculate();
+    auto r = Length(source, ty, args[0]);
     if (!r) {
         AddNote("when calculating length", source);
     }
diff --git a/src/tint/resolver/const_eval.h b/src/tint/resolver/const_eval.h
index 6f46ef2..33ec0a4 100644
--- a/src/tint/resolver/const_eval.h
+++ b/src/tint/resolver/const_eval.h
@@ -557,6 +557,15 @@
                        utils::VectorRef<const sem::Constant*> args,
                        const Source& source);
 
+    /// distance builtin
+    /// @param ty the expression type
+    /// @param args the input arguments
+    /// @param source the source location of the conversion
+    /// @return the result value, or null if the value cannot be calculated
+    Result distance(const sem::Type* ty,
+                    utils::VectorRef<const sem::Constant*> args,
+                    const Source& source);
+
     /// dot builtin
     /// @param ty the expression type
     /// @param args the input arguments
@@ -1225,6 +1234,13 @@
     /// @returns the dot product
     Result Dot(const Source& source, const sem::Constant* v1, const sem::Constant* v2);
 
+    /// Return sthe length of c0
+    /// @param source the source location
+    /// @param ty the return type
+    /// @param c0 the constant to calculate the length of
+    /// @returns the length of c0
+    Result Length(const Source& source, const sem::Type* ty, const sem::Constant* c0);
+
     ProgramBuilder& builder;
 };
 
diff --git a/src/tint/resolver/const_eval_builtin_test.cc b/src/tint/resolver/const_eval_builtin_test.cc
index d031a35..9c55323 100644
--- a/src/tint/resolver/const_eval_builtin_test.cc
+++ b/src/tint/resolver/const_eval_builtin_test.cc
@@ -803,6 +803,33 @@
                                               CrossCases<f16>()))));
 
 template <typename T>
+std::vector<Case> DistanceCases() {
+    auto error_msg = [](auto a, const char* op, auto b) {
+        return "12:34 error: " + OverflowErrorMessage(a, op, b) + R"(
+12:34 note: when calculating distance)";
+    };
+
+    return std::vector<Case>{
+        C({T(0), T(0)}, T(0)),
+        // length(-5) -> 5
+        C({T(30), T(35)}, T(5)),
+
+        C({Vec(T(30), T(20)), Vec(T(25), T(15))}, Val(T(7.0710678119))).FloatComp(),
+
+        E({T::Lowest(), T::Highest()}, error_msg(T::Lowest(), "-", T::Highest())),
+        E({Vec(T::Highest(), T::Highest()), Vec(T(1), T(1))},
+          error_msg(T(T::Highest() - T(1)), "*", T(T::Highest() - T(1)))),
+    };
+}
+INSTANTIATE_TEST_SUITE_P(  //
+    Distance,
+    ResolverConstEvalBuiltinTest,
+    testing::Combine(testing::Values(sem::BuiltinType::kDistance),
+                     testing::ValuesIn(Concat(DistanceCases<AFloat>(),  //
+                                              DistanceCases<f32>(),     //
+                                              DistanceCases<f16>()))));
+
+template <typename T>
 std::vector<Case> DotCases() {
     auto r = std::vector<Case>{
         C({Vec(T(0), T(0)), Vec(T(0), T(0))}, Val(T(0))),
diff --git a/src/tint/resolver/intrinsic_table.inl b/src/tint/resolver/intrinsic_table.inl
index 3ee8aca..e213f81 100644
--- a/src/tint/resolver/intrinsic_table.inl
+++ b/src/tint/resolver/intrinsic_table.inl
@@ -12198,24 +12198,24 @@
     /* num parameters */ 2,
     /* num template types */ 1,
     /* num template numbers */ 0,
-    /* template types */ &kTemplateTypes[26],
+    /* template types */ &kTemplateTypes[23],
     /* template numbers */ &kTemplateNumbers[10],
     /* parameters */ &kParameters[600],
     /* return matcher indices */ &kMatcherIndices[3],
     /* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
-    /* const eval */ nullptr,
+    /* const eval */ &ConstEval::distance,
   },
   {
     /* [324] */
     /* num parameters */ 2,
     /* num template types */ 1,
     /* num template numbers */ 1,
-    /* template types */ &kTemplateTypes[26],
+    /* template types */ &kTemplateTypes[23],
     /* template numbers */ &kTemplateNumbers[4],
     /* parameters */ &kParameters[602],
     /* return matcher indices */ &kMatcherIndices[3],
     /* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
-    /* const eval */ nullptr,
+    /* const eval */ &ConstEval::distance,
   },
   {
     /* [325] */
@@ -14130,8 +14130,8 @@
   },
   {
     /* [21] */
-    /* fn distance<T : f32_f16>(T, T) -> T */
-    /* fn distance<N : num, T : f32_f16>(vec<N, T>, vec<N, T>) -> T */
+    /* fn distance<T : fa_f32_f16>(T, T) -> T */
+    /* fn distance<N : num, T : fa_f32_f16>(vec<N, T>, vec<N, T>) -> T */
     /* num overloads */ 2,
     /* overloads */ &kOverloads[323],
   },
diff --git a/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.dxc.hlsl
index 192c046..f3cfc1c 100644
--- a/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void distance_0657d4() {
-  float res = distance((1.0f).xxx, (1.0f).xxx);
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.fxc.hlsl
index 192c046..f3cfc1c 100644
--- a/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void distance_0657d4() {
-  float res = distance((1.0f).xxx, (1.0f).xxx);
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.glsl
index 4792eb8..ed0378f 100644
--- a/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.glsl
@@ -1,7 +1,7 @@
 #version 310 es
 
 void distance_0657d4() {
-  float res = distance(vec3(1.0f), vec3(1.0f));
+  float res = 0.0f;
 }
 
 vec4 vertex_main() {
@@ -21,7 +21,7 @@
 precision mediump float;
 
 void distance_0657d4() {
-  float res = distance(vec3(1.0f), vec3(1.0f));
+  float res = 0.0f;
 }
 
 void fragment_main() {
@@ -35,7 +35,7 @@
 #version 310 es
 
 void distance_0657d4() {
-  float res = distance(vec3(1.0f), vec3(1.0f));
+  float res = 0.0f;
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.msl
index b61c9fb..2418aa3 100644
--- a/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void distance_0657d4() {
-  float res = distance(float3(1.0f), float3(1.0f));
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.spvasm
index 6b0a28a..6968ef0 100644
--- a/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/distance/0657d4.wgsl.expected.spvasm
@@ -1,10 +1,9 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 33
+; Bound: 29
 ; Schema: 0
                OpCapability Shader
-         %14 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -31,37 +30,34 @@
 %vertex_point_size = OpVariable %_ptr_Output_float Output %8
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
-    %v3float = OpTypeVector %float 3
-    %float_1 = OpConstant %float 1
-         %17 = OpConstantComposite %v3float %float_1 %float_1 %float_1
 %_ptr_Function_float = OpTypePointer Function %float
-         %20 = OpTypeFunction %v4float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
 %distance_0657d4 = OpFunction %void None %9
          %12 = OpLabel
         %res = OpVariable %_ptr_Function_float Function %8
-         %13 = OpExtInst %float %14 Distance %17 %17
-               OpStore %res %13
+               OpStore %res %8
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %20
-         %22 = OpLabel
-         %23 = OpFunctionCall %void %distance_0657d4
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_0657d4
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %25 = OpLabel
-         %26 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %26
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %28 = OpLabel
-         %29 = OpFunctionCall %void %distance_0657d4
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_0657d4
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %31 = OpLabel
-         %32 = OpFunctionCall %void %distance_0657d4
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_0657d4
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/3a175a.wgsl b/test/tint/builtins/gen/literal/distance/3a175a.wgsl
new file mode 100644
index 0000000..b229dd1
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/3a175a.wgsl
@@ -0,0 +1,43 @@
+// Copyright 2022 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.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn distance(vec<2, fa>, vec<2, fa>) -> fa
+fn distance_3a175a() {
+  var res = distance(vec2(1.), vec2(1.));
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_3a175a();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_3a175a();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_3a175a();
+}
diff --git a/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..2bc4567
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_3a175a();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_3a175a();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_3a175a();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..2bc4567
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_3a175a();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_3a175a();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_3a175a();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.glsl
new file mode 100644
index 0000000..58e8f50
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+vec4 vertex_main() {
+  distance_3a175a();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+void fragment_main() {
+  distance_3a175a();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+void compute_main() {
+  distance_3a175a();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.msl
new file mode 100644
index 0000000..4273f3f
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  distance_3a175a();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  distance_3a175a();
+  return;
+}
+
+kernel void compute_main() {
+  distance_3a175a();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.spvasm
new file mode 100644
index 0000000..393637d
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.spvasm
@@ -0,0 +1,63 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 29
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %distance_3a175a "distance_3a175a"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+%_ptr_Function_float = OpTypePointer Function %float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%distance_3a175a = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_float Function %8
+               OpStore %res %8
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_3a175a
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_3a175a
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_3a175a
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.wgsl
new file mode 100644
index 0000000..1dac42f
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/3a175a.wgsl.expected.wgsl
@@ -0,0 +1,19 @@
+fn distance_3a175a() {
+  var res = distance(vec2(1.0), vec2(1.0));
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_3a175a();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_3a175a();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_3a175a();
+}
diff --git a/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.dxc.hlsl
index 43150f3..9975d15 100644
--- a/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void distance_7272f3() {
-  float16_t res = distance((float16_t(1.0h)).xxxx, (float16_t(1.0h)).xxxx);
+  float16_t res = float16_t(0.0h);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.glsl
index def5558..80ea586 100644
--- a/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.glsl
@@ -2,7 +2,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void distance_7272f3() {
-  float16_t res = distance(f16vec4(1.0hf), f16vec4(1.0hf));
+  float16_t res = 0.0hf;
 }
 
 vec4 vertex_main() {
@@ -23,7 +23,7 @@
 precision mediump float;
 
 void distance_7272f3() {
-  float16_t res = distance(f16vec4(1.0hf), f16vec4(1.0hf));
+  float16_t res = 0.0hf;
 }
 
 void fragment_main() {
@@ -38,7 +38,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void distance_7272f3() {
-  float16_t res = distance(f16vec4(1.0hf), f16vec4(1.0hf));
+  float16_t res = 0.0hf;
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.msl
index 881f168..21b5578 100644
--- a/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void distance_7272f3() {
-  half res = distance(half4(1.0h), half4(1.0h));
+  half res = 0.0h;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.spvasm
index 508e80c..4caa4ef 100644
--- a/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/distance/7272f3.wgsl.expected.spvasm
@@ -1,14 +1,13 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 36
+; Bound: 31
 ; Schema: 0
                OpCapability Shader
                OpCapability Float16
                OpCapability UniformAndStorageBuffer16BitAccess
                OpCapability StorageBuffer16BitAccess
                OpCapability StorageInputOutput16
-         %15 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -36,39 +35,35 @@
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
        %half = OpTypeFloat 16
-     %v4half = OpTypeVector %half 4
-%half_0x1p_0 = OpConstant %half 0x1p+0
-         %18 = OpConstantComposite %v4half %half_0x1p_0 %half_0x1p_0 %half_0x1p_0 %half_0x1p_0
+         %14 = OpConstantNull %half
 %_ptr_Function_half = OpTypePointer Function %half
-         %21 = OpConstantNull %half
-         %22 = OpTypeFunction %v4float
+         %17 = OpTypeFunction %v4float
     %float_1 = OpConstant %float 1
 %distance_7272f3 = OpFunction %void None %9
          %12 = OpLabel
-        %res = OpVariable %_ptr_Function_half Function %21
-         %13 = OpExtInst %half %15 Distance %18 %18
-               OpStore %res %13
+        %res = OpVariable %_ptr_Function_half Function %14
+               OpStore %res %14
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %22
-         %24 = OpLabel
-         %25 = OpFunctionCall %void %distance_7272f3
+%vertex_main_inner = OpFunction %v4float None %17
+         %19 = OpLabel
+         %20 = OpFunctionCall %void %distance_7272f3
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %27 = OpLabel
-         %28 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %28
+         %22 = OpLabel
+         %23 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %23
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %31 = OpLabel
-         %32 = OpFunctionCall %void %distance_7272f3
+         %26 = OpLabel
+         %27 = OpFunctionCall %void %distance_7272f3
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %34 = OpLabel
-         %35 = OpFunctionCall %void %distance_7272f3
+         %29 = OpLabel
+         %30 = OpFunctionCall %void %distance_7272f3
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.dxc.hlsl
index d8b616f..5de1ed2 100644
--- a/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void distance_7d201f() {
-  float16_t res = distance(float16_t(1.0h), float16_t(1.0h));
+  float16_t res = float16_t(0.0h);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.glsl
index 00663ec..b2cc1bd 100644
--- a/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.glsl
@@ -2,7 +2,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void distance_7d201f() {
-  float16_t res = distance(1.0hf, 1.0hf);
+  float16_t res = 0.0hf;
 }
 
 vec4 vertex_main() {
@@ -23,7 +23,7 @@
 precision mediump float;
 
 void distance_7d201f() {
-  float16_t res = distance(1.0hf, 1.0hf);
+  float16_t res = 0.0hf;
 }
 
 void fragment_main() {
@@ -38,7 +38,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void distance_7d201f() {
-  float16_t res = distance(1.0hf, 1.0hf);
+  float16_t res = 0.0hf;
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.msl
index fc5149e..0a0b634 100644
--- a/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void distance_7d201f() {
-  half res = fabs(1.0h - 1.0h);
+  half res = 0.0h;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.spvasm
index e5a3ac2..90dbc0d 100644
--- a/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/distance/7d201f.wgsl.expected.spvasm
@@ -1,14 +1,13 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 34
+; Bound: 31
 ; Schema: 0
                OpCapability Shader
                OpCapability Float16
                OpCapability UniformAndStorageBuffer16BitAccess
                OpCapability StorageBuffer16BitAccess
                OpCapability StorageInputOutput16
-         %15 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -36,37 +35,35 @@
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
        %half = OpTypeFloat 16
-%half_0x1p_0 = OpConstant %half 0x1p+0
+         %14 = OpConstantNull %half
 %_ptr_Function_half = OpTypePointer Function %half
-         %19 = OpConstantNull %half
-         %20 = OpTypeFunction %v4float
+         %17 = OpTypeFunction %v4float
     %float_1 = OpConstant %float 1
 %distance_7d201f = OpFunction %void None %9
          %12 = OpLabel
-        %res = OpVariable %_ptr_Function_half Function %19
-         %13 = OpExtInst %half %15 Distance %half_0x1p_0 %half_0x1p_0
-               OpStore %res %13
+        %res = OpVariable %_ptr_Function_half Function %14
+               OpStore %res %14
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %20
-         %22 = OpLabel
-         %23 = OpFunctionCall %void %distance_7d201f
+%vertex_main_inner = OpFunction %v4float None %17
+         %19 = OpLabel
+         %20 = OpFunctionCall %void %distance_7d201f
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %25 = OpLabel
-         %26 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %26
+         %22 = OpLabel
+         %23 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %23
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %29 = OpLabel
-         %30 = OpFunctionCall %void %distance_7d201f
+         %26 = OpLabel
+         %27 = OpFunctionCall %void %distance_7d201f
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %32 = OpLabel
-         %33 = OpFunctionCall %void %distance_7d201f
+         %29 = OpLabel
+         %30 = OpFunctionCall %void %distance_7d201f
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/83911f.wgsl b/test/tint/builtins/gen/literal/distance/83911f.wgsl
new file mode 100644
index 0000000..ab9bc91
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/83911f.wgsl
@@ -0,0 +1,43 @@
+// Copyright 2022 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.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn distance(vec<3, fa>, vec<3, fa>) -> fa
+fn distance_83911f() {
+  var res = distance(vec3(1.), vec3(1.));
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_83911f();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_83911f();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_83911f();
+}
diff --git a/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..7fe07e2
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_83911f();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_83911f();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_83911f();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..7fe07e2
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_83911f();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_83911f();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_83911f();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.glsl
new file mode 100644
index 0000000..7486548
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+vec4 vertex_main() {
+  distance_83911f();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+void fragment_main() {
+  distance_83911f();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+void compute_main() {
+  distance_83911f();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.msl
new file mode 100644
index 0000000..a810881
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  distance_83911f();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  distance_83911f();
+  return;
+}
+
+kernel void compute_main() {
+  distance_83911f();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.spvasm
new file mode 100644
index 0000000..42ac8e2
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.spvasm
@@ -0,0 +1,63 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 29
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %distance_83911f "distance_83911f"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+%_ptr_Function_float = OpTypePointer Function %float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%distance_83911f = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_float Function %8
+               OpStore %res %8
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_83911f
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_83911f
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_83911f
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.wgsl
new file mode 100644
index 0000000..ce8c81a
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/83911f.wgsl.expected.wgsl
@@ -0,0 +1,19 @@
+fn distance_83911f() {
+  var res = distance(vec3(1.0), vec3(1.0));
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_83911f();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_83911f();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_83911f();
+}
diff --git a/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.dxc.hlsl
index ade1134..2a6873b 100644
--- a/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void distance_892a5d() {
-  float16_t res = distance((float16_t(1.0h)).xx, (float16_t(1.0h)).xx);
+  float16_t res = float16_t(0.0h);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.glsl
index 903ffc5..a2e35a9 100644
--- a/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.glsl
@@ -2,7 +2,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void distance_892a5d() {
-  float16_t res = distance(f16vec2(1.0hf), f16vec2(1.0hf));
+  float16_t res = 0.0hf;
 }
 
 vec4 vertex_main() {
@@ -23,7 +23,7 @@
 precision mediump float;
 
 void distance_892a5d() {
-  float16_t res = distance(f16vec2(1.0hf), f16vec2(1.0hf));
+  float16_t res = 0.0hf;
 }
 
 void fragment_main() {
@@ -38,7 +38,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void distance_892a5d() {
-  float16_t res = distance(f16vec2(1.0hf), f16vec2(1.0hf));
+  float16_t res = 0.0hf;
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.msl
index 627969b..c1f2c4d 100644
--- a/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void distance_892a5d() {
-  half res = distance(half2(1.0h), half2(1.0h));
+  half res = 0.0h;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.spvasm
index 4ddc326..049c36b 100644
--- a/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/distance/892a5d.wgsl.expected.spvasm
@@ -1,14 +1,13 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 36
+; Bound: 31
 ; Schema: 0
                OpCapability Shader
                OpCapability Float16
                OpCapability UniformAndStorageBuffer16BitAccess
                OpCapability StorageBuffer16BitAccess
                OpCapability StorageInputOutput16
-         %15 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -36,39 +35,35 @@
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
        %half = OpTypeFloat 16
-     %v2half = OpTypeVector %half 2
-%half_0x1p_0 = OpConstant %half 0x1p+0
-         %18 = OpConstantComposite %v2half %half_0x1p_0 %half_0x1p_0
+         %14 = OpConstantNull %half
 %_ptr_Function_half = OpTypePointer Function %half
-         %21 = OpConstantNull %half
-         %22 = OpTypeFunction %v4float
+         %17 = OpTypeFunction %v4float
     %float_1 = OpConstant %float 1
 %distance_892a5d = OpFunction %void None %9
          %12 = OpLabel
-        %res = OpVariable %_ptr_Function_half Function %21
-         %13 = OpExtInst %half %15 Distance %18 %18
-               OpStore %res %13
+        %res = OpVariable %_ptr_Function_half Function %14
+               OpStore %res %14
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %22
-         %24 = OpLabel
-         %25 = OpFunctionCall %void %distance_892a5d
+%vertex_main_inner = OpFunction %v4float None %17
+         %19 = OpLabel
+         %20 = OpFunctionCall %void %distance_892a5d
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %27 = OpLabel
-         %28 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %28
+         %22 = OpLabel
+         %23 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %23
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %31 = OpLabel
-         %32 = OpFunctionCall %void %distance_892a5d
+         %26 = OpLabel
+         %27 = OpFunctionCall %void %distance_892a5d
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %34 = OpLabel
-         %35 = OpFunctionCall %void %distance_892a5d
+         %29 = OpLabel
+         %30 = OpFunctionCall %void %distance_892a5d
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.dxc.hlsl
index 852e284..aceea56 100644
--- a/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void distance_928fa0() {
-  float16_t res = distance((float16_t(1.0h)).xxx, (float16_t(1.0h)).xxx);
+  float16_t res = float16_t(0.0h);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.glsl
index 30f8cf3..8e3bfd4 100644
--- a/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.glsl
@@ -2,7 +2,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void distance_928fa0() {
-  float16_t res = distance(f16vec3(1.0hf), f16vec3(1.0hf));
+  float16_t res = 0.0hf;
 }
 
 vec4 vertex_main() {
@@ -23,7 +23,7 @@
 precision mediump float;
 
 void distance_928fa0() {
-  float16_t res = distance(f16vec3(1.0hf), f16vec3(1.0hf));
+  float16_t res = 0.0hf;
 }
 
 void fragment_main() {
@@ -38,7 +38,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void distance_928fa0() {
-  float16_t res = distance(f16vec3(1.0hf), f16vec3(1.0hf));
+  float16_t res = 0.0hf;
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.msl
index 9c928e6..dffd473 100644
--- a/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void distance_928fa0() {
-  half res = distance(half3(1.0h), half3(1.0h));
+  half res = 0.0h;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.spvasm
index d272d09..c2c743a 100644
--- a/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/distance/928fa0.wgsl.expected.spvasm
@@ -1,14 +1,13 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 36
+; Bound: 31
 ; Schema: 0
                OpCapability Shader
                OpCapability Float16
                OpCapability UniformAndStorageBuffer16BitAccess
                OpCapability StorageBuffer16BitAccess
                OpCapability StorageInputOutput16
-         %15 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -36,39 +35,35 @@
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
        %half = OpTypeFloat 16
-     %v3half = OpTypeVector %half 3
-%half_0x1p_0 = OpConstant %half 0x1p+0
-         %18 = OpConstantComposite %v3half %half_0x1p_0 %half_0x1p_0 %half_0x1p_0
+         %14 = OpConstantNull %half
 %_ptr_Function_half = OpTypePointer Function %half
-         %21 = OpConstantNull %half
-         %22 = OpTypeFunction %v4float
+         %17 = OpTypeFunction %v4float
     %float_1 = OpConstant %float 1
 %distance_928fa0 = OpFunction %void None %9
          %12 = OpLabel
-        %res = OpVariable %_ptr_Function_half Function %21
-         %13 = OpExtInst %half %15 Distance %18 %18
-               OpStore %res %13
+        %res = OpVariable %_ptr_Function_half Function %14
+               OpStore %res %14
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %22
-         %24 = OpLabel
-         %25 = OpFunctionCall %void %distance_928fa0
+%vertex_main_inner = OpFunction %v4float None %17
+         %19 = OpLabel
+         %20 = OpFunctionCall %void %distance_928fa0
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %27 = OpLabel
-         %28 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %28
+         %22 = OpLabel
+         %23 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %23
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %31 = OpLabel
-         %32 = OpFunctionCall %void %distance_928fa0
+         %26 = OpLabel
+         %27 = OpFunctionCall %void %distance_928fa0
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %34 = OpLabel
-         %35 = OpFunctionCall %void %distance_928fa0
+         %29 = OpLabel
+         %30 = OpFunctionCall %void %distance_928fa0
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.dxc.hlsl
index 629f3ab..7d382a6 100644
--- a/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void distance_9646ea() {
-  float res = distance((1.0f).xxxx, (1.0f).xxxx);
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.fxc.hlsl
index 629f3ab..7d382a6 100644
--- a/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void distance_9646ea() {
-  float res = distance((1.0f).xxxx, (1.0f).xxxx);
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.glsl
index ee04153..8f708a0 100644
--- a/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.glsl
@@ -1,7 +1,7 @@
 #version 310 es
 
 void distance_9646ea() {
-  float res = distance(vec4(1.0f), vec4(1.0f));
+  float res = 0.0f;
 }
 
 vec4 vertex_main() {
@@ -21,7 +21,7 @@
 precision mediump float;
 
 void distance_9646ea() {
-  float res = distance(vec4(1.0f), vec4(1.0f));
+  float res = 0.0f;
 }
 
 void fragment_main() {
@@ -35,7 +35,7 @@
 #version 310 es
 
 void distance_9646ea() {
-  float res = distance(vec4(1.0f), vec4(1.0f));
+  float res = 0.0f;
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.msl
index 0d90ab3..0fb4dd8 100644
--- a/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void distance_9646ea() {
-  float res = distance(float4(1.0f), float4(1.0f));
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.spvasm
index 2956c30..2a380dd 100644
--- a/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/distance/9646ea.wgsl.expected.spvasm
@@ -1,10 +1,9 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 32
+; Bound: 29
 ; Schema: 0
                OpCapability Shader
-         %14 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -31,36 +30,34 @@
 %vertex_point_size = OpVariable %_ptr_Output_float Output %8
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
-    %float_1 = OpConstant %float 1
-         %16 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
 %_ptr_Function_float = OpTypePointer Function %float
-         %19 = OpTypeFunction %v4float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
 %distance_9646ea = OpFunction %void None %9
          %12 = OpLabel
         %res = OpVariable %_ptr_Function_float Function %8
-         %13 = OpExtInst %float %14 Distance %16 %16
-               OpStore %res %13
+               OpStore %res %8
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %19
-         %21 = OpLabel
-         %22 = OpFunctionCall %void %distance_9646ea
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_9646ea
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %24 = OpLabel
-         %25 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %25
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %27 = OpLabel
-         %28 = OpFunctionCall %void %distance_9646ea
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_9646ea
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %30 = OpLabel
-         %31 = OpFunctionCall %void %distance_9646ea
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_9646ea
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.dxc.hlsl
index 948efd0..3bddd0f 100644
--- a/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void distance_aa4055() {
-  float res = distance((1.0f).xx, (1.0f).xx);
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.fxc.hlsl
index 948efd0..3bddd0f 100644
--- a/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void distance_aa4055() {
-  float res = distance((1.0f).xx, (1.0f).xx);
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.glsl
index 9a2c485..71ebcff 100644
--- a/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.glsl
@@ -1,7 +1,7 @@
 #version 310 es
 
 void distance_aa4055() {
-  float res = distance(vec2(1.0f), vec2(1.0f));
+  float res = 0.0f;
 }
 
 vec4 vertex_main() {
@@ -21,7 +21,7 @@
 precision mediump float;
 
 void distance_aa4055() {
-  float res = distance(vec2(1.0f), vec2(1.0f));
+  float res = 0.0f;
 }
 
 void fragment_main() {
@@ -35,7 +35,7 @@
 #version 310 es
 
 void distance_aa4055() {
-  float res = distance(vec2(1.0f), vec2(1.0f));
+  float res = 0.0f;
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.msl
index 990edc4..75d883c 100644
--- a/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void distance_aa4055() {
-  float res = distance(float2(1.0f), float2(1.0f));
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.spvasm
index f1cda7e..25f74d1 100644
--- a/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/distance/aa4055.wgsl.expected.spvasm
@@ -1,10 +1,9 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 33
+; Bound: 29
 ; Schema: 0
                OpCapability Shader
-         %14 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -31,37 +30,34 @@
 %vertex_point_size = OpVariable %_ptr_Output_float Output %8
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
-    %v2float = OpTypeVector %float 2
-    %float_1 = OpConstant %float 1
-         %17 = OpConstantComposite %v2float %float_1 %float_1
 %_ptr_Function_float = OpTypePointer Function %float
-         %20 = OpTypeFunction %v4float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
 %distance_aa4055 = OpFunction %void None %9
          %12 = OpLabel
         %res = OpVariable %_ptr_Function_float Function %8
-         %13 = OpExtInst %float %14 Distance %17 %17
-               OpStore %res %13
+               OpStore %res %8
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %20
-         %22 = OpLabel
-         %23 = OpFunctionCall %void %distance_aa4055
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_aa4055
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %25 = OpLabel
-         %26 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %26
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %28 = OpLabel
-         %29 = OpFunctionCall %void %distance_aa4055
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_aa4055
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %31 = OpLabel
-         %32 = OpFunctionCall %void %distance_aa4055
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_aa4055
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/ac5535.wgsl b/test/tint/builtins/gen/literal/distance/ac5535.wgsl
new file mode 100644
index 0000000..5984840
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/ac5535.wgsl
@@ -0,0 +1,43 @@
+// Copyright 2022 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.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn distance(vec<4, fa>, vec<4, fa>) -> fa
+fn distance_ac5535() {
+  var res = distance(vec4(1.), vec4(1.));
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_ac5535();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_ac5535();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_ac5535();
+}
diff --git a/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..6a2192f
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_ac5535();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_ac5535();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_ac5535();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..6a2192f
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_ac5535();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_ac5535();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_ac5535();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.glsl
new file mode 100644
index 0000000..8cd6d36
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+vec4 vertex_main() {
+  distance_ac5535();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+void fragment_main() {
+  distance_ac5535();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+void compute_main() {
+  distance_ac5535();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.msl
new file mode 100644
index 0000000..93af9d8
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  distance_ac5535();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  distance_ac5535();
+  return;
+}
+
+kernel void compute_main() {
+  distance_ac5535();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.spvasm
new file mode 100644
index 0000000..caf276c
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.spvasm
@@ -0,0 +1,63 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 29
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %distance_ac5535 "distance_ac5535"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+%_ptr_Function_float = OpTypePointer Function %float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%distance_ac5535 = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_float Function %8
+               OpStore %res %8
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_ac5535
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_ac5535
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_ac5535
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.wgsl
new file mode 100644
index 0000000..49b1eca
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/ac5535.wgsl.expected.wgsl
@@ -0,0 +1,19 @@
+fn distance_ac5535() {
+  var res = distance(vec4(1.0), vec4(1.0));
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_ac5535();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_ac5535();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_ac5535();
+}
diff --git a/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.dxc.hlsl
index 277968e..8e44709 100644
--- a/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void distance_cfed73() {
-  float res = distance(1.0f, 1.0f);
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.fxc.hlsl
index 277968e..8e44709 100644
--- a/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void distance_cfed73() {
-  float res = distance(1.0f, 1.0f);
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.glsl
index 1bdaa15..7c0db51 100644
--- a/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.glsl
@@ -1,7 +1,7 @@
 #version 310 es
 
 void distance_cfed73() {
-  float res = distance(1.0f, 1.0f);
+  float res = 0.0f;
 }
 
 vec4 vertex_main() {
@@ -21,7 +21,7 @@
 precision mediump float;
 
 void distance_cfed73() {
-  float res = distance(1.0f, 1.0f);
+  float res = 0.0f;
 }
 
 void fragment_main() {
@@ -35,7 +35,7 @@
 #version 310 es
 
 void distance_cfed73() {
-  float res = distance(1.0f, 1.0f);
+  float res = 0.0f;
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.msl
index a149206..e48b48f 100644
--- a/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void distance_cfed73() {
-  float res = fabs(1.0f - 1.0f);
+  float res = 0.0f;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.spvasm
index a0ad9f2..2a601c1 100644
--- a/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/distance/cfed73.wgsl.expected.spvasm
@@ -1,10 +1,9 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 31
+; Bound: 29
 ; Schema: 0
                OpCapability Shader
-         %14 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -31,35 +30,34 @@
 %vertex_point_size = OpVariable %_ptr_Output_float Output %8
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
-    %float_1 = OpConstant %float 1
 %_ptr_Function_float = OpTypePointer Function %float
-         %18 = OpTypeFunction %v4float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
 %distance_cfed73 = OpFunction %void None %9
          %12 = OpLabel
         %res = OpVariable %_ptr_Function_float Function %8
-         %13 = OpExtInst %float %14 Distance %float_1 %float_1
-               OpStore %res %13
+               OpStore %res %8
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %18
-         %20 = OpLabel
-         %21 = OpFunctionCall %void %distance_cfed73
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_cfed73
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %23 = OpLabel
-         %24 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %24
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %26 = OpLabel
-         %27 = OpFunctionCall %void %distance_cfed73
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_cfed73
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %29 = OpLabel
-         %30 = OpFunctionCall %void %distance_cfed73
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_cfed73
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl
new file mode 100644
index 0000000..6a9fd64
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl
@@ -0,0 +1,43 @@
+// Copyright 2022 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.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn distance(fa, fa) -> fa
+fn distance_f9c9ee() {
+  var res = distance(1., 1.);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_f9c9ee();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_f9c9ee();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_f9c9ee();
+}
diff --git a/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..2c8da65
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_f9c9ee();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_f9c9ee();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_f9c9ee();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..2c8da65
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_f9c9ee();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_f9c9ee();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_f9c9ee();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.glsl b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.glsl
new file mode 100644
index 0000000..99df855
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+vec4 vertex_main() {
+  distance_f9c9ee();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+void fragment_main() {
+  distance_f9c9ee();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+void compute_main() {
+  distance_f9c9ee();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.msl b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.msl
new file mode 100644
index 0000000..b160831
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  distance_f9c9ee();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  distance_f9c9ee();
+  return;
+}
+
+kernel void compute_main() {
+  distance_f9c9ee();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.spvasm
new file mode 100644
index 0000000..0710c1c
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.spvasm
@@ -0,0 +1,63 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 29
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %distance_f9c9ee "distance_f9c9ee"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+%_ptr_Function_float = OpTypePointer Function %float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%distance_f9c9ee = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_float Function %8
+               OpStore %res %8
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_f9c9ee
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_f9c9ee
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_f9c9ee
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.wgsl
new file mode 100644
index 0000000..0cd7fe0
--- /dev/null
+++ b/test/tint/builtins/gen/literal/distance/f9c9ee.wgsl.expected.wgsl
@@ -0,0 +1,19 @@
+fn distance_f9c9ee() {
+  var res = distance(1.0, 1.0);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_f9c9ee();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_f9c9ee();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_f9c9ee();
+}
diff --git a/test/tint/builtins/gen/var/distance/3a175a.wgsl b/test/tint/builtins/gen/var/distance/3a175a.wgsl
new file mode 100644
index 0000000..03422ed
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/3a175a.wgsl
@@ -0,0 +1,45 @@
+// Copyright 2022 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.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn distance(vec<2, fa>, vec<2, fa>) -> fa
+fn distance_3a175a() {
+  const arg_0 = vec2(1.);
+  const arg_1 = vec2(1.);
+  var res = distance(arg_0, arg_1);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_3a175a();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_3a175a();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_3a175a();
+}
diff --git a/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..2bc4567
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_3a175a();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_3a175a();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_3a175a();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..2bc4567
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_3a175a();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_3a175a();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_3a175a();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.glsl b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.glsl
new file mode 100644
index 0000000..58e8f50
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+vec4 vertex_main() {
+  distance_3a175a();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+void fragment_main() {
+  distance_3a175a();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+void compute_main() {
+  distance_3a175a();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.msl b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.msl
new file mode 100644
index 0000000..4273f3f
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void distance_3a175a() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  distance_3a175a();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  distance_3a175a();
+  return;
+}
+
+kernel void compute_main() {
+  distance_3a175a();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.spvasm b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.spvasm
new file mode 100644
index 0000000..393637d
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.spvasm
@@ -0,0 +1,63 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 29
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %distance_3a175a "distance_3a175a"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+%_ptr_Function_float = OpTypePointer Function %float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%distance_3a175a = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_float Function %8
+               OpStore %res %8
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_3a175a
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_3a175a
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_3a175a
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.wgsl b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.wgsl
new file mode 100644
index 0000000..d4f0948
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/3a175a.wgsl.expected.wgsl
@@ -0,0 +1,21 @@
+fn distance_3a175a() {
+  const arg_0 = vec2(1.0);
+  const arg_1 = vec2(1.0);
+  var res = distance(arg_0, arg_1);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_3a175a();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_3a175a();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_3a175a();
+}
diff --git a/test/tint/builtins/gen/var/distance/83911f.wgsl b/test/tint/builtins/gen/var/distance/83911f.wgsl
new file mode 100644
index 0000000..578ee8d
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/83911f.wgsl
@@ -0,0 +1,45 @@
+// Copyright 2022 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.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn distance(vec<3, fa>, vec<3, fa>) -> fa
+fn distance_83911f() {
+  const arg_0 = vec3(1.);
+  const arg_1 = vec3(1.);
+  var res = distance(arg_0, arg_1);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_83911f();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_83911f();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_83911f();
+}
diff --git a/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..7fe07e2
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_83911f();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_83911f();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_83911f();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..7fe07e2
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_83911f();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_83911f();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_83911f();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.glsl b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.glsl
new file mode 100644
index 0000000..7486548
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+vec4 vertex_main() {
+  distance_83911f();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+void fragment_main() {
+  distance_83911f();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+void compute_main() {
+  distance_83911f();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.msl b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.msl
new file mode 100644
index 0000000..a810881
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void distance_83911f() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  distance_83911f();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  distance_83911f();
+  return;
+}
+
+kernel void compute_main() {
+  distance_83911f();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.spvasm b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.spvasm
new file mode 100644
index 0000000..42ac8e2
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.spvasm
@@ -0,0 +1,63 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 29
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %distance_83911f "distance_83911f"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+%_ptr_Function_float = OpTypePointer Function %float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%distance_83911f = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_float Function %8
+               OpStore %res %8
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_83911f
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_83911f
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_83911f
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.wgsl b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.wgsl
new file mode 100644
index 0000000..5becc19
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/83911f.wgsl.expected.wgsl
@@ -0,0 +1,21 @@
+fn distance_83911f() {
+  const arg_0 = vec3(1.0);
+  const arg_1 = vec3(1.0);
+  var res = distance(arg_0, arg_1);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_83911f();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_83911f();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_83911f();
+}
diff --git a/test/tint/builtins/gen/var/distance/ac5535.wgsl b/test/tint/builtins/gen/var/distance/ac5535.wgsl
new file mode 100644
index 0000000..86d6549
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/ac5535.wgsl
@@ -0,0 +1,45 @@
+// Copyright 2022 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.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn distance(vec<4, fa>, vec<4, fa>) -> fa
+fn distance_ac5535() {
+  const arg_0 = vec4(1.);
+  const arg_1 = vec4(1.);
+  var res = distance(arg_0, arg_1);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_ac5535();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_ac5535();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_ac5535();
+}
diff --git a/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..6a2192f
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_ac5535();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_ac5535();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_ac5535();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..6a2192f
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_ac5535();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_ac5535();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_ac5535();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.glsl b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.glsl
new file mode 100644
index 0000000..8cd6d36
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+vec4 vertex_main() {
+  distance_ac5535();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+void fragment_main() {
+  distance_ac5535();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+void compute_main() {
+  distance_ac5535();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.msl b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.msl
new file mode 100644
index 0000000..93af9d8
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void distance_ac5535() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  distance_ac5535();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  distance_ac5535();
+  return;
+}
+
+kernel void compute_main() {
+  distance_ac5535();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.spvasm b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.spvasm
new file mode 100644
index 0000000..caf276c
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.spvasm
@@ -0,0 +1,63 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 29
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %distance_ac5535 "distance_ac5535"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+%_ptr_Function_float = OpTypePointer Function %float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%distance_ac5535 = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_float Function %8
+               OpStore %res %8
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_ac5535
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_ac5535
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_ac5535
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.wgsl b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.wgsl
new file mode 100644
index 0000000..6ce3cb1
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/ac5535.wgsl.expected.wgsl
@@ -0,0 +1,21 @@
+fn distance_ac5535() {
+  const arg_0 = vec4(1.0);
+  const arg_1 = vec4(1.0);
+  var res = distance(arg_0, arg_1);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_ac5535();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_ac5535();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_ac5535();
+}
diff --git a/test/tint/builtins/gen/var/distance/f9c9ee.wgsl b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl
new file mode 100644
index 0000000..a72a3e3
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl
@@ -0,0 +1,45 @@
+// Copyright 2022 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.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn distance(fa, fa) -> fa
+fn distance_f9c9ee() {
+  const arg_0 = 1.;
+  const arg_1 = 1.;
+  var res = distance(arg_0, arg_1);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_f9c9ee();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_f9c9ee();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_f9c9ee();
+}
diff --git a/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..2c8da65
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_f9c9ee();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_f9c9ee();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_f9c9ee();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..2c8da65
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  distance_f9c9ee();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  distance_f9c9ee();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  distance_f9c9ee();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.glsl b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.glsl
new file mode 100644
index 0000000..99df855
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+vec4 vertex_main() {
+  distance_f9c9ee();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+void fragment_main() {
+  distance_f9c9ee();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+void compute_main() {
+  distance_f9c9ee();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.msl b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.msl
new file mode 100644
index 0000000..b160831
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void distance_f9c9ee() {
+  float res = 0.0f;
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  distance_f9c9ee();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  distance_f9c9ee();
+  return;
+}
+
+kernel void compute_main() {
+  distance_f9c9ee();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.spvasm b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.spvasm
new file mode 100644
index 0000000..0710c1c
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.spvasm
@@ -0,0 +1,63 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 29
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %distance_f9c9ee "distance_f9c9ee"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+%_ptr_Function_float = OpTypePointer Function %float
+         %15 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%distance_f9c9ee = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_float Function %8
+               OpStore %res %8
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %15
+         %17 = OpLabel
+         %18 = OpFunctionCall %void %distance_f9c9ee
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %20 = OpLabel
+         %21 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %21
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %void %distance_f9c9ee
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %27 = OpLabel
+         %28 = OpFunctionCall %void %distance_f9c9ee
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.wgsl b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.wgsl
new file mode 100644
index 0000000..ed7ba1e
--- /dev/null
+++ b/test/tint/builtins/gen/var/distance/f9c9ee.wgsl.expected.wgsl
@@ -0,0 +1,21 @@
+fn distance_f9c9ee() {
+  const arg_0 = 1.0;
+  const arg_1 = 1.0;
+  var res = distance(arg_0, arg_1);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  distance_f9c9ee();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  distance_f9c9ee();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  distance_f9c9ee();
+}